4 #![warn(clippy::use_self)]
6 #![allow(clippy::should_implement_trait, clippy::upper_case_acronyms)]
22 impl Default for Foo {
23 fn default() -> Self {
24 // FIXME: applicable here
42 impl Default for Foo {
43 fn default() -> Self {
55 // Cannot use `Self` as return type, because the function is actually `fn foo<'b>(s: &'b str) ->
57 fn foo(s: &str) -> Foo {
60 // cannot replace with `Self`, because that's `Foo<'a>`
61 fn bar() -> Foo<'static> {
62 Foo { foo_str: "foo" }
65 // FIXME: the lint does not handle lifetimed struct
66 // `Self` should be applicable here
67 fn clone(&self) -> Foo<'a> {
68 Foo { foo_str: self.foo_str }
75 #[allow(clippy::wrong_self_convention)]
76 fn into_bytes(&self) -> Vec<u8>;
79 // This should not be linted
80 impl IntoBytes for u8 {
81 fn into_bytes(&self) -> Vec<u8> {
92 // TyKind::Def (used for `impl Trait` types) does not include type parameters yet.
93 // See documentation in rustc_hir::hir::TyKind.
94 // The hir tree walk stops at `impl Iterator` level and does not inspect &Foo.
95 fn bad(foos: &[Self]) -> impl Iterator<Item = &Foo> {
99 fn good(foos: &[Self]) -> impl Iterator<Item = &Self> {
109 pub fn ts() -> Self {
116 macro_rules! use_self_expand {
127 use_self_expand!(); // Should lint in local macros
135 #[allow(unused_imports)]
136 use self::Foo; // Can't use Self here
138 foo: Foo, // Foo != Self
147 // Can't use Self here
166 #[allow(unused_imports)]
167 use self::Enum::*; // Issue 3425
168 static STATIC: Enum = Enum::A; // Can't use Self as type
173 let _ = Self::C { field: true };
188 impl Trait<Vec<A>> for Vec<B> {
189 fn a(_: Vec<A>) -> Self {
194 impl<T> Trait<Vec<A>> for Vec<T>
198 fn a(v: Vec<A>) -> Self {
199 <Vec<B>>::a(v).into_iter().map(Trait::a).collect()
204 #[allow(clippy::no_effect, path_statements)]
211 const A: bool = true;
227 fn from_something() -> Self {
233 fn test() -> TestStruct;
236 impl Test for TestStruct {
237 fn test() -> TestStruct {
238 // FIXME: applicable here
239 TestStruct::from_something()
244 mod paths_created_by_lowering {
253 // FIXME: applicable here
258 fn f<'a>(&self, p: &'a [u8]) -> &'a [u8] {
259 // FIXME: applicable here twice
265 fn f<'a>(&self, p: &'a [u8]) -> &'a [u8];
268 impl T for Range<u8> {
269 fn f<'a>(&self, p: &'a [u8]) -> &'a [u8] {
282 // `Self` is applicable here
283 fn foo(value: T) -> Self {
287 // `Cannot` use `Self` as a return type as the generic types are different
288 fn bar(value: i32) -> Foo<i32> {
295 pub struct Error<From, To> {
304 fn from(value: T) -> Self;
314 fn try_from(value: T) -> Result<Self, Error<Self::From, Self::To>>;
317 impl<F, T> TryFrom<F> for T
324 fn try_from(value: F) -> Result<Self, Error<Self::From, Self::To>> {
325 Ok(From::from(value))
329 impl From<bool> for i64 {
333 fn from(value: bool) -> Self {
352 impl<T: Foo> Foo for Option<T> {
353 type Bar = Option<T::Bar>;
359 pub struct Bar([usize; 3]);
362 pub const BAR: usize = 3;
365 const _X: usize = Foo::BAR;
366 // const _Y: usize = Self::BAR;
372 trait Foo: 'static {}
378 impl<T: Foo> From<T> for Box<dyn Foo> {
379 fn from(t: T) -> Self {
380 // FIXME: applicable here
386 mod lint_at_item_level {
389 #[allow(clippy::use_self)]
396 #[allow(clippy::use_self)]
397 impl Default for Foo {
398 fn default() -> Foo {
404 mod lint_at_impl_item_level {
408 #[allow(clippy::use_self)]
414 impl Default for Foo {
415 #[allow(clippy::use_self)]
416 fn default() -> Foo {
428 impl From<X> for u32 {
429 fn from(c: X) -> Self {
430 unsafe { core::mem::transmute(c) }
436 use std::convert::Into;
453 fn new<V: Into<T>>(v: V) -> Self {
454 Self { t: Into::into(v) }
460 // FIXME: applicable here
461 A::new::<submod::B>(submod::B {})