-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #115011 - compiler-errors:warn-on-elided-assoc-ct-lt,…
… r=cjgillot Warn on elided lifetimes in associated constants (`ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT`) Elided lifetimes in associated constants (in impls) erroneously resolve to fresh lifetime parameters on the impl since #97313. This is not correct behavior (see #38831). I originally opened #114716 to fix this, but given the time that has passed, the crater results seem pretty bad: #114716 (comment) This PR alternatively implements a lint against this behavior, and I'm hoping to bump this to deny in a few versions.
- Loading branch information
Showing
10 changed files
with
180 additions
and
27 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
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 | ||
|