Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.type_matches_expected_vid(expected_vid, data.self_ty())
}
ty::PredicateKind::Clause(ty::ClauseKind::Projection(data)) => {
self.type_matches_expected_vid(expected_vid, data.projection_term.self_ty())
if data.projection_term.kind.is_trait_projection() {
self.type_matches_expected_vid(expected_vid, data.projection_term.self_ty())
} else {
false
}
}
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(..))
| ty::PredicateKind::Subtype(..)
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1816,6 +1816,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let pred = bound_predicate.rebind(pred);
// `<Foo as Iterator>::Item = String`.
let projection_term = pred.skip_binder().projection_term;
if !projection_term.kind.is_trait_projection() {
return None;
}

let quiet_projection_term = projection_term
.with_replaced_self_ty(tcx, Ty::new_var(tcx, ty::TyVid::ZERO));

Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_infer/src/infer/opaque_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,10 @@ impl<'tcx> InferCtxt<'tcx> {
goals.push(Goal::new(
self.tcx,
param_env,
ty::PredicateKind::Clause(ty::ClauseKind::Projection(
ty::ProjectionPredicate {
projection_term: projection_ty.into(),
term: ty_var.into(),
},
)),
ty::ProjectionPredicate {
projection_term: projection_ty.into(),
term: ty_var.into(),
},
));
ty_var
}
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_infer/src/infer/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ impl<'tcx> InferCtxt<'tcx> {
self.next_const_var(span).into()
};

let projection =
ty::PredicateKind::Clause(ty::ClauseKind::Projection(ty::ProjectionPredicate {
projection_term: alias_term,
term: infer_var,
}));
let projection = ty::ProjectionPredicate { projection_term: alias_term, term: infer_var };
let obligation =
Obligation::with_depth(self.tcx, cause, recursion_depth, param_env, projection);
obligations.push(obligation);
Expand Down
32 changes: 16 additions & 16 deletions compiler/rustc_next_trait_solver/src/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use rustc_type_ir::data_structures::ensure_sufficient_stack;
use rustc_type_ir::inherent::*;
use rustc_type_ir::solve::{Goal, NoSolution};
use rustc_type_ir::{
self as ty, Binder, FallibleTypeFolder, InferConst, InferCtxtLike, InferTy, Interner,
TypeFoldable, TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
self as ty, AliasTerm, Binder, FallibleTypeFolder, InferConst, InferCtxtLike, InferTy,
Interner, TypeFoldable, TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
TypeVisitor, UniverseIndex,
};
use tracing::instrument;
Expand Down Expand Up @@ -101,7 +101,7 @@ impl<'a, Infcx, I, F> NormalizationFolder<'a, Infcx, I, F>
where
Infcx: InferCtxtLike<Interner = I>,
I: Interner,
F: FnMut(I::Term) -> Result<(I::Term, Option<Goal<I, I::Predicate>>), NoSolution>,
F: FnMut(AliasTerm<I>) -> Result<(I::Term, Option<Goal<I, I::Predicate>>), NoSolution>,
{
pub fn new(
infcx: &'a Infcx,
Expand All @@ -118,7 +118,7 @@ where

fn normalize_alias_term(
&mut self,
alias_term: I::Term,
alias_term: AliasTerm<I>,
has_escaping: HasEscapingBoundVars,
) -> Result<I::Term, NoSolution> {
let current_universe = self.infcx.universe();
Expand All @@ -139,7 +139,7 @@ where
normalized.visit_with(&mut visitor);
let max_universe = visitor.max_universe();
if current_universe.cannot_name(max_universe) {
return Ok(alias_term);
return Ok(alias_term.to_term(self.cx()));
}
}

Expand All @@ -152,7 +152,7 @@ impl<'a, Infcx, I, F> FallibleTypeFolder<I> for NormalizationFolder<'a, Infcx, I
where
Infcx: InferCtxtLike<Interner = I>,
I: Interner,
F: FnMut(I::Term) -> Result<(I::Term, Option<Goal<I, I::Predicate>>), NoSolution>,
F: FnMut(AliasTerm<I>) -> Result<(I::Term, Option<Goal<I, I::Predicate>>), NoSolution>,
{
type Error = NoSolution;

Expand Down Expand Up @@ -180,13 +180,13 @@ where
// With eager normalization, we should normalize the args of alias before
// normalizing the alias itself.
let ty = ty.try_super_fold_with(self)?;
let ty::Alias(..) = ty.kind() else { return Ok(ty) };
let ty::Alias(alias_ty) = ty.kind() else { return Ok(ty) };

if ty.has_escaping_bound_vars() {
let (ty, mapped_regions, mapped_types, mapped_consts) =
BoundVarReplacer::replace_bound_vars(infcx, &mut self.universes, ty);
let (alias_ty, mapped_regions, mapped_types, mapped_consts) =
BoundVarReplacer::replace_bound_vars(infcx, &mut self.universes, alias_ty);
let result = ensure_sufficient_stack(|| {
self.normalize_alias_term(ty.into(), HasEscapingBoundVars::Yes)
self.normalize_alias_term(alias_ty.into(), HasEscapingBoundVars::Yes)
})?
.expect_ty();
Ok(PlaceholderReplacer::replace_placeholders(
Expand All @@ -199,7 +199,7 @@ where
))
} else {
Ok(ensure_sufficient_stack(|| {
self.normalize_alias_term(ty.into(), HasEscapingBoundVars::No)
self.normalize_alias_term(alias_ty.into(), HasEscapingBoundVars::No)
})?
.expect_ty())
}
Expand All @@ -215,13 +215,13 @@ where
// With eager normalization, we should normalize the args of alias before
// normalizing the alias itself.
let ct = ct.try_super_fold_with(self)?;
let ty::ConstKind::Unevaluated(..) = ct.kind() else { return Ok(ct) };
let ty::ConstKind::Unevaluated(uc) = ct.kind() else { return Ok(ct) };

if ct.has_escaping_bound_vars() {
let (ct, mapped_regions, mapped_types, mapped_consts) =
BoundVarReplacer::replace_bound_vars(infcx, &mut self.universes, ct);
let (uc, mapped_regions, mapped_types, mapped_consts) =
BoundVarReplacer::replace_bound_vars(infcx, &mut self.universes, uc);
let result = ensure_sufficient_stack(|| {
self.normalize_alias_term(ct.into(), HasEscapingBoundVars::Yes)
self.normalize_alias_term(uc.into(), HasEscapingBoundVars::Yes)
})?
.expect_const();
Ok(PlaceholderReplacer::replace_placeholders(
Expand All @@ -234,7 +234,7 @@ where
))
} else {
Ok(ensure_sufficient_stack(|| {
self.normalize_alias_term(ct.into(), HasEscapingBoundVars::No)
self.normalize_alias_term(uc.into(), HasEscapingBoundVars::No)
})?
.expect_const())
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_next_trait_solver/src/solve/alias_relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ where
let term = self.next_term_infer_of_kind(lhs);
self.add_goal(
GoalSource::TypeRelating,
goal.with(cx, ty::NormalizesTo { alias, term }),
goal.with(cx, ty::ProjectionPredicate { projection_term: alias, term }),
);
term
} else {
Expand All @@ -64,7 +64,7 @@ where
let term = self.next_term_infer_of_kind(rhs);
self.add_goal(
GoalSource::TypeRelating,
goal.with(cx, ty::NormalizesTo { alias, term }),
goal.with(cx, ty::ProjectionPredicate { projection_term: alias, term }),
);
term
} else {
Expand Down
Loading
Loading