4 #![warn(clippy::use_self)]
6 #![allow(clippy::should_implement_trait, clippy::upper_case_acronyms, clippy::from_over_into)]
22 impl Default for Foo {
41 impl Default for Foo {
42 fn default() -> Self {
54 // Cannot use `Self` as return type, because the function is actually `fn foo<'b>(s: &'b str) ->
56 fn foo(s: &str) -> Foo {
59 // cannot replace with `Self`, because that's `Foo<'a>`
60 fn bar() -> Foo<'static> {
61 Foo { foo_str: "foo" }
64 // FIXME: the lint does not handle lifetimed struct
65 // `Self` should be applicable here
66 fn clone(&self) -> Foo<'a> {
67 Foo { foo_str: self.foo_str }
74 fn to_bytes(&self) -> Vec<u8>;
77 // This should not be linted
78 impl IntoBytes for u8 {
79 fn to_bytes(&self) -> Vec<u8> {
89 fn bad(foos: &[Foo]) -> impl Iterator<Item = &Foo> {
93 fn good(foos: &[Self]) -> impl Iterator<Item = &Self> {
103 pub fn ts() -> Self {
110 macro_rules! use_self_expand {
121 use_self_expand!(); // Should lint in local macros
129 #[allow(unused_imports)]
130 use self::Foo; // Can't use Self here
132 foo: Foo, // Foo != Self
141 // Can't use Self here
160 #[allow(unused_imports)]
161 use self::Enum::*; // Issue 3425
162 static STATIC: Enum = Enum::A; // Can't use Self as type
167 let _ = Enum::C { field: true };
182 impl Trait<Vec<A>> for Vec<B> {
183 fn a(_: Vec<A>) -> Self {
188 impl<T> Trait<Vec<A>> for Vec<T>
192 fn a(v: Vec<A>) -> Self {
193 <Vec<B>>::a(v).into_iter().map(Trait::a).collect()
198 #[allow(clippy::no_effect, path_statements)]
205 const A: bool = true;
221 fn from_something() -> Self {
227 fn test() -> TestStruct;
230 impl Test for TestStruct {
231 fn test() -> TestStruct {
232 TestStruct::from_something()
237 mod paths_created_by_lowering {
250 fn f<'a>(&self, p: &'a [u8]) -> &'a [u8] {
256 fn f<'a>(&self, p: &'a [u8]) -> &'a [u8];
259 impl T for Range<u8> {
260 fn f<'a>(&self, p: &'a [u8]) -> &'a [u8] {
273 // `Self` is applicable here
274 fn foo(value: T) -> Foo<T> {
278 // `Cannot` use `Self` as a return type as the generic types are different
279 fn bar(value: i32) -> Foo<i32> {
286 pub struct Error<From, To> {
295 fn from(value: T) -> Self;
305 fn try_from(value: T) -> Result<Self, Error<Self::From, Self::To>>;
308 impl<F, T> TryFrom<F> for T
315 fn try_from(value: F) -> Result<Self, Error<Self::From, Self::To>> {
316 Ok(From::from(value))
320 impl From<bool> for i64 {
324 fn from(value: bool) -> Self {
343 impl<T: Foo> Foo for Option<T> {
344 type Bar = Option<T::Bar>;
350 pub struct Bar([usize; 3]);
353 pub const BAR: usize = 3;
356 const _X: usize = Foo::BAR;
357 // const _Y: usize = Self::BAR;
363 trait Foo: 'static {}
369 impl<T: Foo> From<T> for Box<dyn Foo> {
370 fn from(t: T) -> Self {
376 mod lint_at_item_level {
379 #[allow(clippy::use_self)]
386 #[allow(clippy::use_self)]
387 impl Default for Foo {
388 fn default() -> Foo {
394 mod lint_at_impl_item_level {
398 #[allow(clippy::use_self)]
404 impl Default for Foo {
405 #[allow(clippy::use_self)]
406 fn default() -> Foo {
418 impl From<X> for u32 {
419 fn from(c: X) -> Self {
420 unsafe { core::mem::transmute(c) }
426 use std::convert::Into;
443 fn new<V: Into<T>>(v: V) -> Self {
444 Self { t: Into::into(v) }
450 A::new::<submod::B>(submod::B {})