Skip to content

Commit 48ae3e0

Browse files
committed
Test elided-lifetimes-in-paths outside of function signatures
1 parent 26830c7 commit 48ae3e0

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 foo() {}
12+
}
13+
14+
fn use_via_turbofish<T>() {}
15+
16+
trait UseViaTrait {
17+
fn use_it(&self) {}
18+
}
19+
20+
impl UseViaTrait for ContainsLifetime<'_> {}
21+
22+
// ==========
23+
24+
static USE_VIA_STATIC: ContainsLifetime = ContainsLifetime(&42);
25+
//~^ ERROR hidden lifetime parameters
26+
27+
fn main() {
28+
use_via_turbofish::<ContainsLifetime>();
29+
//~^ ERROR hidden lifetime parameters
30+
31+
let _use_via_binding: ContainsLifetime;
32+
//~^ ERROR hidden lifetime parameters
33+
34+
_ = <ContainsLifetime as UseViaTrait>::use_it;
35+
//~^ ERROR hidden lifetime parameters
36+
37+
ContainsLifetime::foo();
38+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
error: hidden lifetime parameters in types are deprecated
2+
--> $DIR/elided-lifetimes-in-type-paths.rs:24: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:28: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:31: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:34:10
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: aborting due to 4 previous errors
51+

0 commit comments

Comments
 (0)