forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warn on elided lifetimes in associated constants
- Loading branch information
1 parent
6ef7d16
commit fad7d22
Showing
8 changed files
with
178 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 15 additions & 1 deletion
16
tests/ui/associated-consts/infer-placeholder-in-non-suggestable-pos.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
warning: `&` without an explicit lifetime name cannot be used here | ||
--> $DIR/infer-placeholder-in-non-suggestable-pos.rs:6:18 | ||
| | ||
LL | const ASSOC: &dyn Fn(_) = 1i32; | ||
| ^ | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #115010 <https://github.com/rust-lang/rust/issues/115010> | ||
= note: `#[warn(elided_lifetimes_in_associated_constant)]` on by default | ||
help: use the `'static` lifetime | ||
| | ||
LL | const ASSOC: &'static dyn Fn(_) = 1i32; | ||
| +++++++ | ||
|
||
error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants | ||
--> $DIR/infer-placeholder-in-non-suggestable-pos.rs:6:26 | ||
| | ||
LL | const ASSOC: &dyn Fn(_) = 1i32; | ||
| ^ not allowed in type signatures | ||
|
||
error: aborting due to previous error | ||
error: aborting due to previous error; 1 warning emitted | ||
|
||
For more information about this error, try `rustc --explain E0121`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#![deny(elided_lifetimes_in_associated_constant)] | ||
|
||
use std::marker::PhantomData; | ||
|
||
struct Foo<'a> { | ||
x: PhantomData<&'a ()>, | ||
} | ||
|
||
impl<'a> Foo<'a> { | ||
const FOO: Foo<'_> = Foo { x: PhantomData::<&()> }; | ||
//~^ ERROR `'_` cannot be used here | ||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
|
||
const BAR: &() = &(); | ||
//~^ ERROR `&` without an explicit lifetime name cannot be used here | ||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
error: `'_` cannot be used here | ||
--> $DIR/assoc-const-elided-lifetime.rs:10:20 | ||
| | ||
LL | const FOO: Foo<'_> = Foo { x: PhantomData::<&()> }; | ||
| ^^ | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #115010 <https://github.com/rust-lang/rust/issues/115010> | ||
note: the lint level is defined here | ||
--> $DIR/assoc-const-elided-lifetime.rs:1:9 | ||
| | ||
LL | #![deny(elided_lifetimes_in_associated_constant)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
help: use the `'static` lifetime | ||
| | ||
LL | const FOO: Foo<'static> = Foo { x: PhantomData::<&()> }; | ||
| ~~~~~~~ | ||
|
||
error: `&` without an explicit lifetime name cannot be used here | ||
--> $DIR/assoc-const-elided-lifetime.rs:14:16 | ||
| | ||
LL | const BAR: &() = &(); | ||
| ^ | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #115010 <https://github.com/rust-lang/rust/issues/115010> | ||
help: use the `'static` lifetime | ||
| | ||
LL | const BAR: &'static () = &(); | ||
| +++++++ | ||
|
||
error: aborting due to 2 previous errors | ||
|