Track WellFormed obligations with an appropriate cause, instead of MiscObligation

This commit is contained in:
Esteban Küber 2022-07-01 16:48:14 -07:00
parent af10a456c1
commit 385c79379c
6 changed files with 14 additions and 14 deletions

View file

@ -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());
@ -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;
@ -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,
@ -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),
@ -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| {
@ -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,

View file

@ -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
}

View file

@ -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
}
@ -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
}
@ -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
}
@ -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));
}
}

View file

@ -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));
}
///////////////////////////////////////////////////////////////////////////

View file

@ -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)),
);
}

View file

@ -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,