This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +171
-0
lines changed
tests/ui/lint/elided-named-lifetimes Expand file tree Collapse file tree 6 files changed +171
-0
lines changed Original file line number Diff line number Diff line change 1+ #![ deny( elided_named_lifetimes) ]
2+
3+ struct Foo ;
4+
5+ impl Foo {
6+ pub fn get_mut ( & ' static self , x : & mut u8 ) -> & mut u8 {
7+ //~^ ERROR elided lifetime has a name
8+ unsafe { & mut * ( x as * mut _ ) }
9+ }
10+ }
11+
12+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ error: elided lifetime has a name
2+ --> $DIR/example-from-issue48686.rs:6:50
3+ |
4+ LL | pub fn get_mut(&'static self, x: &mut u8) -> &mut u8 {
5+ | ^ this elided lifetime gets resolved as `'static`
6+ |
7+ note: the lint level is defined here
8+ --> $DIR/example-from-issue48686.rs:1:9
9+ |
10+ LL | #![deny(elided_named_lifetimes)]
11+ | ^^^^^^^^^^^^^^^^^^^^^^
12+
13+ error: aborting due to 1 previous error
14+
Original file line number Diff line number Diff line change 1+ #![ deny( elided_named_lifetimes) ]
2+
3+ fn ampersand < ' a > ( x : & ' a u8 ) -> & u8 {
4+ //~^ ERROR elided lifetime has a name
5+ x
6+ }
7+
8+ struct Brackets < ' a > ( & ' a u8 ) ;
9+
10+ fn brackets < ' a > ( x : & ' a u8 ) -> Brackets {
11+ //~^ ERROR elided lifetime has a name
12+ Brackets ( x)
13+ }
14+
15+ struct Comma < ' a , T > ( & ' a T ) ;
16+
17+ fn comma < ' a > ( x : & ' a u8 ) -> Comma < u8 > {
18+ //~^ ERROR elided lifetime has a name
19+ Comma ( x)
20+ }
21+
22+ fn underscore < ' a > ( x : & ' a u8 ) -> & ' _ u8 {
23+ //~^ ERROR elided lifetime has a name
24+ x
25+ }
26+
27+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ error: elided lifetime has a name
2+ --> $DIR/missing-lifetime-kind.rs:3:32
3+ |
4+ LL | fn ampersand<'a>(x: &'a u8) -> &u8 {
5+ | -- ^ this elided lifetime gets resolved as `'a`
6+ | |
7+ | lifetime `'a` declared here
8+ |
9+ note: the lint level is defined here
10+ --> $DIR/missing-lifetime-kind.rs:1:9
11+ |
12+ LL | #![deny(elided_named_lifetimes)]
13+ | ^^^^^^^^^^^^^^^^^^^^^^
14+
15+ error: elided lifetime has a name
16+ --> $DIR/missing-lifetime-kind.rs:10:31
17+ |
18+ LL | fn brackets<'a>(x: &'a u8) -> Brackets {
19+ | -- ^^^^^^^^ this elided lifetime gets resolved as `'a`
20+ | |
21+ | lifetime `'a` declared here
22+
23+ error: elided lifetime has a name
24+ --> $DIR/missing-lifetime-kind.rs:17:33
25+ |
26+ LL | fn comma<'a>(x: &'a u8) -> Comma<u8> {
27+ | -- ^ this elided lifetime gets resolved as `'a`
28+ | |
29+ | lifetime `'a` declared here
30+
31+ error: elided lifetime has a name
32+ --> $DIR/missing-lifetime-kind.rs:22:34
33+ |
34+ LL | fn underscore<'a>(x: &'a u8) -> &'_ u8 {
35+ | -- ^^ this elided lifetime gets resolved as `'a`
36+ | |
37+ | lifetime `'a` declared here
38+
39+ error: aborting due to 4 previous errors
40+
Original file line number Diff line number Diff line change 1+ #![ deny( elided_named_lifetimes) ]
2+
3+ use std:: borrow:: Cow ;
4+
5+ const A : & [ u8 ] = & [ ] ;
6+ static B : & str = "hello" ;
7+
8+ trait Trait {
9+ const C : & u8 = & 0 ;
10+ }
11+
12+ impl Trait for ( ) {
13+ const C : & u8 = & 1 ;
14+ }
15+
16+ fn ampersand ( x : & ' static u8 ) -> & u8 {
17+ //~^ ERROR elided lifetime has a name
18+ x
19+ }
20+
21+ struct Brackets < ' a > ( & ' a u8 ) ;
22+
23+ fn brackets ( x : & ' static u8 ) -> Brackets {
24+ //~^ ERROR elided lifetime has a name
25+ Brackets ( x)
26+ }
27+
28+ struct Comma < ' a , T > ( & ' a T ) ;
29+
30+ fn comma ( x : & ' static u8 ) -> Comma < u8 > {
31+ //~^ ERROR elided lifetime has a name
32+ Comma ( x)
33+ }
34+
35+ fn underscore ( x : & ' static u8 ) -> & ' _ u8 {
36+ //~^ ERROR elided lifetime has a name
37+ x
38+ }
39+
40+ const NESTED : & Vec < & Box < Cow < str > > > = & vec ! [ ] ;
41+
42+ fn main ( ) {
43+ const HELLO : & str = "Hello" ;
44+ static WORLD : & str = "world" ;
45+ println ! ( "{HELLO}, {WORLD}!" )
46+ }
Original file line number Diff line number Diff line change 1+ error: elided lifetime has a name
2+ --> $DIR/static.rs:16:33
3+ |
4+ LL | fn ampersand(x: &'static u8) -> &u8 {
5+ | ^ this elided lifetime gets resolved as `'static`
6+ |
7+ note: the lint level is defined here
8+ --> $DIR/static.rs:1:9
9+ |
10+ LL | #![deny(elided_named_lifetimes)]
11+ | ^^^^^^^^^^^^^^^^^^^^^^
12+
13+ error: elided lifetime has a name
14+ --> $DIR/static.rs:23:32
15+ |
16+ LL | fn brackets(x: &'static u8) -> Brackets {
17+ | ^^^^^^^^ this elided lifetime gets resolved as `'static`
18+
19+ error: elided lifetime has a name
20+ --> $DIR/static.rs:30:34
21+ |
22+ LL | fn comma(x: &'static u8) -> Comma<u8> {
23+ | ^ this elided lifetime gets resolved as `'static`
24+
25+ error: elided lifetime has a name
26+ --> $DIR/static.rs:35:35
27+ |
28+ LL | fn underscore(x: &'static u8) -> &'_ u8 {
29+ | ^^ this elided lifetime gets resolved as `'static`
30+
31+ error: aborting due to 4 previous errors
32+
You can’t perform that action at this time.
0 commit comments