Skip to content

Commit 615e373

Browse files
committed
Test elided-lifetimes-in-paths outside of function signatures
1 parent 7d82b83 commit 615e373

File tree

2 files changed

+145
-0
lines changed

2 files changed

+145
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
enum EnumWithType<T> {
35+
VariantStructLike { v: T },
36+
VariantTupleLike(T),
37+
VariantUnit,
38+
}
39+
40+
type TypeAliasWithLifetime<'a> = EnumWithType<&'a u8>;
41+
42+
// ==========
43+
44+
static USE_VIA_STATIC: ContainsLifetime = ContainsLifetime(&42);
45+
//~^ ERROR hidden lifetime parameters
46+
47+
fn main() {
48+
use_via_turbofish::<ContainsLifetime>();
49+
//~^ ERROR hidden lifetime parameters
50+
51+
let _use_via_binding: ContainsLifetime;
52+
//~^ ERROR hidden lifetime parameters
53+
54+
<ContainsLifetime as UseViaTrait>::use_it();
55+
//~^ ERROR hidden lifetime parameters
56+
57+
<ContainsLifetime>::use_it();
58+
//~^ ERROR hidden lifetime parameters
59+
60+
ContainsLifetime::use_it();
61+
62+
ContainsLifetimeAndType::<u8>::use_it();
63+
64+
<u8 as TraitWithLifetime>::use_it();
65+
}
66+
67+
impl TypeAliasWithLifetime<'_> {
68+
fn use_via_match(self) {
69+
match self {
70+
TypeAliasWithLifetime::VariantStructLike { .. } => (),
71+
TypeAliasWithLifetime::VariantTupleLike(_) => (),
72+
TypeAliasWithLifetime::VariantUnit => (),
73+
}
74+
}
75+
76+
fn use_via_create(v: u8) -> Self {
77+
match v {
78+
0 => TypeAliasWithLifetime::VariantStructLike { v: &42 },
79+
1 => TypeAliasWithLifetime::VariantTupleLike(&42),
80+
_ => TypeAliasWithLifetime::VariantUnit,
81+
}
82+
}
83+
}
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:44: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:48: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:51: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:54: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:57: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)