Skip to content

Commit 70f1d0d

Browse files
committed
Auto merge of #9043 - dswij:9037-test, r=Manishearth
`extra_unused_lifetimes` add FP test case emitting from derived attributes. Add test to cover for #9014 which is fixed in #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 ```
2 parents 90227c1 + a8f6824 commit 70f1d0d

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

tests/ui/auxiliary/proc_macro_derive.rs

+14
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,17 @@ pub fn mini_macro(_: TokenStream) -> TokenStream {
7272
}
7373
)
7474
}
75+
76+
#[proc_macro_derive(ExtraLifetimeDerive)]
77+
#[allow(unused)]
78+
pub fn extra_lifetime(_input: TokenStream) -> TokenStream {
79+
quote!(
80+
pub struct ExtraLifetime;
81+
82+
impl<'b> ExtraLifetime {
83+
pub fn something<'c>() -> Self {
84+
Self
85+
}
86+
}
87+
)
88+
}

tests/ui/extra_unused_lifetimes.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// aux-build:proc_macro_derive.rs
2+
13
#![allow(
24
unused,
35
dead_code,
@@ -7,6 +9,9 @@
79
)]
810
#![warn(clippy::extra_unused_lifetimes)]
911

12+
#[macro_use]
13+
extern crate proc_macro_derive;
14+
1015
fn empty() {}
1116

1217
fn used_lt<'a>(x: &'a u8) {}
@@ -114,4 +119,11 @@ mod second_case {
114119
}
115120
}
116121

122+
// Should not lint
123+
#[derive(ExtraLifetimeDerive)]
124+
struct Human<'a> {
125+
pub bones: i32,
126+
pub name: &'a str,
127+
}
128+
117129
fn main() {}

tests/ui/extra_unused_lifetimes.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
error: this lifetime isn't used in the function definition
2-
--> $DIR/extra_unused_lifetimes.rs:14:14
2+
--> $DIR/extra_unused_lifetimes.rs:19:14
33
|
44
LL | fn unused_lt<'a>(x: u8) {}
55
| ^^
66
|
77
= note: `-D clippy::extra-unused-lifetimes` implied by `-D warnings`
88

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

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

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

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

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

0 commit comments

Comments
 (0)