diff --git a/compiler/rustc_infer/src/traits/util.rs b/compiler/rustc_infer/src/traits/util.rs index 50190058a7688..9bdc7d23ba622 100644 --- a/compiler/rustc_infer/src/traits/util.rs +++ b/compiler/rustc_infer/src/traits/util.rs @@ -261,14 +261,9 @@ impl<'tcx, O: Elaboratable<'tcx>> Elaborator<'tcx, O> { fn elaborate(&mut self, elaboratable: &O) { let tcx = self.visited.tcx; - // We only elaborate clauses. - let Some(clause) = elaboratable.predicate().as_clause() else { - return; - }; - - let bound_clause = clause.kind(); - match bound_clause.skip_binder() { - ty::ClauseKind::Trait(data) => { + let bound_predicate = elaboratable.predicate().kind(); + match bound_predicate.skip_binder() { + ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => { // Negative trait bounds do not imply any supertrait bounds if data.polarity == ty::ImplPolarity::Negative { return; @@ -285,16 +280,49 @@ impl<'tcx, O: Elaboratable<'tcx>> Elaborator<'tcx, O> { let obligations = predicates.predicates.iter().enumerate().map(|(index, &(clause, span))| { elaboratable.child_with_derived_cause( - clause.subst_supertrait(tcx, &bound_clause.rebind(data.trait_ref)), + clause.subst_supertrait(tcx, &bound_predicate.rebind(data.trait_ref)), span, - bound_clause.rebind(data), + bound_predicate.rebind(data), index, ) }); debug!(?data, ?obligations, "super_predicates"); self.extend_deduped(obligations); } - ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(ty_max, r_min)) => { + ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(..)) => { + // Currently, we do not elaborate WF predicates, + // although we easily could. + } + ty::PredicateKind::ObjectSafe(..) => { + // Currently, we do not elaborate object-safe + // predicates. + } + ty::PredicateKind::Subtype(..) => { + // Currently, we do not "elaborate" predicates like `X <: Y`, + // though conceivably we might. + } + ty::PredicateKind::Coerce(..) => { + // Currently, we do not "elaborate" predicates like `X -> Y`, + // though conceivably we might. + } + ty::PredicateKind::Clause(ty::ClauseKind::Projection(..)) => { + // Nothing to elaborate in a projection predicate. + } + ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..)) => { + // Currently, we do not elaborate const-evaluatable + // predicates. + } + ty::PredicateKind::ConstEquate(..) => { + // Currently, we do not elaborate const-equate + // predicates. + } + ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(..)) => { + // Nothing to elaborate from `'a: 'b`. + } + ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate( + ty_max, + r_min, + ))) => { // We know that `T: 'a` for some type `T`. We can // often elaborate this. For example, if we know that // `[U]: 'a`, that implies that `U: 'a`. Similarly, if @@ -357,25 +385,15 @@ impl<'tcx, O: Elaboratable<'tcx>> Elaborator<'tcx, O> { } }) .map(|clause| { - elaboratable.child(bound_clause.rebind(clause).to_predicate(tcx)) + elaboratable.child(bound_predicate.rebind(clause).to_predicate(tcx)) }), ); } - ty::ClauseKind::RegionOutlives(..) => { - // Nothing to elaborate from `'a: 'b`. - } - ty::ClauseKind::WellFormed(..) => { - // Currently, we do not elaborate WF predicates, - // although we easily could. - } - ty::ClauseKind::Projection(..) => { - // Nothing to elaborate in a projection predicate. - } - ty::ClauseKind::ConstEvaluatable(..) => { - // Currently, we do not elaborate const-evaluatable - // predicates. + ty::PredicateKind::Ambiguous => {} + ty::PredicateKind::NormalizesTo(..) | ty::PredicateKind::AliasRelate(..) => { + // No } - ty::ClauseKind::ConstArgHasType(..) => { + ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(..)) => { // Nothing to elaborate } } diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index 9cbddd2bb2b8b..96b1c4c4a5fb7 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -360,11 +360,8 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { ProcessResult::Changed(mk_pending(vec![obligation.with(infcx.tcx, pred)])) } ty::PredicateKind::Ambiguous => ProcessResult::Unchanged, - ty::PredicateKind::NormalizesTo(..) => { - bug!("NormalizesTo is only used by the new solver") - } - ty::PredicateKind::AliasRelate(..) => { - bug!("AliasRelate is only used by the new solver") + ty::PredicateKind::NormalizesTo(..) | ty::PredicateKind::AliasRelate(..) => { + bug!("only used by the new solver") } }, Some(pred) => match pred { @@ -415,11 +412,8 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { } ty::PredicateKind::Ambiguous => ProcessResult::Unchanged, - ty::PredicateKind::NormalizesTo(..) => { - bug!("NormalizesTo is only used by the new solver") - } - ty::PredicateKind::AliasRelate(..) => { - bug!("AliasRelate is only used by the new solver") + ty::PredicateKind::NormalizesTo(..) | ty::PredicateKind::AliasRelate(..) => { + bug!("only used by the new solver") } // General case overflow check. Allow `process_trait_obligation` diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 6ba379467dac7..d36fab62faefd 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -990,11 +990,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } } - ty::PredicateKind::NormalizesTo(..) => { - bug!("NormalizesTo is only used by the new solver") - } - ty::PredicateKind::AliasRelate(..) => { - bug!("AliasRelate is only used by the new solver") + ty::PredicateKind::NormalizesTo(..) | ty::PredicateKind::AliasRelate(..) => { + bug!("only used by the new solver") } ty::PredicateKind::Ambiguous => Ok(EvaluatedToAmbig), ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => {