-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
trait solver: Include implied outlives assumptions #162238
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
rust-bors
merged 3 commits into
rust-lang:main
from
Dnreikronos:trait_solver/implied_outlives_assumptions
Sep 9, 2026
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
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
33 changes: 33 additions & 0 deletions
33
tests/ui/assumptions_on_binders/supertrait-implied-outlives-assumptions.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,33 @@ | ||
| //@ check-pass | ||
| //@ compile-flags: -Zassumptions-on-binders -Znext-solver=globally | ||
|
|
||
| // A trait clause implies its supertraits, so a `&'x (): Bound<'x>` requirement is also evidence | ||
| // for `&'x (): 'static`, which elaborates to the region assumption `'x: 'static`. | ||
| // `Assumptions::new` therefore takes clauses and elaborates them itself; handing it only the | ||
| // outlives clauses would drop the trait clause before it could imply anything. | ||
| // | ||
| // The clause has to mention the binder's own `'x` to survive the `max_universe == u` filter, | ||
| // while the supertrait outlives is on `'static` so that the assumption can discharge `'x: 'a`. | ||
| // | ||
| // Keeping the requirement binder-local matters: the `for<'x> Wrap<'x>: 'a` bound is proven at the | ||
| // call site below, so failing to discharge `'x: 'a` is a `NoSolution` inside the solver rather | ||
| // than a constraint escaping to the root. Constraints reaching the root are still dropped, so a | ||
| // shape which lets `'x` escape (e.g. requiring `T: 'x` for an outer `T`) would pass either way. | ||
| // Removing the `&'x (): Bound<'x>` clause below makes this fail, as does dropping trait clauses | ||
| // before elaborating. | ||
|
|
||
| trait Bound<'c>: 'static {} | ||
|
|
||
| struct Wrap<'x>(&'x ()) | ||
| where | ||
| &'x (): Bound<'x>; | ||
|
|
||
| fn foo<'a>(_a: &'a u32) | ||
| where | ||
| for<'x> Wrap<'x>: 'a, | ||
| { | ||
| } | ||
|
|
||
| fn main() { | ||
| foo(&10); | ||
| } |
26 changes: 26 additions & 0 deletions
26
tests/ui/assumptions_on_binders/type-outlives-assumptions.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,26 @@ | ||
| //@ check-pass | ||
| //@ compile-flags: -Zassumptions-on-binders | ||
|
|
||
| // Regression test for rust-lang/project-assumptions-on-binders#19, based on the `syn` failure. | ||
| // The receiver gives us an implied `I: 'b` bound and `'b: 'a` lets that satisfy the object | ||
| // lifetime. The implied type bound has to be included in the root assumptions for that to work. | ||
| trait IterTrait<'a, T: 'a>: Iterator<Item = &'a T> { | ||
| fn clone_box<'b>(&'b self) -> Box<dyn IterTrait<'a, T> + 'a> | ||
| where | ||
| 'b: 'a; | ||
| } | ||
|
|
||
| impl<'a, T, I> IterTrait<'a, T> for I | ||
| where | ||
| T: 'a, | ||
| I: Iterator<Item = &'a T> + Clone, | ||
| { | ||
| fn clone_box<'b>(&'b self) -> Box<dyn IterTrait<'a, T> + 'a> | ||
| where | ||
| 'b: 'a, | ||
| { | ||
| Box::new(self.clone()) | ||
| } | ||
| } | ||
|
|
||
| fn main() {} |
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.
Uh oh!
There was an error while loading. Please reload this page.