-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
wf: discard nested obligations with placeholders #103565
Closed
Closed
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// check-pass | ||
struct NeedsCopy<T: Copy>(T); | ||
|
||
// Skips WF because of an escaping bound region. | ||
struct HasWfHigherRanked | ||
where | ||
(for<'a> fn(NeedsCopy<&'a mut u32>)):, | ||
{} | ||
|
||
// Skips WF because of a placeholder region. | ||
struct HasWfPlaceholder | ||
where | ||
for<'a> NeedsCopy<&'a mut u32>:, | ||
{} | ||
|
||
fn main() { | ||
let _: HasWfHigherRanked; | ||
let _: HasWfPlaceholder; | ||
} |
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,17 @@ | ||
// Checks that manual WF bounds are not use for implied bounds. | ||
// | ||
// With the current implementation for WF check, this can easily cause | ||
// unsoundness, as wf does not emit any obligations containing | ||
// placeholders or bound variables. | ||
struct MyStruct<T, U>(T, U); | ||
|
||
trait Foo<'a, 'b> {} | ||
|
||
// IF THIS TEST STOPS EMITTING ERRORS, PLEASE NOTIFY T-TYPES TO CHECK WHETHER THE CHANGE IS SOUND. | ||
impl<'a, 'b> Foo<'a, 'b> for () //~ ERROR cannot infer an appropriate lifetime | ||
where | ||
&'a &'b ():, | ||
//~^ ERROR in type `&'a &'b ()`, reference has a longer lifetime than the data it references | ||
{} | ||
|
||
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,45 @@ | ||
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'b` due to conflicting requirements | ||
--> $DIR/on-impl-not-implied.rs:11:14 | ||
| | ||
LL | impl<'a, 'b> Foo<'a, 'b> for () | ||
| ^^^^^^^^^^^ | ||
| | ||
note: first, the lifetime cannot outlive the lifetime `'b` as defined here... | ||
--> $DIR/on-impl-not-implied.rs:11:10 | ||
| | ||
LL | impl<'a, 'b> Foo<'a, 'b> for () | ||
| ^^ | ||
note: ...but the lifetime must also be valid for the lifetime `'a` as defined here... | ||
--> $DIR/on-impl-not-implied.rs:11:6 | ||
| | ||
LL | impl<'a, 'b> Foo<'a, 'b> for () | ||
| ^^ | ||
note: ...so that the types are compatible | ||
--> $DIR/on-impl-not-implied.rs:11:14 | ||
| | ||
LL | impl<'a, 'b> Foo<'a, 'b> for () | ||
| ^^^^^^^^^^^ | ||
= note: expected `Foo<'a, 'b>` | ||
found `Foo<'_, '_>` | ||
|
||
error[E0491]: in type `&'a &'b ()`, reference has a longer lifetime than the data it references | ||
--> $DIR/on-impl-not-implied.rs:13:5 | ||
| | ||
LL | &'a &'b ():, | ||
| ^^^^^^^^^^ | ||
| | ||
note: the pointer is valid for the lifetime `'a` as defined here | ||
--> $DIR/on-impl-not-implied.rs:11:6 | ||
| | ||
LL | impl<'a, 'b> Foo<'a, 'b> for () | ||
| ^^ | ||
note: but the referenced data is only valid for the lifetime `'b` as defined here | ||
--> $DIR/on-impl-not-implied.rs:11:10 | ||
| | ||
LL | impl<'a, 'b> Foo<'a, 'b> for () | ||
| ^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0491, E0495. | ||
For more information about an error, try `rustc --explain E0491`. |
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,21 @@ | ||
// check-pass | ||
trait Foo<A> {} | ||
impl<'a, T: Foo<A>, A> Foo<A> for &'a mut T | ||
where | ||
// Needed to use `(A,)` because `A:` by itself doesn't emit a WF bound | ||
// as of writing this comment. | ||
// | ||
// This happens in `fn explicit_predicates_of`. | ||
(A,):, | ||
{} | ||
|
||
fn tragic<T, F: for<'a> Foo<&'a T>>(_: F) {} | ||
fn oh_no<T, F: for<'a> Foo<&'a T>>(mut f: F) { | ||
// This results in a `for<'a> WF(&'a T)` bound where `'a` is replaced | ||
// with a placeholder before we compute the wf requirements. | ||
// | ||
// This bound would otherwise result in a `T: 'static` bound. | ||
tragic::<T, _>(&mut f); | ||
} | ||
|
||
fn main() {} |
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.
Maybe make this a method on TypeVisitable and add warning doc comments on has_escaping_bound_var