1
Fork 0

Rename some ObligationCauseCode variants

This commit is contained in:
Michael Goulet 2024-05-09 20:12:47 -04:00
parent 4bde8a8f4b
commit 534e267d48
33 changed files with 186 additions and 246 deletions

View file

@ -2059,15 +2059,12 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// We currently do not store the `DefId` in the `ConstraintCategory` // We currently do not store the `DefId` in the `ConstraintCategory`
// for performances reasons. The error reporting code used by NLL only // for performances reasons. The error reporting code used by NLL only
// uses the span, so this doesn't cause any problems at the moment. // uses the span, so this doesn't cause any problems at the moment.
Some(ObligationCauseCode::BindingObligation( Some(ObligationCauseCode::Where(CRATE_DEF_ID.to_def_id(), predicate_span))
CRATE_DEF_ID.to_def_id(),
predicate_span,
))
} else { } else {
None None
} }
}) })
.unwrap_or_else(|| ObligationCauseCode::MiscObligation); .unwrap_or_else(|| ObligationCauseCode::Misc);
// Classify each of the constraints along the path. // Classify each of the constraints along the path.
let mut categorized_path: Vec<BlameConstraint<'tcx>> = path let mut categorized_path: Vec<BlameConstraint<'tcx>> = path

View file

@ -738,7 +738,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
let cause = ObligationCause::new( let cause = ObligationCause::new(
terminator.source_info.span, terminator.source_info.span,
self.body.source.def_id().expect_local(), self.body.source.def_id().expect_local(),
ObligationCauseCode::ItemObligation(callee), ObligationCauseCode::MiscItem(callee),
); );
let normalized_predicates = ocx.normalize(&cause, param_env, predicates); let normalized_predicates = ocx.normalize(&cause, param_env, predicates);
ocx.register_obligations(traits::predicates_for_generics( ocx.register_obligations(traits::predicates_for_generics(

View file

@ -175,7 +175,7 @@ fn compare_method_predicate_entailment<'tcx>(
let cause = ObligationCause::new( let cause = ObligationCause::new(
impl_m_span, impl_m_span,
impl_m_def_id, impl_m_def_id,
ObligationCauseCode::CompareImplItemObligation { ObligationCauseCode::CompareImplItem {
impl_item_def_id: impl_m_def_id, impl_item_def_id: impl_m_def_id,
trait_item_def_id: trait_m.def_id, trait_item_def_id: trait_m.def_id,
kind: impl_m.kind, kind: impl_m.kind,
@ -236,7 +236,7 @@ fn compare_method_predicate_entailment<'tcx>(
let cause = ObligationCause::new( let cause = ObligationCause::new(
span, span,
impl_m_def_id, impl_m_def_id,
ObligationCauseCode::CompareImplItemObligation { ObligationCauseCode::CompareImplItem {
impl_item_def_id: impl_m_def_id, impl_item_def_id: impl_m_def_id,
trait_item_def_id: trait_m.def_id, trait_item_def_id: trait_m.def_id,
kind: impl_m.kind, kind: impl_m.kind,
@ -464,7 +464,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
let cause = ObligationCause::new( let cause = ObligationCause::new(
return_span, return_span,
impl_m_def_id, impl_m_def_id,
ObligationCauseCode::CompareImplItemObligation { ObligationCauseCode::CompareImplItem {
impl_item_def_id: impl_m_def_id, impl_item_def_id: impl_m_def_id,
trait_item_def_id: trait_m.def_id, trait_item_def_id: trait_m.def_id,
kind: impl_m.kind, kind: impl_m.kind,
@ -819,7 +819,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'_, 'tcx> {
ObligationCause::new( ObligationCause::new(
self.span, self.span,
self.body_id, self.body_id,
ObligationCauseCode::BindingObligation(proj.def_id, pred_span), ObligationCauseCode::Where(proj.def_id, pred_span),
), ),
self.param_env, self.param_env,
pred, pred,
@ -1752,7 +1752,7 @@ fn compare_const_predicate_entailment<'tcx>(
let impl_ty = tcx.type_of(impl_ct_def_id).instantiate_identity(); let impl_ty = tcx.type_of(impl_ct_def_id).instantiate_identity();
let trait_ty = tcx.type_of(trait_ct.def_id).instantiate(tcx, trait_to_impl_args); let trait_ty = tcx.type_of(trait_ct.def_id).instantiate(tcx, trait_to_impl_args);
let code = ObligationCauseCode::CompareImplItemObligation { let code = ObligationCauseCode::CompareImplItem {
impl_item_def_id: impl_ct_def_id, impl_item_def_id: impl_ct_def_id,
trait_item_def_id: trait_ct.def_id, trait_item_def_id: trait_ct.def_id,
kind: impl_ct.kind, kind: impl_ct.kind,
@ -1924,7 +1924,7 @@ fn compare_type_predicate_entailment<'tcx>(
let cause = ObligationCause::new( let cause = ObligationCause::new(
span, span,
impl_ty_def_id, impl_ty_def_id,
ObligationCauseCode::CompareImplItemObligation { ObligationCauseCode::CompareImplItem {
impl_item_def_id: impl_ty.def_id.expect_local(), impl_item_def_id: impl_ty.def_id.expect_local(),
trait_item_def_id: trait_ty.def_id, trait_item_def_id: trait_ty.def_id,
kind: impl_ty.kind, kind: impl_ty.kind,
@ -2012,9 +2012,9 @@ pub(super) fn check_type_bounds<'tcx>(
); );
let mk_cause = |span: Span| { let mk_cause = |span: Span| {
let code = if span.is_dummy() { let code = if span.is_dummy() {
ObligationCauseCode::ItemObligation(trait_ty.def_id) ObligationCauseCode::MiscItem(trait_ty.def_id)
} else { } else {
ObligationCauseCode::BindingObligation(trait_ty.def_id, span) ObligationCauseCode::Where(trait_ty.def_id, span)
}; };
ObligationCause::new(impl_ty_span, impl_ty_def_id, code) ObligationCause::new(impl_ty_span, impl_ty_def_id, code)
}; };
@ -2251,8 +2251,7 @@ fn try_report_async_mismatch<'tcx>(
}; };
for error in errors { for error in errors {
if let ObligationCauseCode::BindingObligation(def_id, _) = if let ObligationCauseCode::Where(def_id, _) = *error.root_obligation.cause.code()
*error.root_obligation.cause.code()
&& def_id == async_future_def_id && def_id == async_future_def_id
&& let Some(proj) = error.root_obligation.predicate.to_opt_poly_projection_pred() && let Some(proj) = error.root_obligation.predicate.to_opt_poly_projection_pred()
&& let Some(proj) = proj.no_bound_vars() && let Some(proj) = proj.no_bound_vars()

View file

@ -1161,7 +1161,7 @@ fn check_type_defn<'tcx>(
let cause = traits::ObligationCause::new( let cause = traits::ObligationCause::new(
tcx.def_span(discr_def_id), tcx.def_span(discr_def_id),
wfcx.body_def_id, wfcx.body_def_id,
ObligationCauseCode::MiscObligation, ObligationCauseCode::Misc,
); );
wfcx.register_obligation(traits::Obligation::new( wfcx.register_obligation(traits::Obligation::new(
tcx, tcx,
@ -1550,7 +1550,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
let cause = traits::ObligationCause::new( let cause = traits::ObligationCause::new(
sp, sp,
wfcx.body_def_id, wfcx.body_def_id,
ObligationCauseCode::ItemObligation(def_id.to_def_id()), ObligationCauseCode::MiscItem(def_id.to_def_id()),
); );
traits::Obligation::new(tcx, cause, wfcx.param_env, pred) traits::Obligation::new(tcx, cause, wfcx.param_env, pred)
}); });

View file

@ -212,7 +212,7 @@ fn get_impl_args(
traits::ObligationCause::new( traits::ObligationCause::new(
impl1_span, impl1_span,
impl1_def_id, impl1_def_id,
traits::ObligationCauseCode::BindingObligation(impl2_node.def_id(), span), traits::ObligationCauseCode::Where(impl2_node.def_id(), span),
) )
}, },
); );

View file

@ -3083,7 +3083,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
polarity: ty::PredicatePolarity::Positive, polarity: ty::PredicatePolarity::Positive,
}), }),
|derived| { |derived| {
ObligationCauseCode::ImplDerivedObligation(Box::new( ObligationCauseCode::ImplDerived(Box::new(
traits::ImplDerivedObligationCause { traits::ImplDerivedObligationCause {
derived, derived,
impl_or_alias_def_id: impl_def_id, impl_or_alias_def_id: impl_def_id,
@ -3352,11 +3352,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let field_ty = self.field_ty(expr.span, field, args); let field_ty = self.field_ty(expr.span, field, args);
// FIXME: DSTs with static alignment should be allowed // FIXME: DSTs with static alignment should be allowed
self.require_type_is_sized( self.require_type_is_sized(field_ty, expr.span, ObligationCauseCode::Misc);
field_ty,
expr.span,
ObligationCauseCode::MiscObligation,
);
if field.vis.is_accessible_from(sub_def_scope, self.tcx) { if field.vis.is_accessible_from(sub_def_scope, self.tcx) {
self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span, None); self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span, None);
@ -3384,11 +3380,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let field_ty = self.field_ty(expr.span, field, args); let field_ty = self.field_ty(expr.span, field, args);
// FIXME: DSTs with static alignment should be allowed // FIXME: DSTs with static alignment should be allowed
self.require_type_is_sized( self.require_type_is_sized(field_ty, expr.span, ObligationCauseCode::Misc);
field_ty,
expr.span,
ObligationCauseCode::MiscObligation,
);
if field.vis.is_accessible_from(def_scope, self.tcx) { if field.vis.is_accessible_from(def_scope, self.tcx) {
self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span, None); self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span, None);
@ -3409,11 +3401,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&& field.name == sym::integer(index) && field.name == sym::integer(index)
{ {
for ty in tys.iter().take(index + 1) { for ty in tys.iter().take(index + 1) {
self.require_type_is_sized( self.require_type_is_sized(ty, expr.span, ObligationCauseCode::Misc);
ty,
expr.span,
ObligationCauseCode::MiscObligation,
);
} }
if let Some(&field_ty) = tys.get(index) { if let Some(&field_ty) = tys.get(index) {
field_indices.push((FIRST_VARIANT, index.into())); field_indices.push((FIRST_VARIANT, index.into()));

View file

@ -1413,9 +1413,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) { ) {
self.add_required_obligations_with_code(span, def_id, args, |idx, span| { self.add_required_obligations_with_code(span, def_id, args, |idx, span| {
if span.is_dummy() { if span.is_dummy() {
ObligationCauseCode::ExprItemObligation(def_id, hir_id, idx) ObligationCauseCode::MiscItemInExpr(def_id, hir_id, idx)
} else { } else {
ObligationCauseCode::ExprBindingObligation(def_id, span, hir_id, idx) ObligationCauseCode::WhereInExpr(def_id, span, hir_id, idx)
} }
}) })
} }

View file

@ -14,8 +14,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self, &self,
error: &mut traits::FulfillmentError<'tcx>, error: &mut traits::FulfillmentError<'tcx>,
) -> bool { ) -> bool {
let (ObligationCauseCode::ExprItemObligation(def_id, hir_id, idx) let (ObligationCauseCode::MiscItemInExpr(def_id, hir_id, idx)
| ObligationCauseCode::ExprBindingObligation(def_id, _, hir_id, idx)) = | ObligationCauseCode::WhereInExpr(def_id, _, hir_id, idx)) =
*error.obligation.cause.code().peel_derives() *error.obligation.cause.code().peel_derives()
else { else {
return false; return false;
@ -167,7 +167,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// the method's turbofish segments but still use `FunctionArgumentObligation` // the method's turbofish segments but still use `FunctionArgumentObligation`
// elsewhere. Hopefully this doesn't break something. // elsewhere. Hopefully this doesn't break something.
error.obligation.cause.map_code(|parent_code| { error.obligation.cause.map_code(|parent_code| {
ObligationCauseCode::FunctionArgumentObligation { ObligationCauseCode::FunctionArg {
arg_hir_id: receiver.hir_id, arg_hir_id: receiver.hir_id,
call_hir_id: hir_id, call_hir_id: hir_id,
parent_code, parent_code,
@ -456,12 +456,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.blame_specific_expr_if_possible(error, arg_expr) self.blame_specific_expr_if_possible(error, arg_expr)
} }
error.obligation.cause.map_code(|parent_code| { error.obligation.cause.map_code(|parent_code| ObligationCauseCode::FunctionArg {
ObligationCauseCode::FunctionArgumentObligation { arg_hir_id: arg.hir_id,
arg_hir_id: arg.hir_id, call_hir_id,
call_hir_id, parent_code,
parent_code,
}
}); });
return true; return true;
} else if args_referencing_param.len() > 0 { } else if args_referencing_param.len() > 0 {
@ -514,12 +512,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expr: &'tcx hir::Expr<'tcx>, expr: &'tcx hir::Expr<'tcx>,
) -> Result<&'tcx hir::Expr<'tcx>, &'tcx hir::Expr<'tcx>> { ) -> Result<&'tcx hir::Expr<'tcx>, &'tcx hir::Expr<'tcx>> {
match obligation_cause_code { match obligation_cause_code {
traits::ObligationCauseCode::ExprBindingObligation(_, _, _, _) => { traits::ObligationCauseCode::WhereInExpr(_, _, _, _) => {
// This is the "root"; we assume that the `expr` is already pointing here. // This is the "root"; we assume that the `expr` is already pointing here.
// Therefore, we return `Ok` so that this `expr` can be refined further. // Therefore, we return `Ok` so that this `expr` can be refined further.
Ok(expr) Ok(expr)
} }
traits::ObligationCauseCode::ImplDerivedObligation(impl_derived) => self traits::ObligationCauseCode::ImplDerived(impl_derived) => self
.blame_specific_expr_if_possible_for_derived_predicate_obligation( .blame_specific_expr_if_possible_for_derived_predicate_obligation(
impl_derived, impl_derived,
expr, expr,

View file

@ -206,7 +206,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.register_wf_obligation( self.register_wf_obligation(
fn_input_ty.into(), fn_input_ty.into(),
arg_expr.span, arg_expr.span,
ObligationCauseCode::MiscObligation, ObligationCauseCode::Misc,
); );
} }

View file

@ -154,7 +154,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
pub fn misc(&self, span: Span) -> ObligationCause<'tcx> { pub fn misc(&self, span: Span) -> ObligationCause<'tcx> {
self.cause(span, ObligationCauseCode::MiscObligation) self.cause(span, ObligationCauseCode::Misc)
} }
pub fn sess(&self) -> &Session { pub fn sess(&self) -> &Session {

View file

@ -565,14 +565,9 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
for obligation in traits::predicates_for_generics( for obligation in traits::predicates_for_generics(
|idx, span| { |idx, span| {
let code = if span.is_dummy() { let code = if span.is_dummy() {
ObligationCauseCode::ExprItemObligation(def_id, self.call_expr.hir_id, idx) ObligationCauseCode::MiscItemInExpr(def_id, self.call_expr.hir_id, idx)
} else { } else {
ObligationCauseCode::ExprBindingObligation( ObligationCauseCode::WhereInExpr(def_id, span, self.call_expr.hir_id, idx)
def_id,
span,
self.call_expr.hir_id,
idx,
)
}; };
traits::ObligationCause::new(self.span, self.body_id, code) traits::ObligationCause::new(self.span, self.body_id, code)
}, },

View file

@ -1402,13 +1402,13 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
ocx.register_obligations(traits::predicates_for_generics( ocx.register_obligations(traits::predicates_for_generics(
|idx, span| { |idx, span| {
let code = if span.is_dummy() { let code = if span.is_dummy() {
ObligationCauseCode::ExprItemObligation( ObligationCauseCode::MiscItemInExpr(
impl_def_id, impl_def_id,
self.scope_expr_id, self.scope_expr_id,
idx, idx,
) )
} else { } else {
ObligationCauseCode::ExprBindingObligation( ObligationCauseCode::WhereInExpr(
impl_def_id, impl_def_id,
span, span,
self.scope_expr_id, self.scope_expr_id,

View file

@ -146,7 +146,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return false; return false;
}; };
let trait_ref = ty::TraitRef::new(self.tcx, into_iterator_trait, [ty]); let trait_ref = ty::TraitRef::new(self.tcx, into_iterator_trait, [ty]);
let cause = ObligationCause::new(span, self.body_id, ObligationCauseCode::MiscObligation); let cause = ObligationCause::new(span, self.body_id, ObligationCauseCode::Misc);
let obligation = Obligation::new(self.tcx, cause, self.param_env, trait_ref); let obligation = Obligation::new(self.tcx, cause, self.param_env, trait_ref);
if !self.predicate_must_hold_modulo_regions(&obligation) { if !self.predicate_must_hold_modulo_regions(&obligation) {
return false; return false;
@ -826,12 +826,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Extract the predicate span and parent def id of the cause, // Extract the predicate span and parent def id of the cause,
// if we have one. // if we have one.
let (item_def_id, cause_span) = match cause.as_ref().map(|cause| cause.code()) { let (item_def_id, cause_span) = match cause.as_ref().map(|cause| cause.code()) {
Some(ObligationCauseCode::ImplDerivedObligation(data)) => { Some(ObligationCauseCode::ImplDerived(data)) => {
(data.impl_or_alias_def_id, data.span) (data.impl_or_alias_def_id, data.span)
} }
Some( Some(
ObligationCauseCode::ExprBindingObligation(def_id, span, _, _) ObligationCauseCode::WhereInExpr(def_id, span, _, _)
| ObligationCauseCode::BindingObligation(def_id, span), | ObligationCauseCode::Where(def_id, span),
) => (*def_id, *span), ) => (*def_id, *span),
_ => continue, _ => continue,
}; };

View file

@ -883,9 +883,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
err.help("...or use `match` instead of `let...else`"); err.help("...or use `match` instead of `let...else`");
} }
_ => { _ => {
if let ObligationCauseCode::BindingObligation(_, span) if let ObligationCauseCode::Where(_, span)
| ObligationCauseCode::ExprBindingObligation(_, span, ..) = | ObligationCauseCode::WhereInExpr(_, span, ..) = cause.code().peel_derives()
cause.code().peel_derives()
&& let TypeError::RegionsPlaceholderMismatch = terr && let TypeError::RegionsPlaceholderMismatch = terr
{ {
err.span_note(*span, "the lifetime requirement is introduced here"); err.span_note(*span, "the lifetime requirement is introduced here");
@ -2776,7 +2775,7 @@ impl<'tcx> ObligationCause<'tcx> {
match self.code() { match self.code() {
ObligationCauseCode::IfExpressionWithNoElse => FailureCode::Error0317, ObligationCauseCode::IfExpressionWithNoElse => FailureCode::Error0317,
ObligationCauseCode::MainFunctionType => FailureCode::Error0580, ObligationCauseCode::MainFunctionType => FailureCode::Error0580,
ObligationCauseCode::CompareImplItemObligation { .. } ObligationCauseCode::CompareImplItem { .. }
| ObligationCauseCode::MatchExpressionArm(_) | ObligationCauseCode::MatchExpressionArm(_)
| ObligationCauseCode::IfExpression { .. } | ObligationCauseCode::IfExpression { .. }
| ObligationCauseCode::LetElse | ObligationCauseCode::LetElse
@ -2806,15 +2805,15 @@ impl<'tcx> ObligationCause<'tcx> {
subdiags: Vec<TypeErrorAdditionalDiags>, subdiags: Vec<TypeErrorAdditionalDiags>,
) -> ObligationCauseFailureCode { ) -> ObligationCauseFailureCode {
match self.code() { match self.code() {
ObligationCauseCode::CompareImplItemObligation { kind: ty::AssocKind::Fn, .. } => { ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Fn, .. } => {
ObligationCauseFailureCode::MethodCompat { span, subdiags } ObligationCauseFailureCode::MethodCompat { span, subdiags }
} }
ObligationCauseCode::CompareImplItemObligation { ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Type, .. } => {
kind: ty::AssocKind::Type, .. ObligationCauseFailureCode::TypeCompat { span, subdiags }
} => ObligationCauseFailureCode::TypeCompat { span, subdiags }, }
ObligationCauseCode::CompareImplItemObligation { ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Const, .. } => {
kind: ty::AssocKind::Const, .. ObligationCauseFailureCode::ConstCompat { span, subdiags }
} => ObligationCauseFailureCode::ConstCompat { span, subdiags }, }
ObligationCauseCode::BlockTailExpression(.., hir::MatchSource::TryDesugar(_)) => { ObligationCauseCode::BlockTailExpression(.., hir::MatchSource::TryDesugar(_)) => {
ObligationCauseFailureCode::TryCompat { span, subdiags } ObligationCauseFailureCode::TryCompat { span, subdiags }
} }
@ -2870,15 +2869,15 @@ impl<'tcx> ObligationCause<'tcx> {
fn as_requirement_str(&self) -> &'static str { fn as_requirement_str(&self) -> &'static str {
match self.code() { match self.code() {
ObligationCauseCode::CompareImplItemObligation { kind: ty::AssocKind::Fn, .. } => { ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Fn, .. } => {
"method type is compatible with trait" "method type is compatible with trait"
} }
ObligationCauseCode::CompareImplItemObligation { ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Type, .. } => {
kind: ty::AssocKind::Type, .. "associated type is compatible with trait"
} => "associated type is compatible with trait", }
ObligationCauseCode::CompareImplItemObligation { ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Const, .. } => {
kind: ty::AssocKind::Const, .. "const is compatible with trait"
} => "const is compatible with trait", }
ObligationCauseCode::MainFunctionType => "`main` function has the correct type", ObligationCauseCode::MainFunctionType => "`main` function has the correct type",
ObligationCauseCode::StartFunctionType => "`#[start]` function has the correct type", ObligationCauseCode::StartFunctionType => "`#[start]` function has the correct type",
ObligationCauseCode::LangFunctionType(_) => "lang item function has the correct type", ObligationCauseCode::LangFunctionType(_) => "lang item function has the correct type",
@ -2895,15 +2894,11 @@ pub struct ObligationCauseAsDiagArg<'tcx>(pub ObligationCause<'tcx>);
impl IntoDiagArg for ObligationCauseAsDiagArg<'_> { impl IntoDiagArg for ObligationCauseAsDiagArg<'_> {
fn into_diag_arg(self) -> rustc_errors::DiagArgValue { fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
let kind = match self.0.code() { let kind = match self.0.code() {
ObligationCauseCode::CompareImplItemObligation { kind: ty::AssocKind::Fn, .. } => { ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Fn, .. } => "method_compat",
"method_compat" ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Type, .. } => "type_compat",
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Const, .. } => {
"const_compat"
} }
ObligationCauseCode::CompareImplItemObligation {
kind: ty::AssocKind::Type, ..
} => "type_compat",
ObligationCauseCode::CompareImplItemObligation {
kind: ty::AssocKind::Const, ..
} => "const_compat",
ObligationCauseCode::MainFunctionType => "fn_main_correct_type", ObligationCauseCode::MainFunctionType => "fn_main_correct_type",
ObligationCauseCode::StartFunctionType => "fn_start_correct_type", ObligationCauseCode::StartFunctionType => "fn_start_correct_type",
ObligationCauseCode::LangFunctionType(_) => "fn_lang_correct_type", ObligationCauseCode::LangFunctionType(_) => "fn_lang_correct_type",

View file

@ -32,14 +32,14 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
// If we added a "points at argument expression" obligation, we remove it here, we care // If we added a "points at argument expression" obligation, we remove it here, we care
// about the original obligation only. // about the original obligation only.
let code = match cause.code() { let code = match cause.code() {
ObligationCauseCode::FunctionArgumentObligation { parent_code, .. } => &*parent_code, ObligationCauseCode::FunctionArg { parent_code, .. } => &*parent_code,
code => code, code => code,
}; };
let ObligationCauseCode::MatchImpl(parent, impl_def_id) = code else { let ObligationCauseCode::MatchImpl(parent, impl_def_id) = code else {
return None; return None;
}; };
let (ObligationCauseCode::BindingObligation(_, binding_span) let (ObligationCauseCode::Where(_, binding_span)
| ObligationCauseCode::ExprBindingObligation(_, binding_span, ..)) = *parent.code() | ObligationCauseCode::WhereInExpr(_, binding_span, ..)) = *parent.code()
else { else {
return None; return None;
}; };

View file

@ -240,8 +240,8 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
let span = cause.span(); let span = cause.span();
let (leading_ellipsis, satisfy_span, where_span, dup_span, def_id) = let (leading_ellipsis, satisfy_span, where_span, dup_span, def_id) =
if let ObligationCauseCode::ItemObligation(def_id) if let ObligationCauseCode::MiscItem(def_id)
| ObligationCauseCode::ExprItemObligation(def_id, ..) = *cause.code() | ObligationCauseCode::MiscItemInExpr(def_id, ..) = *cause.code()
{ {
( (
true, true,

View file

@ -214,8 +214,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
_ => cause.code(), _ => cause.code(),
} }
&& let ( && let (
&ObligationCauseCode::ItemObligation(item_def_id) &ObligationCauseCode::MiscItem(item_def_id)
| &ObligationCauseCode::ExprItemObligation(item_def_id, ..), | &ObligationCauseCode::MiscItemInExpr(item_def_id, ..),
None, None,
) = (code, override_error_code) ) = (code, override_error_code)
{ {

View file

@ -357,13 +357,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
infer::Subtype(box ref trace) infer::Subtype(box ref trace)
if matches!( if matches!(
&trace.cause.code().peel_derives(), &trace.cause.code().peel_derives(),
ObligationCauseCode::BindingObligation(..) ObligationCauseCode::Where(..) | ObligationCauseCode::WhereInExpr(..)
| ObligationCauseCode::ExprBindingObligation(..)
) => ) =>
{ {
// Hack to get around the borrow checker because trace.cause has an `Rc`. // Hack to get around the borrow checker because trace.cause has an `Rc`.
if let ObligationCauseCode::BindingObligation(_, span) if let ObligationCauseCode::Where(_, span)
| ObligationCauseCode::ExprBindingObligation(_, span, ..) = | ObligationCauseCode::WhereInExpr(_, span, ..) =
&trace.cause.code().peel_derives() &trace.cause.code().peel_derives()
{ {
let span = *span; let span = *span;

View file

@ -629,8 +629,7 @@ impl<T> Trait<T> for X {
| hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }), | hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }),
) )
); );
let impl_comparison = let impl_comparison = matches!(cause_code, ObligationCauseCode::CompareImplItem { .. });
matches!(cause_code, ObligationCauseCode::CompareImplItemObligation { .. });
let assoc = tcx.associated_item(proj_ty.def_id); let assoc = tcx.associated_item(proj_ty.def_id);
if impl_comparison { if impl_comparison {
// We do not want to suggest calling functions when the reason of the // We do not want to suggest calling functions when the reason of the

View file

@ -167,7 +167,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
exp_span, exp_found.expected, exp_found.found, exp_span, exp_found.expected, exp_found.found,
); );
if let ObligationCauseCode::CompareImplItemObligation { .. } = cause.code() { if let ObligationCauseCode::CompareImplItem { .. } = cause.code() {
return; return;
} }

View file

@ -1876,7 +1876,7 @@ impl<'tcx> SubregionOrigin<'tcx> {
SubregionOrigin::ReferenceOutlivesReferent(ref_type, cause.span) SubregionOrigin::ReferenceOutlivesReferent(ref_type, cause.span)
} }
traits::ObligationCauseCode::CompareImplItemObligation { traits::ObligationCauseCode::CompareImplItem {
impl_item_def_id, impl_item_def_id,
trait_item_def_id, trait_item_def_id,
kind: _, kind: _,

View file

@ -103,8 +103,8 @@ impl<'tcx> InferCtxt<'tcx> {
cause.span, cause.span,
sup_type, sup_type,
match cause.code().peel_derives() { match cause.code().peel_derives() {
ObligationCauseCode::BindingObligation(_, span) ObligationCauseCode::Where(_, span)
| ObligationCauseCode::ExprBindingObligation(_, span, ..) => Some(*span), | ObligationCauseCode::WhereInExpr(_, span, ..) => Some(*span),
_ => None, _ => None,
}, },
) )

View file

@ -129,14 +129,12 @@ impl<'tcx> Elaboratable<'tcx> for PredicateObligation<'tcx> {
index: usize, index: usize,
) -> Self { ) -> Self {
let cause = self.cause.clone().derived_cause(parent_trait_pred, |derived| { let cause = self.cause.clone().derived_cause(parent_trait_pred, |derived| {
ObligationCauseCode::ImplDerivedObligation(Box::new( ObligationCauseCode::ImplDerived(Box::new(traits::ImplDerivedObligationCause {
traits::ImplDerivedObligationCause { derived,
derived, impl_or_alias_def_id: parent_trait_pred.def_id(),
impl_or_alias_def_id: parent_trait_pred.def_id(), impl_def_predicate_index: Some(index),
impl_def_predicate_index: Some(index), span,
span, }))
},
))
}); });
Obligation { Obligation {
cause, cause,

View file

@ -150,11 +150,8 @@ fn suggest_question_mark<'tcx>(
let ocx = ObligationCtxt::new(&infcx); let ocx = ObligationCtxt::new(&infcx);
let body_def_id = cx.tcx.hir().body_owner_def_id(body_id); let body_def_id = cx.tcx.hir().body_owner_def_id(body_id);
let cause = ObligationCause::new( let cause =
span, ObligationCause::new(span, body_def_id, rustc_infer::traits::ObligationCauseCode::Misc);
body_def_id,
rustc_infer::traits::ObligationCauseCode::MiscObligation,
);
ocx.register_bound( ocx.register_bound(
cause, cause,

View file

@ -127,7 +127,7 @@ impl<'tcx> ObligationCause<'tcx> {
} }
pub fn misc(span: Span, body_id: LocalDefId) -> ObligationCause<'tcx> { pub fn misc(span: Span, body_id: LocalDefId) -> ObligationCause<'tcx> {
ObligationCause::new(span, body_id, ObligationCauseCode::MiscObligation) ObligationCause::new(span, body_id, ObligationCauseCode::Misc)
} }
#[inline(always)] #[inline(always)]
@ -207,7 +207,7 @@ pub struct UnifyReceiverContext<'tcx> {
#[derive(Clone, PartialEq, Eq, Default, HashStable)] #[derive(Clone, PartialEq, Eq, Default, HashStable)]
#[derive(TypeVisitable, TypeFoldable, TyEncodable, TyDecodable)] #[derive(TypeVisitable, TypeFoldable, TyEncodable, TyDecodable)]
pub struct InternedObligationCauseCode<'tcx> { pub struct InternedObligationCauseCode<'tcx> {
/// `None` for `ObligationCauseCode::MiscObligation` (a common case, occurs ~60% of /// `None` for `ObligationCauseCode::Misc` (a common case, occurs ~60% of
/// the time). `Some` otherwise. /// the time). `Some` otherwise.
code: Option<Lrc<ObligationCauseCode<'tcx>>>, code: Option<Lrc<ObligationCauseCode<'tcx>>>,
} }
@ -223,11 +223,7 @@ impl<'tcx> ObligationCauseCode<'tcx> {
#[inline(always)] #[inline(always)]
fn into(self) -> InternedObligationCauseCode<'tcx> { fn into(self) -> InternedObligationCauseCode<'tcx> {
InternedObligationCauseCode { InternedObligationCauseCode {
code: if let ObligationCauseCode::MiscObligation = self { code: if let ObligationCauseCode::Misc = self { None } else { Some(Lrc::new(self)) },
None
} else {
Some(Lrc::new(self))
},
} }
} }
} }
@ -236,7 +232,7 @@ impl<'tcx> std::ops::Deref for InternedObligationCauseCode<'tcx> {
type Target = ObligationCauseCode<'tcx>; type Target = ObligationCauseCode<'tcx>;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
self.code.as_deref().unwrap_or(&ObligationCauseCode::MiscObligation) self.code.as_deref().unwrap_or(&ObligationCauseCode::Misc)
} }
} }
@ -244,7 +240,7 @@ impl<'tcx> std::ops::Deref for InternedObligationCauseCode<'tcx> {
#[derive(TypeVisitable, TypeFoldable)] #[derive(TypeVisitable, TypeFoldable)]
pub enum ObligationCauseCode<'tcx> { pub enum ObligationCauseCode<'tcx> {
/// Not well classified or should be obvious from the span. /// Not well classified or should be obvious from the span.
MiscObligation, Misc,
/// A slice or array is WF only if `T: Sized`. /// A slice or array is WF only if `T: Sized`.
SliceOrArrayElem, SliceOrArrayElem,
@ -254,20 +250,20 @@ pub enum ObligationCauseCode<'tcx> {
/// Must satisfy all of the where-clause predicates of the /// Must satisfy all of the where-clause predicates of the
/// given item. /// given item.
ItemObligation(DefId), MiscItem(DefId),
/// Like `ItemObligation`, but carries the span of the /// Like `MiscItem`, but carries the span of the
/// predicate when it can be identified. /// predicate when it can be identified.
BindingObligation(DefId, Span), Where(DefId, Span),
/// Like `ItemObligation`, but carries the `HirId` of the /// Like `ItemObligation`, but carries the `HirId` of the
/// expression that caused the obligation, and the `usize` /// expression that caused the obligation, and the `usize`
/// indicates exactly which predicate it is in the list of /// indicates exactly which predicate it is in the list of
/// instantiated predicates. /// instantiated predicates.
ExprItemObligation(DefId, HirId, usize), MiscItemInExpr(DefId, HirId, usize),
/// Combines `ExprItemObligation` and `BindingObligation`. /// Combines `ExprItemObligation` and `BindingObligation`.
ExprBindingObligation(DefId, Span, HirId, usize), WhereInExpr(DefId, Span, HirId, usize),
/// A type like `&'a T` is WF only if `T: 'a`. /// A type like `&'a T` is WF only if `T: 'a`.
ReferenceOutlivesReferent(Ty<'tcx>), ReferenceOutlivesReferent(Ty<'tcx>),
@ -331,14 +327,14 @@ pub enum ObligationCauseCode<'tcx> {
/// Derived obligation (i.e. theoretical `where` clause) on a built-in /// Derived obligation (i.e. theoretical `where` clause) on a built-in
/// implementation like `Copy` or `Sized`. /// implementation like `Copy` or `Sized`.
BuiltinDerivedObligation(DerivedObligationCause<'tcx>), BuiltinDerived(DerivedObligationCause<'tcx>),
/// Derived obligation (i.e. `where` clause) on an user-provided impl /// Derived obligation (i.e. `where` clause) on an user-provided impl
/// or a trait alias. /// or a trait alias.
ImplDerivedObligation(Box<ImplDerivedObligationCause<'tcx>>), ImplDerived(Box<ImplDerivedObligationCause<'tcx>>),
/// Derived obligation for WF goals. /// Derived obligation for WF goals.
WellFormedDerivedObligation(DerivedObligationCause<'tcx>), WellFormedDerived(DerivedObligationCause<'tcx>),
FunctionArgumentObligation { FunctionArgumentObligation {
/// The node of the relevant argument in the function call. /// The node of the relevant argument in the function call.
@ -430,8 +426,8 @@ pub enum ObligationCauseCode<'tcx> {
/// then it will be used to perform HIR-based wf checking /// then it will be used to perform HIR-based wf checking
/// after an error occurs, in order to generate a more precise error span. /// after an error occurs, in order to generate a more precise error span.
/// This is purely for diagnostic purposes - it is always /// This is purely for diagnostic purposes - it is always
/// correct to use `MiscObligation` instead, or to specify /// correct to use `Misc` instead, or to specify
/// `WellFormed(None)` /// `WellFormed(None)`.
WellFormed(Option<WellFormedLoc>), WellFormed(Option<WellFormedLoc>),
/// From `match_impl`. The cause for us having to match an impl, and the DefId we are matching against. /// From `match_impl`. The cause for us having to match an impl, and the DefId we are matching against.
@ -538,14 +534,11 @@ impl<'tcx> ObligationCauseCode<'tcx> {
pub fn parent(&self) -> Option<(&Self, Option<ty::PolyTraitPredicate<'tcx>>)> { pub fn parent(&self) -> Option<(&Self, Option<ty::PolyTraitPredicate<'tcx>>)> {
match self { match self {
ObligationCauseCode::FunctionArgumentObligation { parent_code, .. } => { ObligationCauseCode::FunctionArg { parent_code, .. } => Some((parent_code, None)),
Some((parent_code, None)) ObligationCauseCode::BuiltinDerived(derived)
} | ObligationCauseCode::WellFormedDerived(derived)
ObligationCauseCode::BuiltinDerivedObligation(derived) | ObligationCauseCode::ImplDerived(box ImplDerivedObligationCause {
| ObligationCauseCode::WellFormedDerivedObligation(derived) derived, ..
| ObligationCauseCode::ImplDerivedObligation(box ImplDerivedObligationCause {
derived,
..
}) => Some((&derived.parent_code, Some(derived.parent_trait_pred))), }) => Some((&derived.parent_code, Some(derived.parent_trait_pred))),
_ => None, _ => None,
} }

View file

@ -425,14 +425,12 @@ fn derive_cause<'tcx>(
tcx.predicates_of(impl_def_id).instantiate_identity(tcx).iter().nth(idx) tcx.predicates_of(impl_def_id).instantiate_identity(tcx).iter().nth(idx)
{ {
cause = cause.derived_cause(parent_trait_pred, |derived| { cause = cause.derived_cause(parent_trait_pred, |derived| {
ObligationCauseCode::ImplDerivedObligation(Box::new( ObligationCauseCode::ImplDerived(Box::new(traits::ImplDerivedObligationCause {
traits::ImplDerivedObligationCause { derived,
derived, impl_or_alias_def_id: impl_def_id,
impl_or_alias_def_id: impl_def_id, impl_def_predicate_index: Some(idx),
impl_def_predicate_index: Some(idx), span,
span, }))
},
))
}) })
} }
} }

View file

@ -127,9 +127,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
flags.push((sym::ItemContext, enclosure)); flags.push((sym::ItemContext, enclosure));
match obligation.cause.code() { match obligation.cause.code() {
ObligationCauseCode::BuiltinDerivedObligation(..) ObligationCauseCode::BuiltinDerived(..)
| ObligationCauseCode::ImplDerivedObligation(..) | ObligationCauseCode::ImplDerived(..)
| ObligationCauseCode::WellFormedDerivedObligation(..) => {} | ObligationCauseCode::WellFormedDerived(..) => {}
_ => { _ => {
// this is a "direct", user-specified, rather than derived, // this is a "direct", user-specified, rather than derived,
// obligation. // obligation.

View file

@ -455,8 +455,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
trait_pred: ty::PolyTraitPredicate<'tcx>, trait_pred: ty::PolyTraitPredicate<'tcx>,
) -> bool { ) -> bool {
let mut code = obligation.cause.code(); let mut code = obligation.cause.code();
if let ObligationCauseCode::FunctionArgumentObligation { arg_hir_id, call_hir_id, .. } = if let ObligationCauseCode::FunctionArg { arg_hir_id, call_hir_id, .. } = code
code
&& let Some(typeck_results) = &self.typeck_results && let Some(typeck_results) = &self.typeck_results
&& let hir::Node::Expr(expr) = self.tcx.hir_node(*arg_hir_id) && let hir::Node::Expr(expr) = self.tcx.hir_node(*arg_hir_id)
&& let Some(arg_ty) = typeck_results.expr_ty_adjusted_opt(expr) && let Some(arg_ty) = typeck_results.expr_ty_adjusted_opt(expr)
@ -846,7 +845,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", "); .join(", ");
if matches!(obligation.cause.code(), ObligationCauseCode::FunctionArgumentObligation { .. }) if matches!(obligation.cause.code(), ObligationCauseCode::FunctionArg { .. })
&& obligation.cause.span.can_be_used_for_suggestions() && obligation.cause.span.can_be_used_for_suggestions()
{ {
// When the obligation error has been ensured to have been caused by // When the obligation error has been ensured to have been caused by
@ -980,8 +979,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
}; };
let ty::Ref(_, inner_ty, hir::Mutability::Not) = ty.kind() else { return false }; let ty::Ref(_, inner_ty, hir::Mutability::Not) = ty.kind() else { return false };
let ty::Param(param) = inner_ty.kind() else { return false }; let ty::Param(param) = inner_ty.kind() else { return false };
let ObligationCauseCode::FunctionArgumentObligation { arg_hir_id, .. } = let ObligationCauseCode::FunctionArg { arg_hir_id, .. } = obligation.cause.code()
obligation.cause.code()
else { else {
return false; return false;
}; };
@ -1204,9 +1202,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
let span = obligation.cause.span; let span = obligation.cause.span;
let code = match obligation.cause.code() { let code = match obligation.cause.code() {
ObligationCauseCode::FunctionArgumentObligation { parent_code, .. } => parent_code, ObligationCauseCode::FunctionArg { parent_code, .. } => parent_code,
c @ ObligationCauseCode::ItemObligation(_) c @ ObligationCauseCode::MiscItem(_) | c @ ObligationCauseCode::MiscItemInExpr(..) => c,
| c @ ObligationCauseCode::ExprItemObligation(..) => c,
c if matches!( c if matches!(
span.ctxt().outer_expn_data().kind, span.ctxt().outer_expn_data().kind,
ExpnKind::Desugaring(DesugaringKind::ForLoop) ExpnKind::Desugaring(DesugaringKind::ForLoop)
@ -1262,8 +1259,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
let mut_ref_self_ty_satisfies_pred = mk_result(trait_pred_and_mut_ref); let mut_ref_self_ty_satisfies_pred = mk_result(trait_pred_and_mut_ref);
let (ref_inner_ty_satisfies_pred, ref_inner_ty_mut) = let (ref_inner_ty_satisfies_pred, ref_inner_ty_mut) =
if let ObligationCauseCode::ItemObligation(_) if let ObligationCauseCode::MiscItem(_) | ObligationCauseCode::MiscItemInExpr(..) =
| ObligationCauseCode::ExprItemObligation(..) = obligation.cause.code() obligation.cause.code()
&& let ty::Ref(_, ty, mutability) = old_pred.self_ty().skip_binder().kind() && let ty::Ref(_, ty, mutability) = old_pred.self_ty().skip_binder().kind()
{ {
( (
@ -1401,12 +1398,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
return false; return false;
}; };
if let ObligationCauseCode::ImplDerivedObligation(cause) = &*code { if let ObligationCauseCode::ImplDerived(cause) = &*code {
try_borrowing(cause.derived.parent_trait_pred, &[]) try_borrowing(cause.derived.parent_trait_pred, &[])
} else if let ObligationCauseCode::BindingObligation(_, _) } else if let ObligationCauseCode::Where(_, _)
| ObligationCauseCode::ItemObligation(_) | ObligationCauseCode::MiscItem(_)
| ObligationCauseCode::ExprItemObligation(..) | ObligationCauseCode::MiscItemInExpr(..)
| ObligationCauseCode::ExprBindingObligation(..) = code | ObligationCauseCode::WhereInExpr(..) = code
{ {
try_borrowing(poly_trait_pred, &never_suggest_borrow) try_borrowing(poly_trait_pred, &never_suggest_borrow)
} else { } else {
@ -1644,10 +1641,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
err: &mut Diag<'_>, err: &mut Diag<'_>,
trait_pred: ty::PolyTraitPredicate<'tcx>, trait_pred: ty::PolyTraitPredicate<'tcx>,
) { ) {
let points_at_arg = matches!( let points_at_arg =
obligation.cause.code(), matches!(obligation.cause.code(), ObligationCauseCode::FunctionArg { .. },);
ObligationCauseCode::FunctionArgumentObligation { .. },
);
let span = obligation.cause.span; let span = obligation.cause.span;
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) { if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
@ -1953,7 +1948,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
found: Ty<'tcx>, found: Ty<'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
) { ) {
let ObligationCauseCode::FunctionArgumentObligation { arg_hir_id, .. } = cause else { let ObligationCauseCode::FunctionArg { arg_hir_id, .. } = cause else {
return; return;
}; };
let ty::FnPtr(expected) = expected.kind() else { let ty::FnPtr(expected) = expected.kind() else {
@ -2107,7 +2102,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
// First, look for an `ExprBindingObligation`, which means we can get // First, look for an `ExprBindingObligation`, which means we can get
// the uninstantiated predicate list of the called function. And check // the uninstantiated predicate list of the called function. And check
// that the predicate that we failed to satisfy is a `Fn`-like trait. // that the predicate that we failed to satisfy is a `Fn`-like trait.
if let ObligationCauseCode::ExprBindingObligation(def_id, _, _, idx) = cause if let ObligationCauseCode::WhereInExpr(def_id, _, _, idx) = cause
&& let predicates = self.tcx.predicates_of(def_id).instantiate_identity(self.tcx) && let predicates = self.tcx.predicates_of(def_id).instantiate_identity(self.tcx)
&& let Some(pred) = predicates.predicates.get(*idx) && let Some(pred) = predicates.predicates.get(*idx)
&& let ty::ClauseKind::Trait(trait_pred) = pred.kind().skip_binder() && let ty::ClauseKind::Trait(trait_pred) = pred.kind().skip_binder()
@ -2261,10 +2256,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
while let Some(code) = next_code { while let Some(code) = next_code {
debug!(?code); debug!(?code);
match code { match code {
ObligationCauseCode::FunctionArgumentObligation { parent_code, .. } => { ObligationCauseCode::FunctionArg { parent_code, .. } => {
next_code = Some(parent_code); next_code = Some(parent_code);
} }
ObligationCauseCode::ImplDerivedObligation(cause) => { ObligationCauseCode::ImplDerived(cause) => {
let ty = cause.derived.parent_trait_pred.skip_binder().self_ty(); let ty = cause.derived.parent_trait_pred.skip_binder().self_ty();
debug!( debug!(
parent_trait_ref = ?cause.derived.parent_trait_pred, parent_trait_ref = ?cause.derived.parent_trait_pred,
@ -2293,8 +2288,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
next_code = Some(&cause.derived.parent_code); next_code = Some(&cause.derived.parent_code);
} }
ObligationCauseCode::WellFormedDerivedObligation(derived_obligation) ObligationCauseCode::WellFormedDerived(derived_obligation)
| ObligationCauseCode::BuiltinDerivedObligation(derived_obligation) => { | ObligationCauseCode::BuiltinDerived(derived_obligation) => {
let ty = derived_obligation.parent_trait_pred.skip_binder().self_ty(); let ty = derived_obligation.parent_trait_pred.skip_binder().self_ty();
debug!( debug!(
parent_trait_ref = ?derived_obligation.parent_trait_pred, parent_trait_ref = ?derived_obligation.parent_trait_pred,
@ -2719,7 +2714,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
| ObligationCauseCode::MethodReceiver | ObligationCauseCode::MethodReceiver
| ObligationCauseCode::ReturnNoExpression | ObligationCauseCode::ReturnNoExpression
| ObligationCauseCode::UnifyReceiver(..) | ObligationCauseCode::UnifyReceiver(..)
| ObligationCauseCode::MiscObligation | ObligationCauseCode::Misc
| ObligationCauseCode::WellFormed(..) | ObligationCauseCode::WellFormed(..)
| ObligationCauseCode::MatchImpl(..) | ObligationCauseCode::MatchImpl(..)
| ObligationCauseCode::ReturnValue(_) | ObligationCauseCode::ReturnValue(_)
@ -2748,13 +2743,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
ObligationCauseCode::TupleElem => { ObligationCauseCode::TupleElem => {
err.note("only the last element of a tuple may have a dynamically sized type"); err.note("only the last element of a tuple may have a dynamically sized type");
} }
ObligationCauseCode::ItemObligation(_) ObligationCauseCode::MiscItem(_) | ObligationCauseCode::MiscItemInExpr(..) => {
| ObligationCauseCode::ExprItemObligation(..) => {
// We hold the `DefId` of the item introducing the obligation, but displaying it // We hold the `DefId` of the item introducing the obligation, but displaying it
// doesn't add user usable information. It always point at an associated item. // doesn't add user usable information. It always point at an associated item.
} }
ObligationCauseCode::BindingObligation(item_def_id, span) ObligationCauseCode::Where(item_def_id, span)
| ObligationCauseCode::ExprBindingObligation(item_def_id, span, ..) => { | ObligationCauseCode::WhereInExpr(item_def_id, span, ..) => {
let item_name = tcx.def_path_str(item_def_id); let item_name = tcx.def_path_str(item_def_id);
let short_item_name = with_forced_trimmed_paths!(tcx.def_path_str(item_def_id)); let short_item_name = with_forced_trimmed_paths!(tcx.def_path_str(item_def_id));
let mut multispan = MultiSpan::from(span); let mut multispan = MultiSpan::from(span);
@ -3175,7 +3169,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
ObligationCauseCode::SharedStatic => { ObligationCauseCode::SharedStatic => {
err.note("shared static variables must have a type that implements `Sync`"); err.note("shared static variables must have a type that implements `Sync`");
} }
ObligationCauseCode::BuiltinDerivedObligation(ref data) => { ObligationCauseCode::BuiltinDerived(ref data) => {
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_pred); let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_pred);
let ty = parent_trait_ref.skip_binder().self_ty(); let ty = parent_trait_ref.skip_binder().self_ty();
if parent_trait_ref.references_error() { if parent_trait_ref.references_error() {
@ -3190,8 +3184,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
let is_upvar_tys_infer_tuple = if !matches!(ty.kind(), ty::Tuple(..)) { let is_upvar_tys_infer_tuple = if !matches!(ty.kind(), ty::Tuple(..)) {
false false
} else { } else {
if let ObligationCauseCode::BuiltinDerivedObligation(data) = &*data.parent_code if let ObligationCauseCode::BuiltinDerived(data) = &*data.parent_code {
{
let parent_trait_ref = let parent_trait_ref =
self.resolve_vars_if_possible(data.parent_trait_pred); self.resolve_vars_if_possible(data.parent_trait_pred);
let nested_ty = parent_trait_ref.skip_binder().self_ty(); let nested_ty = parent_trait_ref.skip_binder().self_ty();
@ -3297,7 +3290,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
}); });
} }
} }
ObligationCauseCode::ImplDerivedObligation(ref data) => { ObligationCauseCode::ImplDerived(ref data) => {
let mut parent_trait_pred = let mut parent_trait_pred =
self.resolve_vars_if_possible(data.derived.parent_trait_pred); self.resolve_vars_if_possible(data.derived.parent_trait_pred);
let parent_def_id = parent_trait_pred.def_id(); let parent_def_id = parent_trait_pred.def_id();
@ -3367,9 +3360,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
if is_auto_trait { if is_auto_trait {
// We don't want to point at the ADT saying "required because it appears within // We don't want to point at the ADT saying "required because it appears within
// the type `X`", like we would otherwise do in test `supertrait-auto-trait.rs`. // the type `X`", like we would otherwise do in test `supertrait-auto-trait.rs`.
while let ObligationCauseCode::BuiltinDerivedObligation(derived) = while let ObligationCauseCode::BuiltinDerived(derived) = &*data.parent_code {
&*data.parent_code
{
let child_trait_ref = let child_trait_ref =
self.resolve_vars_if_possible(derived.parent_trait_pred); self.resolve_vars_if_possible(derived.parent_trait_pred);
let child_def_id = child_trait_ref.def_id(); let child_def_id = child_trait_ref.def_id();
@ -3381,7 +3372,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
parent_trait_pred = child_trait_ref; parent_trait_pred = child_trait_ref;
} }
} }
while let ObligationCauseCode::ImplDerivedObligation(child) = &*data.parent_code { while let ObligationCauseCode::ImplDerived(child) = &*data.parent_code {
// Skip redundant recursive obligation notes. See `ui/issue-20413.rs`. // Skip redundant recursive obligation notes. See `ui/issue-20413.rs`.
let child_trait_pred = let child_trait_pred =
self.resolve_vars_if_possible(child.derived.parent_trait_pred); self.resolve_vars_if_possible(child.derived.parent_trait_pred);
@ -3422,7 +3413,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
) )
}); });
} }
ObligationCauseCode::WellFormedDerivedObligation(ref data) => { ObligationCauseCode::WellFormedDerived(ref data) => {
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_pred); let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_pred);
let parent_predicate = parent_trait_ref; let parent_predicate = parent_trait_ref;
// #74711: avoid a stack overflow // #74711: avoid a stack overflow
@ -3458,11 +3449,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
format!("required by a bound on the type alias `{}`", tcx.item_name(def_id)), format!("required by a bound on the type alias `{}`", tcx.item_name(def_id)),
); );
} }
ObligationCauseCode::FunctionArgumentObligation { ObligationCauseCode::FunctionArg {
arg_hir_id, arg_hir_id, call_hir_id, ref parent_code, ..
call_hir_id,
ref parent_code,
..
} => { } => {
self.note_function_argument_obligation( self.note_function_argument_obligation(
body_id, body_id,
@ -3485,7 +3473,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
) )
}); });
} }
ObligationCauseCode::CompareImplItemObligation { trait_item_def_id, kind, .. } => { ObligationCauseCode::CompareImplItem { trait_item_def_id, kind, .. } => {
let item_name = tcx.item_name(trait_item_def_id); let item_name = tcx.item_name(trait_item_def_id);
let msg = format!( let msg = format!(
"the requirement `{predicate}` appears on the `impl`'s {kind} \ "the requirement `{predicate}` appears on the `impl`'s {kind} \
@ -3694,7 +3682,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
err: &mut Diag<'_>, err: &mut Diag<'_>,
trait_pred: ty::PolyTraitPredicate<'tcx>, trait_pred: ty::PolyTraitPredicate<'tcx>,
) { ) {
if let ObligationCauseCode::ImplDerivedObligation(_) = obligation.cause.code() if let ObligationCauseCode::ImplDerived(_) = obligation.cause.code()
&& self && self
.tcx .tcx
.is_diagnostic_item(sym::SliceIndex, trait_pred.skip_binder().trait_ref.def_id) .is_diagnostic_item(sym::SliceIndex, trait_pred.skip_binder().trait_ref.def_id)
@ -3811,7 +3799,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
// to an associated type (as seen from `trait_pred`) in the predicate. Like in // to an associated type (as seen from `trait_pred`) in the predicate. Like in
// trait_pred `S: Sum<<Self as Iterator>::Item>` and predicate `i32: Sum<&()>` // trait_pred `S: Sum<<Self as Iterator>::Item>` and predicate `i32: Sum<&()>`
let mut type_diffs = vec![]; let mut type_diffs = vec![];
if let ObligationCauseCode::ExprBindingObligation(def_id, _, _, idx) = parent_code if let ObligationCauseCode::WhereInExpr(def_id, _, _, idx) = parent_code
&& let Some(node_args) = typeck_results.node_args_opt(call_hir_id) && let Some(node_args) = typeck_results.node_args_opt(call_hir_id)
&& let where_clauses = && let where_clauses =
self.tcx.predicates_of(def_id).instantiate(self.tcx, node_args) self.tcx.predicates_of(def_id).instantiate(self.tcx, node_args)
@ -4320,8 +4308,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
) { ) {
// We can only suggest the slice coersion for function and binary operation arguments, // We can only suggest the slice coersion for function and binary operation arguments,
// since the suggestion would make no sense in turbofish or call // since the suggestion would make no sense in turbofish or call
let (ObligationCauseCode::BinOp { .. } let (ObligationCauseCode::BinOp { .. } | ObligationCauseCode::FunctionArg { .. }) =
| ObligationCauseCode::FunctionArgumentObligation { .. }) = obligation.cause.code() obligation.cause.code()
else { else {
return; return;
}; };
@ -4407,7 +4395,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
return; return;
} }
if let ObligationCauseCode::FunctionArgumentObligation { if let ObligationCauseCode::FunctionArg {
call_hir_id, call_hir_id,
arg_hir_id, arg_hir_id,
parent_code: _, parent_code: _,

View file

@ -391,7 +391,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
} }
} }
if let ObligationCauseCode::CompareImplItemObligation { if let ObligationCauseCode::CompareImplItem {
impl_item_def_id, impl_item_def_id,
trait_item_def_id, trait_item_def_id,
kind: _, kind: _,
@ -1017,7 +1017,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
if let Some((_, Some(parent))) = obligation.cause.code().parent() { if let Some((_, Some(parent))) = obligation.cause.code().parent() {
// If we have a derived obligation, then the parent will be a `AsyncFn*` goal. // If we have a derived obligation, then the parent will be a `AsyncFn*` goal.
trait_ref = parent.to_poly_trait_ref(); trait_ref = parent.to_poly_trait_ref();
} else if let &ObligationCauseCode::FunctionArgumentObligation { arg_hir_id, .. } = } else if let &ObligationCauseCode::FunctionArg { arg_hir_id, .. } =
obligation.cause.code() obligation.cause.code()
&& let Some(typeck_results) = &self.typeck_results && let Some(typeck_results) = &self.typeck_results
&& let ty::Closure(closure_def_id, _) | ty::CoroutineClosure(closure_def_id, _) = && let ty::Closure(closure_def_id, _) | ty::CoroutineClosure(closure_def_id, _) =
@ -1104,8 +1104,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
&self, &self,
obligation: &PredicateObligation<'tcx>, obligation: &PredicateObligation<'tcx>,
) -> Result<(), ErrorGuaranteed> { ) -> Result<(), ErrorGuaranteed> {
if let ObligationCauseCode::FunctionArgumentObligation { arg_hir_id, .. } = if let ObligationCauseCode::FunctionArg { arg_hir_id, .. } = obligation.cause.code()
obligation.cause.code()
&& let Node::Expr(arg) = self.tcx.hir_node(*arg_hir_id) && let Node::Expr(arg) = self.tcx.hir_node(*arg_hir_id)
&& let arg = arg.peel_borrows() && let arg = arg.peel_borrows()
&& let hir::ExprKind::Path(hir::QPath::Resolved( && let hir::ExprKind::Path(hir::QPath::Resolved(
@ -1534,10 +1533,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
*err, *err,
); );
let code = error.obligation.cause.code().peel_derives().peel_match_impls(); let code = error.obligation.cause.code().peel_derives().peel_match_impls();
if let ObligationCauseCode::BindingObligation(..) if let ObligationCauseCode::Where(..)
| ObligationCauseCode::ItemObligation(..) | ObligationCauseCode::MiscItem(..)
| ObligationCauseCode::ExprBindingObligation(..) | ObligationCauseCode::WhereInExpr(..)
| ObligationCauseCode::ExprItemObligation(..) = code | ObligationCauseCode::MiscItemInExpr(..) = code
{ {
self.note_obligation_cause_code( self.note_obligation_cause_code(
error.obligation.cause.body_id, error.obligation.cause.body_id,
@ -1611,10 +1610,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
let is_normalized_term_expected = !matches!( let is_normalized_term_expected = !matches!(
obligation.cause.code().peel_derives(), obligation.cause.code().peel_derives(),
ObligationCauseCode::ItemObligation(_) ObligationCauseCode::MiscItem(_)
| ObligationCauseCode::BindingObligation(_, _) | ObligationCauseCode::Where(_, _)
| ObligationCauseCode::ExprItemObligation(..) | ObligationCauseCode::MiscItemInExpr(..)
| ObligationCauseCode::ExprBindingObligation(..) | ObligationCauseCode::WhereInExpr(..)
| ObligationCauseCode::Coercion { .. } | ObligationCauseCode::Coercion { .. }
); );
@ -2211,7 +2210,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
code: &ObligationCauseCode<'tcx>, code: &ObligationCauseCode<'tcx>,
) -> Option<(Ty<'tcx>, Option<Span>)> { ) -> Option<(Ty<'tcx>, Option<Span>)> {
match code { match code {
ObligationCauseCode::BuiltinDerivedObligation(data) => { ObligationCauseCode::BuiltinDerived(data) => {
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_pred); let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_pred);
match self.get_parent_trait_ref(&data.parent_code) { match self.get_parent_trait_ref(&data.parent_code) {
Some(t) => Some(t), Some(t) => Some(t),
@ -2223,7 +2222,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
} }
} }
} }
ObligationCauseCode::FunctionArgumentObligation { parent_code, .. } => { ObligationCauseCode::FunctionArg { parent_code, .. } => {
self.get_parent_trait_ref(parent_code) self.get_parent_trait_ref(parent_code)
} }
_ => None, _ => None,
@ -2446,8 +2445,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
} }
} }
if let ObligationCauseCode::ItemObligation(def_id) if let ObligationCauseCode::MiscItem(def_id)
| ObligationCauseCode::ExprItemObligation(def_id, ..) = *obligation.cause.code() | ObligationCauseCode::MiscItemInExpr(def_id, ..) = *obligation.cause.code()
{ {
self.suggest_fully_qualified_path(&mut err, def_id, span, trait_ref.def_id()); self.suggest_fully_qualified_path(&mut err, def_id, span, trait_ref.def_id());
} }
@ -2882,8 +2881,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
else { else {
return; return;
}; };
let (ObligationCauseCode::BindingObligation(item_def_id, span) let (ObligationCauseCode::Where(item_def_id, span)
| ObligationCauseCode::ExprBindingObligation(item_def_id, span, ..)) = | ObligationCauseCode::WhereInExpr(item_def_id, span, ..)) =
*obligation.cause.code().peel_derives() *obligation.cause.code().peel_derives()
else { else {
return; return;
@ -3003,7 +3002,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
obligated_types: &mut Vec<Ty<'tcx>>, obligated_types: &mut Vec<Ty<'tcx>>,
cause_code: &ObligationCauseCode<'tcx>, cause_code: &ObligationCauseCode<'tcx>,
) -> bool { ) -> bool {
if let ObligationCauseCode::BuiltinDerivedObligation(ref data) = cause_code { if let ObligationCauseCode::BuiltinDerived(ref data) = cause_code {
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_pred); let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_pred);
let self_ty = parent_trait_ref.skip_binder().self_ty(); let self_ty = parent_trait_ref.skip_binder().self_ty();
if obligated_types.iter().any(|ot| ot == &self_ty) { if obligated_types.iter().any(|ot| ot == &self_ty) {
@ -3180,8 +3179,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
ObligationCauseCode::RustCall => { ObligationCauseCode::RustCall => {
err.primary_message("functions with the \"rust-call\" ABI must take a single non-self tuple argument"); err.primary_message("functions with the \"rust-call\" ABI must take a single non-self tuple argument");
} }
ObligationCauseCode::BindingObligation(def_id, _) ObligationCauseCode::Where(def_id, _) | ObligationCauseCode::MiscItem(def_id)
| ObligationCauseCode::ItemObligation(def_id)
if self.tcx.is_fn_trait(*def_id) => if self.tcx.is_fn_trait(*def_id) =>
{ {
err.code(E0059); err.code(E0059);
@ -3570,7 +3568,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
match self.tcx.sess.source_map().span_to_snippet(const_span) { match self.tcx.sess.source_map().span_to_snippet(const_span) {
Ok(snippet) => { Ok(snippet) => {
let code = format!("[(); {snippet}{cast}]:"); let code = format!("[(); {snippet}{cast}]:");
let def_id = if let ObligationCauseCode::CompareImplItemObligation { let def_id = if let ObligationCauseCode::CompareImplItem {
trait_item_def_id, trait_item_def_id,
.. ..
} = obligation.cause.code() } = obligation.cause.code()

View file

@ -574,9 +574,9 @@ pub fn normalize_inherent_projection<'a, 'b, 'tcx>(
// diagnostics which is not ideal. // diagnostics which is not ideal.
// Consider creating separate cause codes for this specific situation. // Consider creating separate cause codes for this specific situation.
if span.is_dummy() { if span.is_dummy() {
ObligationCauseCode::ItemObligation(alias_ty.def_id) ObligationCauseCode::MiscItem(alias_ty.def_id)
} else { } else {
ObligationCauseCode::BindingObligation(alias_ty.def_id, span) ObligationCauseCode::Where(alias_ty.def_id, span)
}, },
); );
@ -2114,7 +2114,7 @@ fn assoc_ty_own_obligations<'cx, 'tcx>(
let nested_cause = if matches!( let nested_cause = if matches!(
obligation.cause.code(), obligation.cause.code(),
ObligationCauseCode::CompareImplItemObligation { .. } ObligationCauseCode::CompareImplItem { .. }
| ObligationCauseCode::CheckAssociatedTypeBounds { .. } | ObligationCauseCode::CheckAssociatedTypeBounds { .. }
| ObligationCauseCode::AscribeUserTypeProvePredicate(..) | ObligationCauseCode::AscribeUserTypeProvePredicate(..)
) { ) {
@ -2123,13 +2123,13 @@ fn assoc_ty_own_obligations<'cx, 'tcx>(
ObligationCause::new( ObligationCause::new(
obligation.cause.span, obligation.cause.span,
obligation.cause.body_id, obligation.cause.body_id,
ObligationCauseCode::ItemObligation(obligation.predicate.def_id), ObligationCauseCode::MiscItem(obligation.predicate.def_id),
) )
} else { } else {
ObligationCause::new( ObligationCause::new(
obligation.cause.span, obligation.cause.span,
obligation.cause.body_id, obligation.cause.body_id,
ObligationCauseCode::BindingObligation(obligation.predicate.def_id, span), ObligationCauseCode::Where(obligation.predicate.def_id, span),
) )
}; };
nested.push(Obligation::with_depth( nested.push(Obligation::with_depth(

View file

@ -1396,7 +1396,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
debug!(?args, "impl args"); debug!(?args, "impl args");
let cause = obligation.derived_cause(|derived| { let cause = obligation.derived_cause(|derived| {
ObligationCauseCode::ImplDerivedObligation(Box::new(ImplDerivedObligationCause { ObligationCauseCode::ImplDerived(Box::new(ImplDerivedObligationCause {
derived, derived,
impl_or_alias_def_id: impl_def_id, impl_or_alias_def_id: impl_def_id,
impl_def_predicate_index: None, impl_def_predicate_index: None,

View file

@ -2771,14 +2771,12 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
cause.clone() cause.clone()
} else { } else {
cause.clone().derived_cause(parent_trait_pred, |derived| { cause.clone().derived_cause(parent_trait_pred, |derived| {
ObligationCauseCode::ImplDerivedObligation(Box::new( ObligationCauseCode::ImplDerived(Box::new(ImplDerivedObligationCause {
ImplDerivedObligationCause { derived,
derived, impl_or_alias_def_id: def_id,
impl_or_alias_def_id: def_id, impl_def_predicate_index: Some(index),
impl_def_predicate_index: Some(index), span,
span, }))
},
))
}) })
}; };
let clause = normalize_with_depth_to( let clause = normalize_with_depth_to(

View file

@ -566,9 +566,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
iter::zip(predicates, origins.into_iter().rev()) iter::zip(predicates, origins.into_iter().rev())
.map(|((pred, span), origin_def_id)| { .map(|((pred, span), origin_def_id)| {
let code = if span.is_dummy() { let code = if span.is_dummy() {
ObligationCauseCode::ItemObligation(origin_def_id) ObligationCauseCode::MiscItem(origin_def_id)
} else { } else {
ObligationCauseCode::BindingObligation(origin_def_id, span) ObligationCauseCode::Where(origin_def_id, span)
}; };
let cause = self.cause(code); let cause = self.cause(code);
traits::Obligation::with_depth( traits::Obligation::with_depth(
@ -683,7 +683,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
} }
ty::Pat(subty, _) => { ty::Pat(subty, _) => {
self.require_sized(subty, ObligationCauseCode::MiscObligation); self.require_sized(subty, ObligationCauseCode::Misc);
} }
ty::Tuple(tys) => { ty::Tuple(tys) => {