3 // aux-build:proc_macro_derive.rs
5 #![warn(clippy::use_self)]
7 #![allow(clippy::should_implement_trait, clippy::upper_case_acronyms, clippy::from_over_into)]
10 extern crate proc_macro_derive;
26 impl Default for Foo {
27 fn default() -> Self {
45 impl Default for Foo {
46 fn default() -> Self {
58 // Cannot use `Self` as return type, because the function is actually `fn foo<'b>(s: &'b str) ->
60 fn foo(s: &str) -> Foo {
63 // cannot replace with `Self`, because that's `Foo<'a>`
64 fn bar() -> Foo<'static> {
65 Foo { foo_str: "foo" }
68 // FIXME: the lint does not handle lifetimed struct
69 // `Self` should be applicable here
70 fn clone(&self) -> Foo<'a> {
71 Foo { foo_str: self.foo_str }
78 fn to_bytes(&self) -> Vec<u8>;
81 // This should not be linted
82 impl IntoBytes for u8 {
83 fn to_bytes(&self) -> Vec<u8> {
93 fn bad(foos: &[Self]) -> impl Iterator<Item = &Self> {
97 fn good(foos: &[Self]) -> impl Iterator<Item = &Self> {
107 pub fn ts() -> Self {
114 macro_rules! use_self_expand {
125 use_self_expand!(); // Should not lint in local macros
128 #[derive(StructAUseSelf)] // Should not lint in derives
136 #[allow(unused_imports)]
137 use self::Foo; // Can't use Self here
139 foo: Foo, // Foo != Self
148 // Can't use Self here
167 #[allow(unused_imports)]
168 use self::Enum::*; // Issue 3425
169 static STATIC: Enum = Enum::A; // Can't use Self as type
174 let _ = Self::C { field: true };
189 impl Trait<Vec<A>> for Vec<B> {
190 fn a(_: Vec<A>) -> Self {
195 impl<T> Trait<Vec<A>> for Vec<T>
199 fn a(v: Vec<A>) -> Self {
200 <Vec<B>>::a(v).into_iter().map(Trait::a).collect()
205 #[allow(clippy::no_effect, path_statements)]
212 const A: bool = true;
228 fn from_something() -> Self {
234 fn test() -> TestStruct;
237 impl Test for TestStruct {
238 fn test() -> TestStruct {
239 Self::from_something()
244 mod paths_created_by_lowering {
253 async fn g() -> Self {
257 fn f<'a>(&self, p: &'a [u8]) -> &'a [u8] {
263 fn f<'a>(&self, p: &'a [u8]) -> &'a [u8];
266 impl T for Range<u8> {
267 fn f<'a>(&self, p: &'a [u8]) -> &'a [u8] {
280 // `Self` is applicable here
281 fn foo(value: T) -> Self {
285 // `Cannot` use `Self` as a return type as the generic types are different
286 fn bar(value: i32) -> Foo<i32> {
293 pub struct Error<From, To> {
302 fn from(value: T) -> Self;
312 fn try_from(value: T) -> Result<Self, Error<Self::From, Self::To>>;
315 // FIXME: Suggested fix results in infinite recursion.
316 // impl<F, T> TryFrom<F> for T
320 // type From = Self::From;
321 // type To = Self::To;
323 // fn try_from(value: F) -> Result<Self, Error<Self::From, Self::To>> {
324 // Ok(From::from(value))
328 impl From<bool> for i64 {
332 fn from(value: bool) -> Self {
333 if value { 100 } else { 0 }
347 impl<T: Foo> Foo for Option<T> {
348 type Bar = Option<T::Bar>;
354 pub struct Bar([usize; 3]);
357 pub const BAR: usize = 3;
360 const _X: usize = Foo::BAR;
361 // const _Y: usize = Self::BAR;
367 trait Foo: 'static {}
373 impl<T: Foo> From<T> for Box<dyn Foo> {
374 fn from(t: T) -> Self {
380 mod lint_at_item_level {
383 #[allow(clippy::use_self)]
390 #[allow(clippy::use_self)]
391 impl Default for Foo {
392 fn default() -> Foo {
398 mod lint_at_impl_item_level {
402 #[allow(clippy::use_self)]
408 impl Default for Foo {
409 #[allow(clippy::use_self)]
410 fn default() -> Foo {
422 impl From<X> for u32 {
423 fn from(c: X) -> Self {
424 unsafe { core::mem::transmute(c) }
430 use std::convert::Into;
447 fn new<V: Into<T>>(v: V) -> Self {
448 Self { t: Into::into(v) }
454 Self::new::<submod::B>(submod::B {})
460 #[derive(serde::Deserialize)]