Exclude inherent projections from some alias ty matches

This commit is contained in:
León Orell Valerian Liehr 2023-05-17 19:47:23 +02:00
parent c2ccc855e7
commit 434f08884e
No known key found for this signature in database
GPG Key ID: D17A07215F68E713
6 changed files with 29 additions and 5 deletions

View File

@ -506,10 +506,12 @@ fn assemble_alias_bound_candidates<G: GoalKind<'tcx>>(
| ty::Param(_) | ty::Param(_)
| ty::Placeholder(..) | ty::Placeholder(..)
| ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
| ty::Alias(ty::Inherent, _)
| ty::Error(_) => return, | ty::Error(_) => return,
ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_))
| ty::Bound(..) => bug!("unexpected self type for `{goal:?}`"), | ty::Bound(..) => bug!("unexpected self type for `{goal:?}`"),
ty::Alias(_, alias_ty) => alias_ty, // Excluding IATs here as they don't have meaningful item bounds.
ty::Alias(ty::Projection | ty::Opaque, alias_ty) => alias_ty,
}; };
for assumption in self.tcx().item_bounds(alias_ty.def_id).subst(self.tcx(), alias_ty.substs) for assumption in self.tcx().item_bounds(alias_ty.def_id).subst(self.tcx(), alias_ty.substs)

View File

@ -1543,7 +1543,10 @@ fn assemble_candidates_from_trait_def<'cx, 'tcx>(
// Check whether the self-type is itself a projection. // Check whether the self-type is itself a projection.
// If so, extract what we know from the trait and try to come up with a good answer. // If so, extract what we know from the trait and try to come up with a good answer.
let bounds = match *obligation.predicate.self_ty().kind() { let bounds = match *obligation.predicate.self_ty().kind() {
ty::Alias(_, ref data) => tcx.item_bounds(data.def_id).subst(tcx, data.substs), // Excluding IATs here as they don't have meaningful item bounds.
ty::Alias(ty::Projection | ty::Opaque, ref data) => {
tcx.item_bounds(data.def_id).subst(tcx, data.substs)
}
ty::Infer(ty::TyVar(_)) => { ty::Infer(ty::TyVar(_)) => {
// If the self-type is an inference variable, then it MAY wind up // If the self-type is an inference variable, then it MAY wind up
// being a projected type, so induce an ambiguity. // being a projected type, so induce an ambiguity.

View File

@ -143,7 +143,8 @@ fn assemble_candidates_from_projected_tys(
// Before we go into the whole placeholder thing, just // Before we go into the whole placeholder thing, just
// quickly check if the self-type is a projection at all. // quickly check if the self-type is a projection at all.
match obligation.predicate.skip_binder().trait_ref.self_ty().kind() { match obligation.predicate.skip_binder().trait_ref.self_ty().kind() {
ty::Alias(..) => {} // Excluding IATs here as they don't have meaningful item bounds.
ty::Alias(ty::Projection | ty::Opaque, _) => {}
ty::Infer(ty::TyVar(_)) => { ty::Infer(ty::TyVar(_)) => {
span_bug!( span_bug!(
obligation.cause.span, obligation.cause.span,

View File

@ -156,7 +156,10 @@ fn confirm_projection_candidate(
let placeholder_self_ty = placeholder_trait_predicate.self_ty(); let placeholder_self_ty = placeholder_trait_predicate.self_ty();
let placeholder_trait_predicate = ty::Binder::dummy(placeholder_trait_predicate); let placeholder_trait_predicate = ty::Binder::dummy(placeholder_trait_predicate);
let (def_id, substs) = match *placeholder_self_ty.kind() { let (def_id, substs) = match *placeholder_self_ty.kind() {
ty::Alias(_, ty::AliasTy { def_id, substs, .. }) => (def_id, substs), // Excluding IATs here as they don't have meaningful item bounds.
ty::Alias(ty::Projection | ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
(def_id, substs)
}
_ => bug!("projection candidate for unexpected type: {:?}", placeholder_self_ty), _ => bug!("projection candidate for unexpected type: {:?}", placeholder_self_ty),
}; };

View File

@ -1645,7 +1645,9 @@ fn match_projection_obligation_against_definition_bounds(
let tcx = self.infcx.tcx; let tcx = self.infcx.tcx;
let (def_id, substs) = match *placeholder_trait_predicate.trait_ref.self_ty().kind() { let (def_id, substs) = match *placeholder_trait_predicate.trait_ref.self_ty().kind() {
ty::Alias(_, ty::AliasTy { def_id, substs, .. }) => (def_id, substs), ty::Alias(ty::Projection | ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
(def_id, substs)
}
_ => { _ => {
span_bug!( span_bug!(
obligation.cause.span, obligation.cause.span,

View File

@ -0,0 +1,13 @@
#![feature(inherent_associated_types)]
#![allow(incomplete_features)]
// Check that rustc doesn't crash on the trait bound `Self::Ty: std::marker::Freeze`.
pub struct Struct;
impl Struct {
pub type Ty = usize;
pub const CT: Self::Ty = 42;
}
fn main() {}