-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Correctly deny late-bound lifetimes from parent in anon consts and TAITs #115486
Merged
Merged
Changes from all commits
Commits
Show all changes
2 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 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
30 changes: 20 additions & 10 deletions
30
tests/ui/const-generics/late-bound-vars/in_closure.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,10 +1,20 @@ | ||
#0 [mir_borrowck] borrow-checking `test::{closure#0}::{constant#1}` | ||
#1 [mir_drops_elaborated_and_const_checked] elaborating drops for `test::{closure#0}::{constant#1}` | ||
#2 [mir_for_ctfe] caching mir of `test::{closure#0}::{constant#1}` for CTFE | ||
#3 [eval_to_allocation_raw] const-evaluating + checking `test::{closure#0}::{constant#1}` | ||
#4 [eval_to_allocation_raw] const-evaluating + checking `test::{closure#0}::{constant#1}` | ||
#5 [eval_to_valtree] evaluating type-level constant | ||
#6 [typeck] type-checking `test` | ||
#7 [analysis] running analysis passes on this crate | ||
end of query stack | ||
error: aborting due to previous error | ||
error: cannot capture late-bound lifetime in constant | ||
--> $DIR/in_closure.rs:16:29 | ||
| | ||
LL | fn test<'a>() { | ||
| -- lifetime defined here | ||
LL | let _ = || { | ||
LL | let _: [u8; inner::<'a>()]; | ||
| ^^ | ||
|
||
error: cannot capture late-bound lifetime in constant | ||
--> $DIR/in_closure.rs:17:29 | ||
| | ||
LL | fn test<'a>() { | ||
| -- lifetime defined here | ||
... | ||
LL | let _ = [0; inner::<'a>()]; | ||
| ^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
13 changes: 13 additions & 0 deletions
13
tests/ui/const-generics/late-bound-vars/late-bound-in-return-issue-77357.rs
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,13 @@ | ||
// known-bug: unknown | ||
// see comment on `tests/ui/const-generics/late-bound-vars/simple.rs` | ||
|
||
#![feature(generic_const_exprs)] | ||
#![allow(incomplete_features)] | ||
|
||
trait MyTrait<T> {} | ||
|
||
fn bug<'a, T>() -> &'static dyn MyTrait<[(); { |x: &'a u32| { x }; 4 }]> { | ||
todo!() | ||
} | ||
|
||
fn main() {} |
8 changes: 8 additions & 0 deletions
8
tests/ui/const-generics/late-bound-vars/late-bound-in-return-issue-77357.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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: cannot capture late-bound lifetime in constant | ||
--> $DIR/late-bound-in-return-issue-77357.rs:9:53 | ||
| | ||
LL | fn bug<'a, T>() -> &'static dyn MyTrait<[(); { |x: &'a u32| { x }; 4 }]> { | ||
| -- lifetime defined here ^^ | ||
|
||
error: aborting due to previous error | ||
|
15 changes: 15 additions & 0 deletions
15
tests/ui/const-generics/late-bound-vars/late-bound-in-where-issue-83993.rs
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,15 @@ | ||
// known-bug: unknown | ||
// see comment on `tests/ui/const-generics/late-bound-vars/simple.rs` | ||
|
||
#![feature(generic_const_exprs)] | ||
#![allow(incomplete_features)] | ||
|
||
fn bug<'a>() | ||
where | ||
for<'b> [(); { | ||
let x: &'b (); | ||
0 | ||
}]: | ||
{} | ||
|
||
fn main() {} |
10 changes: 10 additions & 0 deletions
10
tests/ui/const-generics/late-bound-vars/late-bound-in-where-issue-83993.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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error: cannot capture late-bound lifetime in constant | ||
--> $DIR/late-bound-in-where-issue-83993.rs:10:17 | ||
| | ||
LL | for<'b> [(); { | ||
| -- lifetime defined here | ||
LL | let x: &'b (); | ||
| ^^ | ||
|
||
error: aborting due to previous error | ||
|
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
Oops, something went wrong.
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.
Both this branch and the next (
if let Some(body_id) = outermost_body
) should only be executed for late-bound variables. Should they both be in anif let ResolvedArg::LateBound(_, _, param_def_id) = def
to make it clearer?For my curiosity, what would happen if we made lifetimes in anon-consts
ResolvedArg::Free
?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.
See my comment here #115486 (comment), I kinda went into it there -- this idea would, in fact, fix at least tests like
const-generics/late-bound-vars/in_closure.rs
andconst-generics/late-bound-vars/simple.rs
, and was how #79298 worked, afaict.It doesn't seem like a general solution, though, since when it comes to, e.g., a binder on a where clause like
where for<'a> [(); { /* const that uses 'a */ }]: ...
, it doesn't really make sense to useReFree
for that usage of'a
, since the late-bound region does not originate from the function's generics (and therefore thefn_sig
's binder).This also doesn't lead us towards a correct solution for handling things like
for<const C: usize> [(); C]: ...
, since there's no equivalent notion of a "free" type or const var (nor does it make sense, since they must be substitutable).