Skip to content

Commit 805397c

Browse files
Add more tests
1 parent 4f97ab5 commit 805397c

7 files changed

+245
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#![deny(elided_lifetimes_in_associated_constant)]
2+
3+
struct Foo<'a>(&'a ());
4+
5+
impl Foo<'_> {
6+
const STATIC: &str = "";
7+
//~^ ERROR `&` without an explicit lifetime name cannot be used here
8+
//~| WARN this was previously accepted by the compiler but is being phased out
9+
}
10+
11+
trait Bar {
12+
const STATIC: &'static str;
13+
// TODO^
14+
}
15+
16+
impl Bar for Foo<'_> {
17+
const STATIC: &str = "";
18+
//~^ ERROR `&` without an explicit lifetime name cannot be used here
19+
//~| WARN this was previously accepted by the compiler but is being phased out
20+
//~| ERROR const not compatible with trait
21+
}
22+
23+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
error: `&` without an explicit lifetime name cannot be used here
2+
--> $DIR/elided-lifetime.rs:6:19
3+
|
4+
LL | const STATIC: &str = "";
5+
| ^
6+
|
7+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8+
= note: for more information, see issue #115010 <https://github.com/rust-lang/rust/issues/115010>
9+
note: cannot automatically infer `'static` because of other lifetimes in scope
10+
--> $DIR/elided-lifetime.rs:5:10
11+
|
12+
LL | impl Foo<'_> {
13+
| ^^
14+
note: the lint level is defined here
15+
--> $DIR/elided-lifetime.rs:1:9
16+
|
17+
LL | #![deny(elided_lifetimes_in_associated_constant)]
18+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19+
help: use the `'static` lifetime
20+
|
21+
LL | const STATIC: &'static str = "";
22+
| +++++++
23+
24+
error: `&` without an explicit lifetime name cannot be used here
25+
--> $DIR/elided-lifetime.rs:17:19
26+
|
27+
LL | const STATIC: &str = "";
28+
| ^
29+
|
30+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
31+
= note: for more information, see issue #115010 <https://github.com/rust-lang/rust/issues/115010>
32+
note: cannot automatically infer `'static` because of other lifetimes in scope
33+
--> $DIR/elided-lifetime.rs:16:18
34+
|
35+
LL | impl Bar for Foo<'_> {
36+
| ^^
37+
help: use the `'static` lifetime
38+
|
39+
LL | const STATIC: &'static str = "";
40+
| +++++++
41+
42+
error[E0308]: const not compatible with trait
43+
--> $DIR/elided-lifetime.rs:17:5
44+
|
45+
LL | const STATIC: &str = "";
46+
| ^^^^^^^^^^^^^^^^^^ lifetime mismatch
47+
|
48+
= note: expected reference `&'static _`
49+
found reference `&_`
50+
note: the anonymous lifetime as defined here...
51+
--> $DIR/elided-lifetime.rs:16:18
52+
|
53+
LL | impl Bar for Foo<'_> {
54+
| ^^
55+
= note: ...does not necessarily outlive the static lifetime
56+
57+
error: aborting due to 3 previous errors
58+
59+
For more information about this error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![deny(elided_lifetimes_in_associated_constant)]
2+
#![feature(generic_const_items)]
3+
//~^ WARN the feature `generic_const_items` is incomplete
4+
5+
struct A;
6+
impl A {
7+
const GAC_TYPE<T>: &str = "";
8+
const GAC_LIFETIME<'a>: &str = "";
9+
//~^ ERROR `&` without an explicit lifetime name cannot be used here
10+
//~| WARN this was previously accepted by the compiler but is being phased out
11+
}
12+
13+
trait Trait {
14+
const GAC_TYPE<T>: &str = "";
15+
//~^ ERROR missing lifetime specifier
16+
const GAC_LIFETIME<'a>: &str = "";
17+
//~^ ERROR missing lifetime specifier
18+
}
19+
20+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
error[E0106]: missing lifetime specifier
2+
--> $DIR/generic-associated-const.rs:14:24
3+
|
4+
LL | const GAC_TYPE<T>: &str = "";
5+
| ^ expected named lifetime parameter
6+
|
7+
help: consider introducing a named lifetime parameter
8+
|
9+
LL | const GAC_TYPE<'a, T>: &'a str = "";
10+
| +++ ++
11+
12+
error[E0106]: missing lifetime specifier
13+
--> $DIR/generic-associated-const.rs:16:29
14+
|
15+
LL | const GAC_LIFETIME<'a>: &str = "";
16+
| ^ expected named lifetime parameter
17+
|
18+
help: consider using the `'a` lifetime
19+
|
20+
LL | const GAC_LIFETIME<'a>: &'a str = "";
21+
| ++
22+
23+
warning: the feature `generic_const_items` is incomplete and may not be safe to use and/or cause compiler crashes
24+
--> $DIR/generic-associated-const.rs:2:12
25+
|
26+
LL | #![feature(generic_const_items)]
27+
| ^^^^^^^^^^^^^^^^^^^
28+
|
29+
= note: see issue #113521 <https://github.com/rust-lang/rust/issues/113521> for more information
30+
= note: `#[warn(incomplete_features)]` on by default
31+
32+
error: `&` without an explicit lifetime name cannot be used here
33+
--> $DIR/generic-associated-const.rs:8:29
34+
|
35+
LL | const GAC_LIFETIME<'a>: &str = "";
36+
| ^
37+
|
38+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
39+
= note: for more information, see issue #115010 <https://github.com/rust-lang/rust/issues/115010>
40+
note: cannot automatically infer `'static` because of other lifetimes in scope
41+
--> $DIR/generic-associated-const.rs:8:24
42+
|
43+
LL | const GAC_LIFETIME<'a>: &str = "";
44+
| ^^
45+
note: the lint level is defined here
46+
--> $DIR/generic-associated-const.rs:1:9
47+
|
48+
LL | #![deny(elided_lifetimes_in_associated_constant)]
49+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
50+
help: use the `'static` lifetime
51+
|
52+
LL | const GAC_LIFETIME<'a>: &'static str = "";
53+
| +++++++
54+
55+
error: aborting due to 3 previous errors; 1 warning emitted
56+
57+
For more information about this error, try `rustc --explain E0106`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@ check-pass
2+
3+
struct Foo<'a>(&'a ());
4+
5+
impl<'a> Foo<'a> {
6+
fn hello(self) {
7+
const INNER: &str = "";
8+
}
9+
}
10+
11+
impl Foo<'_> {
12+
fn implicit(self) {
13+
const INNER: &str = "";
14+
}
15+
16+
fn fn_lifetime(&self) {
17+
const INNER: &str = "";
18+
}
19+
}
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![deny(elided_lifetimes_in_associated_constant)]
2+
3+
trait Bar<'a> {
4+
const STATIC: &'a str;
5+
}
6+
7+
struct A;
8+
impl Bar<'_> for A {
9+
const STATIC: &str = "";
10+
//~^ ERROR `&` without an explicit lifetime name cannot be used here
11+
//~| WARN this was previously accepted by the compiler but is being phased out
12+
//~| ERROR const not compatible with trait
13+
}
14+
15+
struct B;
16+
impl Bar<'static> for B {
17+
const STATIC: &str = "";
18+
}
19+
20+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
error: `&` without an explicit lifetime name cannot be used here
2+
--> $DIR/static-trait-impl.rs:9:19
3+
|
4+
LL | const STATIC: &str = "";
5+
| ^
6+
|
7+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8+
= note: for more information, see issue #115010 <https://github.com/rust-lang/rust/issues/115010>
9+
note: cannot automatically infer `'static` because of other lifetimes in scope
10+
--> $DIR/static-trait-impl.rs:8:10
11+
|
12+
LL | impl Bar<'_> for A {
13+
| ^^
14+
note: the lint level is defined here
15+
--> $DIR/static-trait-impl.rs:1:9
16+
|
17+
LL | #![deny(elided_lifetimes_in_associated_constant)]
18+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19+
help: use the `'static` lifetime
20+
|
21+
LL | const STATIC: &'static str = "";
22+
| +++++++
23+
24+
error[E0308]: const not compatible with trait
25+
--> $DIR/static-trait-impl.rs:9:5
26+
|
27+
LL | const STATIC: &str = "";
28+
| ^^^^^^^^^^^^^^^^^^ lifetime mismatch
29+
|
30+
= note: expected reference `&_`
31+
found reference `&_`
32+
note: the anonymous lifetime as defined here...
33+
--> $DIR/static-trait-impl.rs:8:10
34+
|
35+
LL | impl Bar<'_> for A {
36+
| ^^
37+
note: ...does not necessarily outlive the anonymous lifetime as defined here
38+
--> $DIR/static-trait-impl.rs:8:10
39+
|
40+
LL | impl Bar<'_> for A {
41+
| ^^
42+
43+
error: aborting due to 2 previous errors
44+
45+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)