-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Only mark projection as ambiguous if GAT substs are constrained #93892
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1508,12 +1508,18 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | |
}) | ||
} | ||
|
||
/// Return `Yes` if the obligation's predicate type applies to the env_predicate, and | ||
/// `No` if it does not. Return `Ambiguous` in the case that the projection type is a GAT, | ||
/// and applying this env_predicate constrains any of the obligation's GAT substitutions. | ||
/// | ||
/// This behavior is a somewhat of a hack to prevent overconstraining inference variables | ||
/// in cases like #91762. | ||
pub(super) fn match_projection_projections( | ||
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. Comment is slightly outdated now that the return type has changed to an enum 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. Good catch. |
||
&mut self, | ||
obligation: &ProjectionTyObligation<'tcx>, | ||
env_predicate: PolyProjectionPredicate<'tcx>, | ||
potentially_unnormalized_candidates: bool, | ||
) -> bool { | ||
) -> ProjectionMatchesProjection { | ||
let mut nested_obligations = Vec::new(); | ||
let (infer_predicate, _) = self.infcx.replace_bound_vars_with_fresh_vars( | ||
obligation.cause.span, | ||
|
@@ -1535,7 +1541,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | |
infer_predicate.projection_ty | ||
}; | ||
|
||
self.infcx | ||
let is_match = self | ||
.infcx | ||
.at(&obligation.cause, obligation.param_env) | ||
.define_opaque_types(false) | ||
.sup(obligation.predicate, infer_projection) | ||
|
@@ -1545,7 +1552,26 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | |
nested_obligations.into_iter().chain(obligations), | ||
) | ||
.map_or(false, |res| res.may_apply()) | ||
}) | ||
}); | ||
|
||
if is_match { | ||
let generics = self.tcx().generics_of(obligation.predicate.item_def_id); | ||
// FIXME(generic-associated-types): Addresses aggressive inference in #92917. | ||
// If this type is a GAT, and of the GAT substs resolve to something new, | ||
// that means that we must have newly inferred something about the GAT. | ||
// We should give up in that case. | ||
if !generics.params.is_empty() | ||
&& obligation.predicate.substs[generics.parent_count..] | ||
.iter() | ||
.any(|&p| p.has_infer_types_or_consts() && self.infcx.shallow_resolve(p) != p) | ||
{ | ||
ProjectionMatchesProjection::Ambiguous | ||
} else { | ||
ProjectionMatchesProjection::Yes | ||
} | ||
} else { | ||
ProjectionMatchesProjection::No | ||
} | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////// | ||
|
@@ -2745,3 +2771,9 @@ impl<'o, 'tcx> fmt::Debug for TraitObligationStack<'o, 'tcx> { | |
write!(f, "TraitObligationStack({:?})", self.obligation) | ||
} | ||
} | ||
|
||
pub enum ProjectionMatchesProjection { | ||
Yes, | ||
Ambiguous, | ||
No, | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// check-pass | ||
|
||
#![feature(generic_associated_types)] | ||
|
||
pub trait Build { | ||
type Output<O>; | ||
fn build<O>(self, input: O) -> Self::Output<O>; | ||
} | ||
|
||
pub struct IdentityBuild; | ||
impl Build for IdentityBuild { | ||
type Output<O> = O; | ||
fn build<O>(self, input: O) -> Self::Output<O> { | ||
input | ||
} | ||
} | ||
|
||
fn a() { | ||
let _x: u8 = IdentityBuild.build(10); | ||
} | ||
|
||
fn b() { | ||
let _x: Vec<u8> = IdentityBuild.build(Vec::new()); | ||
} | ||
|
||
fn c() { | ||
let mut f = IdentityBuild.build(|| ()); | ||
(f)(); | ||
} | ||
|
||
pub fn main() { | ||
a(); | ||
b(); | ||
c(); | ||
} |
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.
Is this diff new?
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.
function returns () and the rest have semicolons, but i'll double check