-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Normalize region obligation in lexical region resolution with next-gen solver #119101
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
+211
−70
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e11a6a9
No need to pass region bound pairs to resolve_regions_with_wf_tys
compiler-errors 028d293
Deeply normalize when processing registered region obligations
compiler-errors fef38a6
Normalize caller bounds
compiler-errors dc050f6
Add a test
compiler-errors 720d7a7
Apply suggestions from review
compiler-errors 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use rustc_infer::infer::outlives::env::OutlivesEnvironment; | ||
use rustc_infer::infer::{InferCtxt, RegionResolutionError}; | ||
use rustc_middle::traits::ObligationCause; | ||
|
||
pub trait InferCtxtRegionExt<'tcx> { | ||
/// Resolve regions, using the deep normalizer to normalize any type-outlives | ||
/// obligations in the process. This is in `rustc_trait_selection` because | ||
/// we need to normalize. | ||
/// | ||
/// Prefer this method over `resolve_regions_with_normalize`, unless you are | ||
/// doing something specific for normalization. | ||
fn resolve_regions( | ||
&self, | ||
outlives_env: &OutlivesEnvironment<'tcx>, | ||
) -> Vec<RegionResolutionError<'tcx>>; | ||
} | ||
|
||
impl<'tcx> InferCtxtRegionExt<'tcx> for InferCtxt<'tcx> { | ||
fn resolve_regions( | ||
&self, | ||
outlives_env: &OutlivesEnvironment<'tcx>, | ||
) -> Vec<RegionResolutionError<'tcx>> { | ||
self.resolve_regions_with_normalize(outlives_env, |ty, origin| { | ||
let ty = self.resolve_vars_if_possible(ty); | ||
|
||
if self.next_trait_solver() { | ||
crate::solve::deeply_normalize( | ||
self.at( | ||
&ObligationCause::dummy_with_span(origin.span()), | ||
outlives_env.param_env, | ||
), | ||
ty, | ||
) | ||
.map_err(|_| ty) | ||
} else { | ||
Ok(ty) | ||
} | ||
}) | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
tests/ui/traits/next-solver/normalize-region-obligations.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,22 @@ | ||
// revisions: normalize_param_env normalize_obligation | ||
// check-pass | ||
// compile-flags: -Znext-solver | ||
|
||
trait Foo { | ||
#[cfg(normalize_param_env)] | ||
type Gat<'a> where <Self as Mirror>::Assoc: 'a; | ||
#[cfg(normalize_obligation)] | ||
type Gat<'a> where Self: 'a; | ||
} | ||
|
||
trait Mirror { type Assoc: ?Sized; } | ||
impl<T: ?Sized> Mirror for T { type Assoc = T; } | ||
|
||
impl<T> Foo for T { | ||
#[cfg(normalize_param_env)] | ||
type Gat<'a> = i32 where T: 'a; | ||
#[cfg(normalize_obligation)] | ||
type Gat<'a> = i32 where <T as Mirror>::Assoc: 'a; | ||
} | ||
|
||
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
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//~ ERROR the type `<() as StaticTy>::Item<'a>` does not fulfill the required lifetime | ||
// compile-flags: -Znext-solver | ||
// Regression test for rust-lang/trait-system-refactor-initiative#59 | ||
|
||
trait StaticTy { | ||
type Item<'a>: 'static; | ||
} | ||
|
||
impl StaticTy for () { | ||
type Item<'a> = &'a (); | ||
} | ||
|
||
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,7 @@ | ||
error[E0477]: the type `<() as StaticTy>::Item<'a>` does not fulfill the required lifetime | ||
| | ||
= note: type must satisfy the static lifetime | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0477`. |
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.