Skip to content

Commit

Permalink
Auto merge of rust-lang#9043 - dswij:9037-test, r=Manishearth
Browse files Browse the repository at this point in the history
`extra_unused_lifetimes` add FP test case emitting from derived attributes.

Add test to cover for rust-lang#9014 which is fixed in rust-lang#9037.

changelog: [`extra_unused_lifetimes`] Add FP test case emitting from derived attributes.

---

Seeing the FP from the test:

```sh
$ git revert -m 1 1d1ae10
$ TESTNAME=extra_unused_lifetime cargo uitest
```
  • Loading branch information
bors committed Jun 29, 2022
2 parents 90227c1 + a8f6824 commit 70f1d0d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
14 changes: 14 additions & 0 deletions tests/ui/auxiliary/proc_macro_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,17 @@ pub fn mini_macro(_: TokenStream) -> TokenStream {
}
)
}

#[proc_macro_derive(ExtraLifetimeDerive)]
#[allow(unused)]
pub fn extra_lifetime(_input: TokenStream) -> TokenStream {
quote!(
pub struct ExtraLifetime;

impl<'b> ExtraLifetime {
pub fn something<'c>() -> Self {
Self
}
}
)
}
12 changes: 12 additions & 0 deletions tests/ui/extra_unused_lifetimes.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// aux-build:proc_macro_derive.rs

#![allow(
unused,
dead_code,
Expand All @@ -7,6 +9,9 @@
)]
#![warn(clippy::extra_unused_lifetimes)]

#[macro_use]
extern crate proc_macro_derive;

fn empty() {}

fn used_lt<'a>(x: &'a u8) {}
Expand Down Expand Up @@ -114,4 +119,11 @@ mod second_case {
}
}

// Should not lint
#[derive(ExtraLifetimeDerive)]
struct Human<'a> {
pub bones: i32,
pub name: &'a str,
}

fn main() {}
12 changes: 6 additions & 6 deletions tests/ui/extra_unused_lifetimes.stderr
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
error: this lifetime isn't used in the function definition
--> $DIR/extra_unused_lifetimes.rs:14:14
--> $DIR/extra_unused_lifetimes.rs:19:14
|
LL | fn unused_lt<'a>(x: u8) {}
| ^^
|
= note: `-D clippy::extra-unused-lifetimes` implied by `-D warnings`

error: this lifetime isn't used in the function definition
--> $DIR/extra_unused_lifetimes.rs:41:10
--> $DIR/extra_unused_lifetimes.rs:46:10
|
LL | fn x<'a>(&self) {}
| ^^

error: this lifetime isn't used in the function definition
--> $DIR/extra_unused_lifetimes.rs:67:22
--> $DIR/extra_unused_lifetimes.rs:72:22
|
LL | fn unused_lt<'a>(x: u8) {}
| ^^

error: this lifetime isn't used in the impl
--> $DIR/extra_unused_lifetimes.rs:78:10
--> $DIR/extra_unused_lifetimes.rs:83:10
|
LL | impl<'a> std::ops::AddAssign<&Scalar> for &mut Scalar {
| ^^

error: this lifetime isn't used in the impl
--> $DIR/extra_unused_lifetimes.rs:84:10
--> $DIR/extra_unused_lifetimes.rs:89:10
|
LL | impl<'b> Scalar {
| ^^

error: this lifetime isn't used in the function definition
--> $DIR/extra_unused_lifetimes.rs:85:26
--> $DIR/extra_unused_lifetimes.rs:90:26
|
LL | pub fn something<'c>() -> Self {
| ^^
Expand Down

0 comments on commit 70f1d0d

Please sign in to comment.