Skip to content

Commit

Permalink
Track WellFormed obligations with an appropriate cause, instead of …
Browse files Browse the repository at this point in the history
…`MiscObligation`
  • Loading branch information
estebank committed Jul 7, 2022
1 parent af10a45 commit 385c793
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions compiler/rustc_trait_selection/src/traits/wf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
}

fn normalize(mut self) -> Vec<traits::PredicateObligation<'tcx>> {
let cause = self.cause(traits::MiscObligation);
let cause = self.cause(traits::WellFormed(None));
let infcx = &mut self.infcx;
let param_env = self.param_env;
let mut obligations = Vec::with_capacity(self.out.len());
Expand Down Expand Up @@ -385,7 +385,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
self.out.extend(obligations);

let tcx = self.tcx();
let cause = self.cause(traits::MiscObligation);
let cause = self.cause(traits::WellFormed(None));
let param_env = self.param_env;
let depth = self.recursion_depth;

Expand Down Expand Up @@ -445,7 +445,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
let predicate =
ty::Binder::dummy(ty::PredicateKind::ConstEvaluatable(uv.shrink()))
.to_predicate(self.tcx());
let cause = self.cause(traits::MiscObligation);
let cause = self.cause(traits::WellFormed(None));
self.out.push(traits::Obligation::with_depth(
cause,
self.recursion_depth,
Expand All @@ -457,7 +457,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
let resolved = self.infcx.shallow_resolve(infer);
// the `InferConst` changed, meaning that we made progress.
if resolved != infer {
let cause = self.cause(traits::MiscObligation);
let cause = self.cause(traits::WellFormed(None));

let resolved_constant = self.infcx.tcx.mk_const(ty::ConstS {
kind: ty::ConstKind::Infer(resolved),
Expand Down Expand Up @@ -648,7 +648,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
let defer_to_coercion = self.tcx().features().object_safe_for_dispatch;

if !defer_to_coercion {
let cause = self.cause(traits::MiscObligation);
let cause = self.cause(traits::WellFormed(None));
let component_traits = data.auto_traits().chain(data.principal_def_id());
let tcx = self.tcx();
self.out.extend(component_traits.map(|did| {
Expand Down Expand Up @@ -679,7 +679,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
let ty = self.infcx.shallow_resolve(ty);
if let ty::Infer(ty::TyVar(_)) = ty.kind() {
// Not yet resolved, but we've made progress.
let cause = self.cause(traits::MiscObligation);
let cause = self.cause(traits::WellFormed(None));
self.out.push(traits::Obligation::with_depth(
cause,
self.recursion_depth,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};

// we must check that return type of called functions is WF:
self.register_wf_obligation(output.into(), call_expr.span, traits::MiscObligation);
self.register_wf_obligation(output.into(), call_expr.span, traits::WellFormed(None));

output
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

pub fn to_ty(&self, ast_t: &hir::Ty<'_>) -> Ty<'tcx> {
let t = <dyn AstConv<'_>>::ast_ty_to_ty(self, ast_t);
self.register_wf_obligation(t.into(), ast_t.span, traits::MiscObligation);
self.register_wf_obligation(t.into(), ast_t.span, traits::WellFormed(None));
t
}

Expand Down Expand Up @@ -526,7 +526,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.register_wf_obligation(
c.into(),
self.tcx.hir().span(ast_c.hir_id),
ObligationCauseCode::MiscObligation,
ObligationCauseCode::WellFormed(None),
);
c
}
Expand All @@ -544,7 +544,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.register_wf_obligation(
c.into(),
self.tcx.hir().span(ast_c.hir_id),
ObligationCauseCode::MiscObligation,
ObligationCauseCode::WellFormed(None),
);
c
}
Expand Down Expand Up @@ -607,7 +607,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
for arg in substs.iter().filter(|arg| {
matches!(arg.unpack(), GenericArgKind::Type(..) | GenericArgKind::Const(..))
}) {
self.register_wf_obligation(arg, expr.span, traits::MiscObligation);
self.register_wf_obligation(arg, expr.span, traits::WellFormed(None));
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
// the function type must also be well-formed (this is not
// implied by the substs being well-formed because of inherent
// impls and late-bound regions - see issue #28609).
self.register_wf_obligation(fty.into(), self.span, traits::MiscObligation);
self.register_wf_obligation(fty.into(), self.span, traits::WellFormed(None));
}

///////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ fn check_item_type(tcx: TyCtxt<'_>, item_id: LocalDefId, ty_span: Span, allow_fo
fcx.register_bound(
item_ty,
tcx.require_lang_item(LangItem::Sized, None),
traits::ObligationCause::new(ty_span, fcx.body_id, traits::MiscObligation),
traits::ObligationCause::new(ty_span, fcx.body_id, traits::WellFormed(None)),
);
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/hir_wf_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn diagnostic_hir_wf_check<'tcx>(
let cause = traits::ObligationCause::new(
ty.span,
self.hir_id,
traits::ObligationCauseCode::MiscObligation,
traits::ObligationCauseCode::WellFormed(None),
);
fulfill.register_predicate_obligation(
&infcx,
Expand Down

0 comments on commit 385c793

Please sign in to comment.