Skip to content

Commit 622ed7a

Browse files
committed
Test elided-lifetimes-in-paths outside of function signatures
1 parent 27b2ac5 commit 622ed7a

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#![deny(elided_lifetimes_in_paths)]
2+
3+
// Most of the time, we focus on elided lifetimes in function
4+
// signatures, but they can also appear in other places! The original
5+
// version of this lint handled all these cases in one location, but
6+
// it's desired that the one lint actually be multiple.
7+
8+
struct ContainsLifetime<'a>(&'a u8);
9+
10+
impl<'a> ContainsLifetime<'a> {
11+
fn use_it() {}
12+
}
13+
14+
struct ContainsLifetimeAndType<'a, T>(&'a T);
15+
16+
impl<'a, T> ContainsLifetimeAndType<'a, T> {
17+
fn use_it() {}
18+
}
19+
20+
fn use_via_turbofish<T>() {}
21+
22+
trait UseViaTrait {
23+
fn use_it() {}
24+
}
25+
26+
impl UseViaTrait for ContainsLifetime<'_> {}
27+
28+
trait TraitWithLifetime<'a> {
29+
fn use_it() {}
30+
}
31+
32+
impl<'a> TraitWithLifetime<'a> for u8 {}
33+
34+
// ==========
35+
36+
static USE_VIA_STATIC: ContainsLifetime = ContainsLifetime(&42);
37+
//~^ ERROR hidden lifetime parameters
38+
39+
fn main() {
40+
use_via_turbofish::<ContainsLifetime>();
41+
//~^ ERROR hidden lifetime parameters
42+
43+
let _use_via_binding: ContainsLifetime;
44+
//~^ ERROR hidden lifetime parameters
45+
46+
<ContainsLifetime as UseViaTrait>::use_it();
47+
//~^ ERROR hidden lifetime parameters
48+
49+
<ContainsLifetime>::use_it();
50+
//~^ ERROR hidden lifetime parameters
51+
52+
ContainsLifetime::use_it();
53+
54+
ContainsLifetimeAndType::<u8>::use_it();
55+
56+
<u8 as TraitWithLifetime>::use_it();
57+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
error: hidden lifetime parameters in types are deprecated
2+
--> $DIR/elided-lifetimes-in-type-paths.rs:36:24
3+
|
4+
LL | static USE_VIA_STATIC: ContainsLifetime = ContainsLifetime(&42);
5+
| ^^^^^^^^^^^^^^^^ expected lifetime parameter
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/elided-lifetimes-in-type-paths.rs:1:9
9+
|
10+
LL | #![deny(elided_lifetimes_in_paths)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
12+
help: indicate the anonymous lifetime
13+
|
14+
LL | static USE_VIA_STATIC: ContainsLifetime<'_> = ContainsLifetime(&42);
15+
| ++++
16+
17+
error: hidden lifetime parameters in types are deprecated
18+
--> $DIR/elided-lifetimes-in-type-paths.rs:40:25
19+
|
20+
LL | use_via_turbofish::<ContainsLifetime>();
21+
| ^^^^^^^^^^^^^^^^ expected lifetime parameter
22+
|
23+
help: indicate the anonymous lifetime
24+
|
25+
LL | use_via_turbofish::<ContainsLifetime<'_>>();
26+
| ++++
27+
28+
error: hidden lifetime parameters in types are deprecated
29+
--> $DIR/elided-lifetimes-in-type-paths.rs:43:27
30+
|
31+
LL | let _use_via_binding: ContainsLifetime;
32+
| ^^^^^^^^^^^^^^^^ expected lifetime parameter
33+
|
34+
help: indicate the anonymous lifetime
35+
|
36+
LL | let _use_via_binding: ContainsLifetime<'_>;
37+
| ++++
38+
39+
error: hidden lifetime parameters in types are deprecated
40+
--> $DIR/elided-lifetimes-in-type-paths.rs:46:6
41+
|
42+
LL | <ContainsLifetime as UseViaTrait>::use_it();
43+
| ^^^^^^^^^^^^^^^^ expected lifetime parameter
44+
|
45+
help: indicate the anonymous lifetime
46+
|
47+
LL | <ContainsLifetime<'_> as UseViaTrait>::use_it();
48+
| ++++
49+
50+
error: hidden lifetime parameters in types are deprecated
51+
--> $DIR/elided-lifetimes-in-type-paths.rs:49:6
52+
|
53+
LL | <ContainsLifetime>::use_it();
54+
| ^^^^^^^^^^^^^^^^ expected lifetime parameter
55+
|
56+
help: indicate the anonymous lifetime
57+
|
58+
LL | <ContainsLifetime<'_>>::use_it();
59+
| ++++
60+
61+
error: aborting due to 5 previous errors
62+

0 commit comments

Comments
 (0)