Skip to content

Commit 87f2f42

Browse files
committed
Make projection wf check the predicates for the projection
1 parent f958e6c commit 87f2f42

File tree

1 file changed

+25
-11
lines changed
  • compiler/rustc_trait_selection/src/traits

1 file changed

+25
-11
lines changed

compiler/rustc_trait_selection/src/traits/wf.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -327,17 +327,31 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
327327
/// Pushes the obligations required for `trait_ref::Item` to be WF
328328
/// into `self.out`.
329329
fn compute_projection(&mut self, data: ty::ProjectionTy<'tcx>) {
330-
// A projection is well-formed if (a) the trait ref itself is
331-
// WF and (b) the trait-ref holds. (It may also be
332-
// normalizable and be WF that way.)
333-
let trait_ref = data.trait_ref(self.infcx.tcx);
334-
self.compute_trait_ref(&trait_ref, Elaborate::None);
335-
336-
if !data.has_escaping_bound_vars() {
337-
let predicate = trait_ref.without_const().to_predicate(self.infcx.tcx);
338-
let cause = self.cause(traits::ProjectionWf(data));
339-
self.out.push(traits::Obligation::new(cause, self.param_env, predicate));
340-
}
330+
// A projection is well-formed if
331+
// (a) its predicates hold
332+
// (b) its substs are wf
333+
let obligations = self.nominal_obligations(data.item_def_id, data.substs);
334+
self.out.extend(obligations);
335+
336+
let tcx = self.tcx();
337+
let cause = self.cause(traits::MiscObligation);
338+
let param_env = self.param_env;
339+
340+
self.out.extend(
341+
data.substs
342+
.iter()
343+
.filter(|arg| {
344+
matches!(arg.unpack(), GenericArgKind::Type(..) | GenericArgKind::Const(..))
345+
})
346+
.filter(|arg| !arg.has_escaping_bound_vars())
347+
.map(|arg| {
348+
traits::Obligation::new(
349+
cause.clone(),
350+
param_env,
351+
ty::PredicateKind::WellFormed(arg).to_predicate(tcx),
352+
)
353+
}),
354+
);
341355
}
342356

343357
fn require_sized(&mut self, subty: Ty<'tcx>, cause: traits::ObligationCauseCode<'tcx>) {

0 commit comments

Comments
 (0)