-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Implement 2024-edition lifetime capture rules RFC #116952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bors
merged 3 commits into
rust-lang:master
from
compiler-errors:lifetime_capture_rules_2024
Dec 10, 2023
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -929,6 +929,7 @@ symbols! { | |
lib, | ||
libc, | ||
lifetime, | ||
lifetime_capture_rules_2024, | ||
lifetimes, | ||
likely, | ||
line, | ||
|
6 changes: 6 additions & 0 deletions
6
tests/ui/feature-gates/feature-gate-lifetime-capture-rules-2024.rs
This file contains hidden or 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,6 @@ | ||
fn foo(x: &Vec<i32>) -> impl Sized { | ||
x | ||
//~^ ERROR hidden type for `impl Sized` captures lifetime that does not appear in bounds | ||
} | ||
|
||
fn main() {} |
18 changes: 18 additions & 0 deletions
18
tests/ui/feature-gates/feature-gate-lifetime-capture-rules-2024.stderr
This file contains hidden or 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,18 @@ | ||
error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds | ||
--> $DIR/feature-gate-lifetime-capture-rules-2024.rs:2:5 | ||
| | ||
LL | fn foo(x: &Vec<i32>) -> impl Sized { | ||
| --------- ---------- opaque type defined here | ||
| | | ||
| hidden type `&Vec<i32>` captures the anonymous lifetime defined here | ||
LL | x | ||
| ^ | ||
| | ||
help: to declare that `impl Sized` captures `'_`, you can add an explicit `'_` lifetime bound | ||
| | ||
LL | fn foo(x: &Vec<i32>) -> impl Sized + '_ { | ||
| ++++ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0700`. |
This file contains hidden or 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,14 @@ | ||
// known-bug: #117647 | ||
|
||
#![feature(lifetime_capture_rules_2024)] | ||
#![feature(rustc_attrs)] | ||
#![allow(internal_features)] | ||
#![rustc_variance_of_opaques] | ||
|
||
use std::ops::Deref; | ||
|
||
fn foo(x: Vec<i32>) -> Box<dyn for<'a> Deref<Target = impl ?Sized>> { | ||
Box::new(x) | ||
} | ||
|
||
fn main() {} |
This file contains hidden or 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,9 @@ | ||
error[E0657]: `impl Trait` can only capture lifetimes bound at the fn or impl level | ||
--> $DIR/implicit-capture-late.rs:10:36 | ||
| | ||
LL | fn foo(x: Vec<i32>) -> Box<dyn for<'a> Deref<Target = impl ?Sized>> { | ||
| ^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0657`. |
This file contains hidden or 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,26 @@ | ||
error: [*, o] | ||
--> $DIR/variance.rs:14:36 | ||
| | ||
LL | fn not_captured_early<'a: 'a>() -> impl Sized {} | ||
| ^^^^^^^^^^ | ||
|
||
error: [*, o] | ||
--> $DIR/variance.rs:19:32 | ||
| | ||
LL | fn captured_early<'a: 'a>() -> impl Sized + Captures<'a> {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: [o] | ||
--> $DIR/variance.rs:21:40 | ||
| | ||
LL | fn not_captured_late<'a>(_: &'a ()) -> impl Sized {} | ||
| ^^^^^^^^^^ | ||
|
||
error: [o] | ||
--> $DIR/variance.rs:26:36 | ||
| | ||
LL | fn captured_late<'a>(_: &'a ()) -> impl Sized + Captures<'a> {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 4 previous errors | ||
|
This file contains hidden or 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,26 @@ | ||
error: [*, o] | ||
--> $DIR/variance.rs:14:36 | ||
| | ||
LL | fn not_captured_early<'a: 'a>() -> impl Sized {} | ||
| ^^^^^^^^^^ | ||
|
||
error: [*, o] | ||
--> $DIR/variance.rs:19:32 | ||
| | ||
LL | fn captured_early<'a: 'a>() -> impl Sized + Captures<'a> {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: [o] | ||
--> $DIR/variance.rs:21:40 | ||
| | ||
LL | fn not_captured_late<'a>(_: &'a ()) -> impl Sized {} | ||
| ^^^^^^^^^^ | ||
|
||
error: [o] | ||
--> $DIR/variance.rs:26:36 | ||
| | ||
LL | fn captured_late<'a>(_: &'a ()) -> impl Sized + Captures<'a> {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 4 previous errors | ||
|
8 changes: 4 additions & 4 deletions
8
tests/ui/impl-trait/variance.stderr → tests/ui/impl-trait/variance.old.stderr
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the RFC:
So until it is stabilized, the feature should be mandatory, even for edition 2024:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The RFC says that we're doing this in Rust 2024. It would make sense to me for this to land in Rust 2024 in nightly without a feature flag.
It does have a dependency, as noted. So if we run into a wall, it would need to be reverted and pulled out of Rust 2024 before stabilization. But that's true of many things we have penciled in for Rust 2024. There are various walls that we could run into and need to pull out other things. This RFC is just very specific about what that wall is.
We're fairly committed to this being stabilized in Rust 2024, so it's likely we'll find a way to avoid it running into this wall. If we fail at that, then we'll need to revert this. But it's better for now to just plan for this going in.