mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-01-09 11:48:44 +00:00
ab3094b3db
It relaxes rules for `to_*` variant, so it doesn't lint in trait definitions and implementations anymore. Although, non-`Copy` type implementing trait's `to_*` method taking `self` feels not good (consumes ownership, so should be rather named `into_`), it would be better if this case was a pedantic lint (allow-by-default) instead.
44 lines
803 B
Rust
44 lines
803 B
Rust
// edition:2018
|
|
#![warn(clippy::wrong_self_convention)]
|
|
#![warn(clippy::wrong_pub_self_convention)]
|
|
#![allow(dead_code)]
|
|
|
|
fn main() {}
|
|
|
|
mod issue6983 {
|
|
pub struct Thing;
|
|
pub trait Trait {
|
|
fn to_thing(&self) -> Thing;
|
|
}
|
|
|
|
impl Trait for u8 {
|
|
// don't trigger, e.g. `ToString` from `std` requires `&self`
|
|
fn to_thing(&self) -> Thing {
|
|
Thing
|
|
}
|
|
}
|
|
|
|
trait ToU64 {
|
|
fn to_u64(self) -> u64;
|
|
}
|
|
|
|
struct FooNoCopy;
|
|
// don't trigger
|
|
impl ToU64 for FooNoCopy {
|
|
fn to_u64(self) -> u64 {
|
|
2
|
|
}
|
|
}
|
|
}
|
|
|
|
mod issue7032 {
|
|
trait Foo {
|
|
fn from_usize(x: usize) -> Self;
|
|
}
|
|
// don't trigger
|
|
impl Foo for usize {
|
|
fn from_usize(x: usize) -> Self {
|
|
x
|
|
}
|
|
}
|
|
}
|