-
-
Notifications
You must be signed in to change notification settings - Fork 16.1k
Normalize non-rigid aliases in ty_known_to_outlive #161246
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
Open
amirHdev
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
amirHdev:fix-161067-non-rigid-alias
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 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 |
|---|---|---|
|
|
@@ -5,9 +5,11 @@ use rustc_infer::infer::{ | |
| InferCtxt, RegionResolutionError, SubregionOrigin, TyCtxtInferExt, TypeOutlivesConstraint, | ||
| }; | ||
| use rustc_macros::extension; | ||
| use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt, TypingMode, elaborate}; | ||
| use rustc_middle::traits::ObligationCause; | ||
| use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt, TypingMode, Unnormalized, elaborate}; | ||
| use rustc_span::DUMMY_SP; | ||
|
|
||
| use crate::traits::ScrubbedTraitError; | ||
| use crate::traits::outlives_bounds::InferCtxtExt; | ||
|
|
||
| #[extension(pub trait OutlivesEnvironmentBuildExt<'tcx>)] | ||
|
|
@@ -90,15 +92,30 @@ pub fn ty_known_to_outlive<'tcx>( | |
| id: LocalDefId, | ||
| param_env: ty::ParamEnv<'tcx>, | ||
| wf_tys: &FxIndexSet<Ty<'tcx>>, | ||
| ty: Ty<'tcx>, | ||
| ty: Unnormalized<'tcx, Ty<'tcx>>, | ||
| region: ty::Region<'tcx>, | ||
| ) -> bool { | ||
| test_region_obligations(tcx, id, param_env, wf_tys, |infcx| { | ||
| // Types in region obligations should be normalized. | ||
| let ty = if infcx.next_trait_solver() { | ||
| let Ok(ty) = crate::solve::deeply_normalize::<_, ScrubbedTraitError<'tcx>>( | ||
| infcx.at(&ObligationCause::dummy_with_span(DUMMY_SP), param_env), | ||
| ty, | ||
| ) else { | ||
| return Err(()); | ||
| }; | ||
| ty | ||
| } else { | ||
| ty.skip_norm_wip() | ||
| }; | ||
|
|
||
| infcx.register_type_outlives_constraint_inner(TypeOutlivesConstraint { | ||
| sub_region: region, | ||
| sup_type: ty, | ||
| origin: SubregionOrigin::RelateParamBound(DUMMY_SP, ty, None), | ||
| }); | ||
|
|
||
| Ok(()) | ||
| }) | ||
| } | ||
|
|
||
|
|
@@ -119,6 +136,7 @@ pub fn region_known_to_outlive<'tcx>( | |
| region_a, | ||
| ty::VisibleForLeakCheck::Unreachable, | ||
| ); | ||
| Ok(()) | ||
| }) | ||
| } | ||
|
|
||
|
|
@@ -130,14 +148,16 @@ pub fn test_region_obligations<'tcx>( | |
| id: LocalDefId, | ||
| param_env: ty::ParamEnv<'tcx>, | ||
| wf_tys: &FxIndexSet<Ty<'tcx>>, | ||
| add_constraints: impl FnOnce(&InferCtxt<'tcx>), | ||
| add_constraints: impl FnOnce(&InferCtxt<'tcx>) -> Result<(), ()>, | ||
| ) -> bool { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't have to do it in this PR, but you can also return |
||
| // Unfortunately, we have to use a new `InferCtxt` each call, because | ||
| // region constraints get added and solved there and we need to test each | ||
| // call individually. | ||
| let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis()); | ||
|
|
||
| add_constraints(&infcx); | ||
| if add_constraints(&infcx).is_err() { | ||
| return false; | ||
| } | ||
|
|
||
| let errors = infcx.resolve_regions(id, param_env, wf_tys.iter().copied()); | ||
| tracing::debug!(?errors, "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
16 changes: 16 additions & 0 deletions
16
tests/ui/assumptions_on_binders/nested-gat-outlives-issue-161067.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,16 @@ | ||
| //@ compile-flags: -Zassumptions-on-binders | ||
| //@ needs-rustc-debug-assertions | ||
|
|
||
| // Regression test for #161067. A nested non-rigid alias must be normalized | ||
| // before it reaches lexical region solving through `ty_known_to_outlive`. | ||
|
|
||
| struct D; | ||
|
|
||
| trait Des { | ||
| type Out<'x, T>; | ||
| //~^ ERROR missing required bound on `Out` | ||
|
|
||
| fn des<'z>() -> Self::Out<'z, Self::Out<'z, D>>; | ||
| } | ||
|
|
||
| fn main() {} |
13 changes: 13 additions & 0 deletions
13
tests/ui/assumptions_on_binders/nested-gat-outlives-issue-161067.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,13 @@ | ||
| error: missing required bound on `Out` | ||
| --> $DIR/nested-gat-outlives-issue-161067.rs:10:5 | ||
| | | ||
| LL | type Out<'x, T>; | ||
| | ^^^^^^^^^^^^^^^- | ||
| | | | ||
| | help: add the required where clause: `where T: 'x` | ||
| | | ||
| = note: this bound is currently required to ensure that impls have maximum flexibility | ||
| = note: we are soliciting feedback, see issue #87479 <https://github.com/rust-lang/rust/issues/87479> for more information | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
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.
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.
we can still use
test_region_obligationsand just normalize thety?View changes since the review
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.
yeah that's the part I overlooked 😬 I reused test_region_obligations here