mirror of https://github.com/rust-lang/rust.git
Rename some ObligationCauseCode variants
This commit is contained in:
parent
4bde8a8f4b
commit
534e267d48
|
@ -2059,15 +2059,12 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
// We currently do not store the `DefId` in the `ConstraintCategory`
|
||||
// for performances reasons. The error reporting code used by NLL only
|
||||
// uses the span, so this doesn't cause any problems at the moment.
|
||||
Some(ObligationCauseCode::BindingObligation(
|
||||
CRATE_DEF_ID.to_def_id(),
|
||||
predicate_span,
|
||||
))
|
||||
Some(ObligationCauseCode::Where(CRATE_DEF_ID.to_def_id(), predicate_span))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.unwrap_or_else(|| ObligationCauseCode::MiscObligation);
|
||||
.unwrap_or_else(|| ObligationCauseCode::Misc);
|
||||
|
||||
// Classify each of the constraints along the path.
|
||||
let mut categorized_path: Vec<BlameConstraint<'tcx>> = path
|
||||
|
|
|
@ -738,7 +738,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
|
|||
let cause = ObligationCause::new(
|
||||
terminator.source_info.span,
|
||||
self.body.source.def_id().expect_local(),
|
||||
ObligationCauseCode::ItemObligation(callee),
|
||||
ObligationCauseCode::MiscItem(callee),
|
||||
);
|
||||
let normalized_predicates = ocx.normalize(&cause, param_env, predicates);
|
||||
ocx.register_obligations(traits::predicates_for_generics(
|
||||
|
|
|
@ -175,7 +175,7 @@ fn compare_method_predicate_entailment<'tcx>(
|
|||
let cause = ObligationCause::new(
|
||||
impl_m_span,
|
||||
impl_m_def_id,
|
||||
ObligationCauseCode::CompareImplItemObligation {
|
||||
ObligationCauseCode::CompareImplItem {
|
||||
impl_item_def_id: impl_m_def_id,
|
||||
trait_item_def_id: trait_m.def_id,
|
||||
kind: impl_m.kind,
|
||||
|
@ -236,7 +236,7 @@ fn compare_method_predicate_entailment<'tcx>(
|
|||
let cause = ObligationCause::new(
|
||||
span,
|
||||
impl_m_def_id,
|
||||
ObligationCauseCode::CompareImplItemObligation {
|
||||
ObligationCauseCode::CompareImplItem {
|
||||
impl_item_def_id: impl_m_def_id,
|
||||
trait_item_def_id: trait_m.def_id,
|
||||
kind: impl_m.kind,
|
||||
|
@ -464,7 +464,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
|
|||
let cause = ObligationCause::new(
|
||||
return_span,
|
||||
impl_m_def_id,
|
||||
ObligationCauseCode::CompareImplItemObligation {
|
||||
ObligationCauseCode::CompareImplItem {
|
||||
impl_item_def_id: impl_m_def_id,
|
||||
trait_item_def_id: trait_m.def_id,
|
||||
kind: impl_m.kind,
|
||||
|
@ -819,7 +819,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'_, 'tcx> {
|
|||
ObligationCause::new(
|
||||
self.span,
|
||||
self.body_id,
|
||||
ObligationCauseCode::BindingObligation(proj.def_id, pred_span),
|
||||
ObligationCauseCode::Where(proj.def_id, pred_span),
|
||||
),
|
||||
self.param_env,
|
||||
pred,
|
||||
|
@ -1752,7 +1752,7 @@ fn compare_const_predicate_entailment<'tcx>(
|
|||
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 code = ObligationCauseCode::CompareImplItemObligation {
|
||||
let code = ObligationCauseCode::CompareImplItem {
|
||||
impl_item_def_id: impl_ct_def_id,
|
||||
trait_item_def_id: trait_ct.def_id,
|
||||
kind: impl_ct.kind,
|
||||
|
@ -1924,7 +1924,7 @@ fn compare_type_predicate_entailment<'tcx>(
|
|||
let cause = ObligationCause::new(
|
||||
span,
|
||||
impl_ty_def_id,
|
||||
ObligationCauseCode::CompareImplItemObligation {
|
||||
ObligationCauseCode::CompareImplItem {
|
||||
impl_item_def_id: impl_ty.def_id.expect_local(),
|
||||
trait_item_def_id: trait_ty.def_id,
|
||||
kind: impl_ty.kind,
|
||||
|
@ -2012,9 +2012,9 @@ pub(super) fn check_type_bounds<'tcx>(
|
|||
);
|
||||
let mk_cause = |span: Span| {
|
||||
let code = if span.is_dummy() {
|
||||
ObligationCauseCode::ItemObligation(trait_ty.def_id)
|
||||
ObligationCauseCode::MiscItem(trait_ty.def_id)
|
||||
} 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)
|
||||
};
|
||||
|
@ -2251,8 +2251,7 @@ fn try_report_async_mismatch<'tcx>(
|
|||
};
|
||||
|
||||
for error in errors {
|
||||
if let ObligationCauseCode::BindingObligation(def_id, _) =
|
||||
*error.root_obligation.cause.code()
|
||||
if let ObligationCauseCode::Where(def_id, _) = *error.root_obligation.cause.code()
|
||||
&& def_id == async_future_def_id
|
||||
&& let Some(proj) = error.root_obligation.predicate.to_opt_poly_projection_pred()
|
||||
&& let Some(proj) = proj.no_bound_vars()
|
||||
|
|
|
@ -1161,7 +1161,7 @@ fn check_type_defn<'tcx>(
|
|||
let cause = traits::ObligationCause::new(
|
||||
tcx.def_span(discr_def_id),
|
||||
wfcx.body_def_id,
|
||||
ObligationCauseCode::MiscObligation,
|
||||
ObligationCauseCode::Misc,
|
||||
);
|
||||
wfcx.register_obligation(traits::Obligation::new(
|
||||
tcx,
|
||||
|
@ -1550,7 +1550,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
|
|||
let cause = traits::ObligationCause::new(
|
||||
sp,
|
||||
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)
|
||||
});
|
||||
|
|
|
@ -212,7 +212,7 @@ fn get_impl_args(
|
|||
traits::ObligationCause::new(
|
||||
impl1_span,
|
||||
impl1_def_id,
|
||||
traits::ObligationCauseCode::BindingObligation(impl2_node.def_id(), span),
|
||||
traits::ObligationCauseCode::Where(impl2_node.def_id(), span),
|
||||
)
|
||||
},
|
||||
);
|
||||
|
|
|
@ -3083,7 +3083,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
polarity: ty::PredicatePolarity::Positive,
|
||||
}),
|
||||
|derived| {
|
||||
ObligationCauseCode::ImplDerivedObligation(Box::new(
|
||||
ObligationCauseCode::ImplDerived(Box::new(
|
||||
traits::ImplDerivedObligationCause {
|
||||
derived,
|
||||
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);
|
||||
|
||||
// FIXME: DSTs with static alignment should be allowed
|
||||
self.require_type_is_sized(
|
||||
field_ty,
|
||||
expr.span,
|
||||
ObligationCauseCode::MiscObligation,
|
||||
);
|
||||
self.require_type_is_sized(field_ty, expr.span, ObligationCauseCode::Misc);
|
||||
|
||||
if field.vis.is_accessible_from(sub_def_scope, self.tcx) {
|
||||
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);
|
||||
|
||||
// FIXME: DSTs with static alignment should be allowed
|
||||
self.require_type_is_sized(
|
||||
field_ty,
|
||||
expr.span,
|
||||
ObligationCauseCode::MiscObligation,
|
||||
);
|
||||
self.require_type_is_sized(field_ty, expr.span, ObligationCauseCode::Misc);
|
||||
|
||||
if field.vis.is_accessible_from(def_scope, self.tcx) {
|
||||
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)
|
||||
{
|
||||
for ty in tys.iter().take(index + 1) {
|
||||
self.require_type_is_sized(
|
||||
ty,
|
||||
expr.span,
|
||||
ObligationCauseCode::MiscObligation,
|
||||
);
|
||||
self.require_type_is_sized(ty, expr.span, ObligationCauseCode::Misc);
|
||||
}
|
||||
if let Some(&field_ty) = tys.get(index) {
|
||||
field_indices.push((FIRST_VARIANT, index.into()));
|
||||
|
|
|
@ -1413,9 +1413,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
) {
|
||||
self.add_required_obligations_with_code(span, def_id, args, |idx, span| {
|
||||
if span.is_dummy() {
|
||||
ObligationCauseCode::ExprItemObligation(def_id, hir_id, idx)
|
||||
ObligationCauseCode::MiscItemInExpr(def_id, hir_id, idx)
|
||||
} else {
|
||||
ObligationCauseCode::ExprBindingObligation(def_id, span, hir_id, idx)
|
||||
ObligationCauseCode::WhereInExpr(def_id, span, hir_id, idx)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -14,8 +14,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
&self,
|
||||
error: &mut traits::FulfillmentError<'tcx>,
|
||||
) -> bool {
|
||||
let (ObligationCauseCode::ExprItemObligation(def_id, hir_id, idx)
|
||||
| ObligationCauseCode::ExprBindingObligation(def_id, _, hir_id, idx)) =
|
||||
let (ObligationCauseCode::MiscItemInExpr(def_id, hir_id, idx)
|
||||
| ObligationCauseCode::WhereInExpr(def_id, _, hir_id, idx)) =
|
||||
*error.obligation.cause.code().peel_derives()
|
||||
else {
|
||||
return false;
|
||||
|
@ -167,7 +167,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
// the method's turbofish segments but still use `FunctionArgumentObligation`
|
||||
// elsewhere. Hopefully this doesn't break something.
|
||||
error.obligation.cause.map_code(|parent_code| {
|
||||
ObligationCauseCode::FunctionArgumentObligation {
|
||||
ObligationCauseCode::FunctionArg {
|
||||
arg_hir_id: receiver.hir_id,
|
||||
call_hir_id: hir_id,
|
||||
parent_code,
|
||||
|
@ -456,12 +456,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
self.blame_specific_expr_if_possible(error, arg_expr)
|
||||
}
|
||||
|
||||
error.obligation.cause.map_code(|parent_code| {
|
||||
ObligationCauseCode::FunctionArgumentObligation {
|
||||
arg_hir_id: arg.hir_id,
|
||||
call_hir_id,
|
||||
parent_code,
|
||||
}
|
||||
error.obligation.cause.map_code(|parent_code| ObligationCauseCode::FunctionArg {
|
||||
arg_hir_id: arg.hir_id,
|
||||
call_hir_id,
|
||||
parent_code,
|
||||
});
|
||||
return true;
|
||||
} else if args_referencing_param.len() > 0 {
|
||||
|
@ -514,12 +512,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
expr: &'tcx hir::Expr<'tcx>,
|
||||
) -> Result<&'tcx hir::Expr<'tcx>, &'tcx hir::Expr<'tcx>> {
|
||||
match obligation_cause_code {
|
||||
traits::ObligationCauseCode::ExprBindingObligation(_, _, _, _) => {
|
||||
traits::ObligationCauseCode::WhereInExpr(_, _, _, _) => {
|
||||
// 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.
|
||||
Ok(expr)
|
||||
}
|
||||
traits::ObligationCauseCode::ImplDerivedObligation(impl_derived) => self
|
||||
traits::ObligationCauseCode::ImplDerived(impl_derived) => self
|
||||
.blame_specific_expr_if_possible_for_derived_predicate_obligation(
|
||||
impl_derived,
|
||||
expr,
|
||||
|
|
|
@ -206,7 +206,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
self.register_wf_obligation(
|
||||
fn_input_ty.into(),
|
||||
arg_expr.span,
|
||||
ObligationCauseCode::MiscObligation,
|
||||
ObligationCauseCode::Misc,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
}
|
||||
|
||||
pub fn misc(&self, span: Span) -> ObligationCause<'tcx> {
|
||||
self.cause(span, ObligationCauseCode::MiscObligation)
|
||||
self.cause(span, ObligationCauseCode::Misc)
|
||||
}
|
||||
|
||||
pub fn sess(&self) -> &Session {
|
||||
|
|
|
@ -565,14 +565,9 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
|
|||
for obligation in traits::predicates_for_generics(
|
||||
|idx, span| {
|
||||
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 {
|
||||
ObligationCauseCode::ExprBindingObligation(
|
||||
def_id,
|
||||
span,
|
||||
self.call_expr.hir_id,
|
||||
idx,
|
||||
)
|
||||
ObligationCauseCode::WhereInExpr(def_id, span, self.call_expr.hir_id, idx)
|
||||
};
|
||||
traits::ObligationCause::new(self.span, self.body_id, code)
|
||||
},
|
||||
|
|
|
@ -1402,13 +1402,13 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
|||
ocx.register_obligations(traits::predicates_for_generics(
|
||||
|idx, span| {
|
||||
let code = if span.is_dummy() {
|
||||
ObligationCauseCode::ExprItemObligation(
|
||||
ObligationCauseCode::MiscItemInExpr(
|
||||
impl_def_id,
|
||||
self.scope_expr_id,
|
||||
idx,
|
||||
)
|
||||
} else {
|
||||
ObligationCauseCode::ExprBindingObligation(
|
||||
ObligationCauseCode::WhereInExpr(
|
||||
impl_def_id,
|
||||
span,
|
||||
self.scope_expr_id,
|
||||
|
|
|
@ -146,7 +146,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
return false;
|
||||
};
|
||||
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);
|
||||
if !self.predicate_must_hold_modulo_regions(&obligation) {
|
||||
return false;
|
||||
|
@ -826,12 +826,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
// Extract the predicate span and parent def id of the cause,
|
||||
// if we have one.
|
||||
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)
|
||||
}
|
||||
Some(
|
||||
ObligationCauseCode::ExprBindingObligation(def_id, span, _, _)
|
||||
| ObligationCauseCode::BindingObligation(def_id, span),
|
||||
ObligationCauseCode::WhereInExpr(def_id, span, _, _)
|
||||
| ObligationCauseCode::Where(def_id, span),
|
||||
) => (*def_id, *span),
|
||||
_ => continue,
|
||||
};
|
||||
|
|
|
@ -883,9 +883,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
err.help("...or use `match` instead of `let...else`");
|
||||
}
|
||||
_ => {
|
||||
if let ObligationCauseCode::BindingObligation(_, span)
|
||||
| ObligationCauseCode::ExprBindingObligation(_, span, ..) =
|
||||
cause.code().peel_derives()
|
||||
if let ObligationCauseCode::Where(_, span)
|
||||
| ObligationCauseCode::WhereInExpr(_, span, ..) = cause.code().peel_derives()
|
||||
&& let TypeError::RegionsPlaceholderMismatch = terr
|
||||
{
|
||||
err.span_note(*span, "the lifetime requirement is introduced here");
|
||||
|
@ -2776,7 +2775,7 @@ impl<'tcx> ObligationCause<'tcx> {
|
|||
match self.code() {
|
||||
ObligationCauseCode::IfExpressionWithNoElse => FailureCode::Error0317,
|
||||
ObligationCauseCode::MainFunctionType => FailureCode::Error0580,
|
||||
ObligationCauseCode::CompareImplItemObligation { .. }
|
||||
ObligationCauseCode::CompareImplItem { .. }
|
||||
| ObligationCauseCode::MatchExpressionArm(_)
|
||||
| ObligationCauseCode::IfExpression { .. }
|
||||
| ObligationCauseCode::LetElse
|
||||
|
@ -2806,15 +2805,15 @@ impl<'tcx> ObligationCause<'tcx> {
|
|||
subdiags: Vec<TypeErrorAdditionalDiags>,
|
||||
) -> ObligationCauseFailureCode {
|
||||
match self.code() {
|
||||
ObligationCauseCode::CompareImplItemObligation { kind: ty::AssocKind::Fn, .. } => {
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Fn, .. } => {
|
||||
ObligationCauseFailureCode::MethodCompat { span, subdiags }
|
||||
}
|
||||
ObligationCauseCode::CompareImplItemObligation {
|
||||
kind: ty::AssocKind::Type, ..
|
||||
} => ObligationCauseFailureCode::TypeCompat { span, subdiags },
|
||||
ObligationCauseCode::CompareImplItemObligation {
|
||||
kind: ty::AssocKind::Const, ..
|
||||
} => ObligationCauseFailureCode::ConstCompat { span, subdiags },
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Type, .. } => {
|
||||
ObligationCauseFailureCode::TypeCompat { span, subdiags }
|
||||
}
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Const, .. } => {
|
||||
ObligationCauseFailureCode::ConstCompat { span, subdiags }
|
||||
}
|
||||
ObligationCauseCode::BlockTailExpression(.., hir::MatchSource::TryDesugar(_)) => {
|
||||
ObligationCauseFailureCode::TryCompat { span, subdiags }
|
||||
}
|
||||
|
@ -2870,15 +2869,15 @@ impl<'tcx> ObligationCause<'tcx> {
|
|||
|
||||
fn as_requirement_str(&self) -> &'static str {
|
||||
match self.code() {
|
||||
ObligationCauseCode::CompareImplItemObligation { kind: ty::AssocKind::Fn, .. } => {
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Fn, .. } => {
|
||||
"method type is compatible with trait"
|
||||
}
|
||||
ObligationCauseCode::CompareImplItemObligation {
|
||||
kind: ty::AssocKind::Type, ..
|
||||
} => "associated type is compatible with trait",
|
||||
ObligationCauseCode::CompareImplItemObligation {
|
||||
kind: ty::AssocKind::Const, ..
|
||||
} => "const is compatible with trait",
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Type, .. } => {
|
||||
"associated type is compatible with trait"
|
||||
}
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Const, .. } => {
|
||||
"const is compatible with trait"
|
||||
}
|
||||
ObligationCauseCode::MainFunctionType => "`main` function has the correct type",
|
||||
ObligationCauseCode::StartFunctionType => "`#[start]` 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<'_> {
|
||||
fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
|
||||
let kind = match self.0.code() {
|
||||
ObligationCauseCode::CompareImplItemObligation { kind: ty::AssocKind::Fn, .. } => {
|
||||
"method_compat"
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Fn, .. } => "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::StartFunctionType => "fn_start_correct_type",
|
||||
ObligationCauseCode::LangFunctionType(_) => "fn_lang_correct_type",
|
||||
|
|
|
@ -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
|
||||
// about the original obligation only.
|
||||
let code = match cause.code() {
|
||||
ObligationCauseCode::FunctionArgumentObligation { parent_code, .. } => &*parent_code,
|
||||
ObligationCauseCode::FunctionArg { parent_code, .. } => &*parent_code,
|
||||
code => code,
|
||||
};
|
||||
let ObligationCauseCode::MatchImpl(parent, impl_def_id) = code else {
|
||||
return None;
|
||||
};
|
||||
let (ObligationCauseCode::BindingObligation(_, binding_span)
|
||||
| ObligationCauseCode::ExprBindingObligation(_, binding_span, ..)) = *parent.code()
|
||||
let (ObligationCauseCode::Where(_, binding_span)
|
||||
| ObligationCauseCode::WhereInExpr(_, binding_span, ..)) = *parent.code()
|
||||
else {
|
||||
return None;
|
||||
};
|
||||
|
|
|
@ -240,8 +240,8 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
|||
let span = cause.span();
|
||||
|
||||
let (leading_ellipsis, satisfy_span, where_span, dup_span, def_id) =
|
||||
if let ObligationCauseCode::ItemObligation(def_id)
|
||||
| ObligationCauseCode::ExprItemObligation(def_id, ..) = *cause.code()
|
||||
if let ObligationCauseCode::MiscItem(def_id)
|
||||
| ObligationCauseCode::MiscItemInExpr(def_id, ..) = *cause.code()
|
||||
{
|
||||
(
|
||||
true,
|
||||
|
|
|
@ -214,8 +214,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
_ => cause.code(),
|
||||
}
|
||||
&& let (
|
||||
&ObligationCauseCode::ItemObligation(item_def_id)
|
||||
| &ObligationCauseCode::ExprItemObligation(item_def_id, ..),
|
||||
&ObligationCauseCode::MiscItem(item_def_id)
|
||||
| &ObligationCauseCode::MiscItemInExpr(item_def_id, ..),
|
||||
None,
|
||||
) = (code, override_error_code)
|
||||
{
|
||||
|
|
|
@ -357,13 +357,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
infer::Subtype(box ref trace)
|
||||
if matches!(
|
||||
&trace.cause.code().peel_derives(),
|
||||
ObligationCauseCode::BindingObligation(..)
|
||||
| ObligationCauseCode::ExprBindingObligation(..)
|
||||
ObligationCauseCode::Where(..) | ObligationCauseCode::WhereInExpr(..)
|
||||
) =>
|
||||
{
|
||||
// Hack to get around the borrow checker because trace.cause has an `Rc`.
|
||||
if let ObligationCauseCode::BindingObligation(_, span)
|
||||
| ObligationCauseCode::ExprBindingObligation(_, span, ..) =
|
||||
if let ObligationCauseCode::Where(_, span)
|
||||
| ObligationCauseCode::WhereInExpr(_, span, ..) =
|
||||
&trace.cause.code().peel_derives()
|
||||
{
|
||||
let span = *span;
|
||||
|
|
|
@ -629,8 +629,7 @@ impl<T> Trait<T> for X {
|
|||
| hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }),
|
||||
)
|
||||
);
|
||||
let impl_comparison =
|
||||
matches!(cause_code, ObligationCauseCode::CompareImplItemObligation { .. });
|
||||
let impl_comparison = matches!(cause_code, ObligationCauseCode::CompareImplItem { .. });
|
||||
let assoc = tcx.associated_item(proj_ty.def_id);
|
||||
if impl_comparison {
|
||||
// We do not want to suggest calling functions when the reason of the
|
||||
|
|
|
@ -167,7 +167,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
exp_span, exp_found.expected, exp_found.found,
|
||||
);
|
||||
|
||||
if let ObligationCauseCode::CompareImplItemObligation { .. } = cause.code() {
|
||||
if let ObligationCauseCode::CompareImplItem { .. } = cause.code() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1876,7 +1876,7 @@ impl<'tcx> SubregionOrigin<'tcx> {
|
|||
SubregionOrigin::ReferenceOutlivesReferent(ref_type, cause.span)
|
||||
}
|
||||
|
||||
traits::ObligationCauseCode::CompareImplItemObligation {
|
||||
traits::ObligationCauseCode::CompareImplItem {
|
||||
impl_item_def_id,
|
||||
trait_item_def_id,
|
||||
kind: _,
|
||||
|
|
|
@ -103,8 +103,8 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
cause.span,
|
||||
sup_type,
|
||||
match cause.code().peel_derives() {
|
||||
ObligationCauseCode::BindingObligation(_, span)
|
||||
| ObligationCauseCode::ExprBindingObligation(_, span, ..) => Some(*span),
|
||||
ObligationCauseCode::Where(_, span)
|
||||
| ObligationCauseCode::WhereInExpr(_, span, ..) => Some(*span),
|
||||
_ => None,
|
||||
},
|
||||
)
|
||||
|
|
|
@ -129,14 +129,12 @@ impl<'tcx> Elaboratable<'tcx> for PredicateObligation<'tcx> {
|
|||
index: usize,
|
||||
) -> Self {
|
||||
let cause = self.cause.clone().derived_cause(parent_trait_pred, |derived| {
|
||||
ObligationCauseCode::ImplDerivedObligation(Box::new(
|
||||
traits::ImplDerivedObligationCause {
|
||||
derived,
|
||||
impl_or_alias_def_id: parent_trait_pred.def_id(),
|
||||
impl_def_predicate_index: Some(index),
|
||||
span,
|
||||
},
|
||||
))
|
||||
ObligationCauseCode::ImplDerived(Box::new(traits::ImplDerivedObligationCause {
|
||||
derived,
|
||||
impl_or_alias_def_id: parent_trait_pred.def_id(),
|
||||
impl_def_predicate_index: Some(index),
|
||||
span,
|
||||
}))
|
||||
});
|
||||
Obligation {
|
||||
cause,
|
||||
|
|
|
@ -150,11 +150,8 @@ fn suggest_question_mark<'tcx>(
|
|||
let ocx = ObligationCtxt::new(&infcx);
|
||||
|
||||
let body_def_id = cx.tcx.hir().body_owner_def_id(body_id);
|
||||
let cause = ObligationCause::new(
|
||||
span,
|
||||
body_def_id,
|
||||
rustc_infer::traits::ObligationCauseCode::MiscObligation,
|
||||
);
|
||||
let cause =
|
||||
ObligationCause::new(span, body_def_id, rustc_infer::traits::ObligationCauseCode::Misc);
|
||||
|
||||
ocx.register_bound(
|
||||
cause,
|
||||
|
|
|
@ -127,7 +127,7 @@ impl<'tcx> 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)]
|
||||
|
@ -207,7 +207,7 @@ pub struct UnifyReceiverContext<'tcx> {
|
|||
#[derive(Clone, PartialEq, Eq, Default, HashStable)]
|
||||
#[derive(TypeVisitable, TypeFoldable, TyEncodable, TyDecodable)]
|
||||
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.
|
||||
code: Option<Lrc<ObligationCauseCode<'tcx>>>,
|
||||
}
|
||||
|
@ -223,11 +223,7 @@ impl<'tcx> ObligationCauseCode<'tcx> {
|
|||
#[inline(always)]
|
||||
fn into(self) -> InternedObligationCauseCode<'tcx> {
|
||||
InternedObligationCauseCode {
|
||||
code: if let ObligationCauseCode::MiscObligation = self {
|
||||
None
|
||||
} else {
|
||||
Some(Lrc::new(self))
|
||||
},
|
||||
code: if let ObligationCauseCode::Misc = self { None } else { Some(Lrc::new(self)) },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -236,7 +232,7 @@ impl<'tcx> std::ops::Deref for InternedObligationCauseCode<'tcx> {
|
|||
type Target = ObligationCauseCode<'tcx>;
|
||||
|
||||
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)]
|
||||
pub enum ObligationCauseCode<'tcx> {
|
||||
/// Not well classified or should be obvious from the span.
|
||||
MiscObligation,
|
||||
Misc,
|
||||
|
||||
/// A slice or array is WF only if `T: Sized`.
|
||||
SliceOrArrayElem,
|
||||
|
@ -254,20 +250,20 @@ pub enum ObligationCauseCode<'tcx> {
|
|||
|
||||
/// Must satisfy all of the where-clause predicates of the
|
||||
/// 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.
|
||||
BindingObligation(DefId, Span),
|
||||
Where(DefId, Span),
|
||||
|
||||
/// Like `ItemObligation`, but carries the `HirId` of the
|
||||
/// expression that caused the obligation, and the `usize`
|
||||
/// indicates exactly which predicate it is in the list of
|
||||
/// instantiated predicates.
|
||||
ExprItemObligation(DefId, HirId, usize),
|
||||
MiscItemInExpr(DefId, HirId, usize),
|
||||
|
||||
/// 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`.
|
||||
ReferenceOutlivesReferent(Ty<'tcx>),
|
||||
|
@ -331,14 +327,14 @@ pub enum ObligationCauseCode<'tcx> {
|
|||
|
||||
/// Derived obligation (i.e. theoretical `where` clause) on a built-in
|
||||
/// implementation like `Copy` or `Sized`.
|
||||
BuiltinDerivedObligation(DerivedObligationCause<'tcx>),
|
||||
BuiltinDerived(DerivedObligationCause<'tcx>),
|
||||
|
||||
/// Derived obligation (i.e. `where` clause) on an user-provided impl
|
||||
/// or a trait alias.
|
||||
ImplDerivedObligation(Box<ImplDerivedObligationCause<'tcx>>),
|
||||
ImplDerived(Box<ImplDerivedObligationCause<'tcx>>),
|
||||
|
||||
/// Derived obligation for WF goals.
|
||||
WellFormedDerivedObligation(DerivedObligationCause<'tcx>),
|
||||
WellFormedDerived(DerivedObligationCause<'tcx>),
|
||||
|
||||
FunctionArgumentObligation {
|
||||
/// 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
|
||||
/// after an error occurs, in order to generate a more precise error span.
|
||||
/// This is purely for diagnostic purposes - it is always
|
||||
/// correct to use `MiscObligation` instead, or to specify
|
||||
/// `WellFormed(None)`
|
||||
/// correct to use `Misc` instead, or to specify
|
||||
/// `WellFormed(None)`.
|
||||
WellFormed(Option<WellFormedLoc>),
|
||||
|
||||
/// 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>>)> {
|
||||
match self {
|
||||
ObligationCauseCode::FunctionArgumentObligation { parent_code, .. } => {
|
||||
Some((parent_code, None))
|
||||
}
|
||||
ObligationCauseCode::BuiltinDerivedObligation(derived)
|
||||
| ObligationCauseCode::WellFormedDerivedObligation(derived)
|
||||
| ObligationCauseCode::ImplDerivedObligation(box ImplDerivedObligationCause {
|
||||
derived,
|
||||
..
|
||||
ObligationCauseCode::FunctionArg { parent_code, .. } => Some((parent_code, None)),
|
||||
ObligationCauseCode::BuiltinDerived(derived)
|
||||
| ObligationCauseCode::WellFormedDerived(derived)
|
||||
| ObligationCauseCode::ImplDerived(box ImplDerivedObligationCause {
|
||||
derived, ..
|
||||
}) => Some((&derived.parent_code, Some(derived.parent_trait_pred))),
|
||||
_ => None,
|
||||
}
|
||||
|
|
|
@ -425,14 +425,12 @@ fn derive_cause<'tcx>(
|
|||
tcx.predicates_of(impl_def_id).instantiate_identity(tcx).iter().nth(idx)
|
||||
{
|
||||
cause = cause.derived_cause(parent_trait_pred, |derived| {
|
||||
ObligationCauseCode::ImplDerivedObligation(Box::new(
|
||||
traits::ImplDerivedObligationCause {
|
||||
derived,
|
||||
impl_or_alias_def_id: impl_def_id,
|
||||
impl_def_predicate_index: Some(idx),
|
||||
span,
|
||||
},
|
||||
))
|
||||
ObligationCauseCode::ImplDerived(Box::new(traits::ImplDerivedObligationCause {
|
||||
derived,
|
||||
impl_or_alias_def_id: impl_def_id,
|
||||
impl_def_predicate_index: Some(idx),
|
||||
span,
|
||||
}))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -127,9 +127,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
flags.push((sym::ItemContext, enclosure));
|
||||
|
||||
match obligation.cause.code() {
|
||||
ObligationCauseCode::BuiltinDerivedObligation(..)
|
||||
| ObligationCauseCode::ImplDerivedObligation(..)
|
||||
| ObligationCauseCode::WellFormedDerivedObligation(..) => {}
|
||||
ObligationCauseCode::BuiltinDerived(..)
|
||||
| ObligationCauseCode::ImplDerived(..)
|
||||
| ObligationCauseCode::WellFormedDerived(..) => {}
|
||||
_ => {
|
||||
// this is a "direct", user-specified, rather than derived,
|
||||
// obligation.
|
||||
|
|
|
@ -455,8 +455,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||
) -> bool {
|
||||
let mut code = obligation.cause.code();
|
||||
if let ObligationCauseCode::FunctionArgumentObligation { arg_hir_id, call_hir_id, .. } =
|
||||
code
|
||||
if let ObligationCauseCode::FunctionArg { arg_hir_id, call_hir_id, .. } = code
|
||||
&& let Some(typeck_results) = &self.typeck_results
|
||||
&& let hir::Node::Expr(expr) = self.tcx.hir_node(*arg_hir_id)
|
||||
&& let Some(arg_ty) = typeck_results.expr_ty_adjusted_opt(expr)
|
||||
|
@ -846,7 +845,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
|
||||
if matches!(obligation.cause.code(), ObligationCauseCode::FunctionArgumentObligation { .. })
|
||||
if matches!(obligation.cause.code(), ObligationCauseCode::FunctionArg { .. })
|
||||
&& obligation.cause.span.can_be_used_for_suggestions()
|
||||
{
|
||||
// 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::Param(param) = inner_ty.kind() else { return false };
|
||||
let ObligationCauseCode::FunctionArgumentObligation { arg_hir_id, .. } =
|
||||
obligation.cause.code()
|
||||
let ObligationCauseCode::FunctionArg { arg_hir_id, .. } = obligation.cause.code()
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
|
@ -1204,9 +1202,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
let span = obligation.cause.span;
|
||||
|
||||
let code = match obligation.cause.code() {
|
||||
ObligationCauseCode::FunctionArgumentObligation { parent_code, .. } => parent_code,
|
||||
c @ ObligationCauseCode::ItemObligation(_)
|
||||
| c @ ObligationCauseCode::ExprItemObligation(..) => c,
|
||||
ObligationCauseCode::FunctionArg { parent_code, .. } => parent_code,
|
||||
c @ ObligationCauseCode::MiscItem(_) | c @ ObligationCauseCode::MiscItemInExpr(..) => c,
|
||||
c if matches!(
|
||||
span.ctxt().outer_expn_data().kind,
|
||||
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 (ref_inner_ty_satisfies_pred, ref_inner_ty_mut) =
|
||||
if let ObligationCauseCode::ItemObligation(_)
|
||||
| ObligationCauseCode::ExprItemObligation(..) = obligation.cause.code()
|
||||
if let ObligationCauseCode::MiscItem(_) | ObligationCauseCode::MiscItemInExpr(..) =
|
||||
obligation.cause.code()
|
||||
&& let ty::Ref(_, ty, mutability) = old_pred.self_ty().skip_binder().kind()
|
||||
{
|
||||
(
|
||||
|
@ -1401,12 +1398,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
return false;
|
||||
};
|
||||
|
||||
if let ObligationCauseCode::ImplDerivedObligation(cause) = &*code {
|
||||
if let ObligationCauseCode::ImplDerived(cause) = &*code {
|
||||
try_borrowing(cause.derived.parent_trait_pred, &[])
|
||||
} else if let ObligationCauseCode::BindingObligation(_, _)
|
||||
| ObligationCauseCode::ItemObligation(_)
|
||||
| ObligationCauseCode::ExprItemObligation(..)
|
||||
| ObligationCauseCode::ExprBindingObligation(..) = code
|
||||
} else if let ObligationCauseCode::Where(_, _)
|
||||
| ObligationCauseCode::MiscItem(_)
|
||||
| ObligationCauseCode::MiscItemInExpr(..)
|
||||
| ObligationCauseCode::WhereInExpr(..) = code
|
||||
{
|
||||
try_borrowing(poly_trait_pred, &never_suggest_borrow)
|
||||
} else {
|
||||
|
@ -1644,10 +1641,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
err: &mut Diag<'_>,
|
||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||
) {
|
||||
let points_at_arg = matches!(
|
||||
obligation.cause.code(),
|
||||
ObligationCauseCode::FunctionArgumentObligation { .. },
|
||||
);
|
||||
let points_at_arg =
|
||||
matches!(obligation.cause.code(), ObligationCauseCode::FunctionArg { .. },);
|
||||
|
||||
let span = obligation.cause.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>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
) {
|
||||
let ObligationCauseCode::FunctionArgumentObligation { arg_hir_id, .. } = cause else {
|
||||
let ObligationCauseCode::FunctionArg { arg_hir_id, .. } = cause else {
|
||||
return;
|
||||
};
|
||||
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
|
||||
// the uninstantiated predicate list of the called function. And check
|
||||
// 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 Some(pred) = predicates.predicates.get(*idx)
|
||||
&& let ty::ClauseKind::Trait(trait_pred) = pred.kind().skip_binder()
|
||||
|
@ -2261,10 +2256,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
while let Some(code) = next_code {
|
||||
debug!(?code);
|
||||
match code {
|
||||
ObligationCauseCode::FunctionArgumentObligation { parent_code, .. } => {
|
||||
ObligationCauseCode::FunctionArg { parent_code, .. } => {
|
||||
next_code = Some(parent_code);
|
||||
}
|
||||
ObligationCauseCode::ImplDerivedObligation(cause) => {
|
||||
ObligationCauseCode::ImplDerived(cause) => {
|
||||
let ty = cause.derived.parent_trait_pred.skip_binder().self_ty();
|
||||
debug!(
|
||||
parent_trait_ref = ?cause.derived.parent_trait_pred,
|
||||
|
@ -2293,8 +2288,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
|
||||
next_code = Some(&cause.derived.parent_code);
|
||||
}
|
||||
ObligationCauseCode::WellFormedDerivedObligation(derived_obligation)
|
||||
| ObligationCauseCode::BuiltinDerivedObligation(derived_obligation) => {
|
||||
ObligationCauseCode::WellFormedDerived(derived_obligation)
|
||||
| ObligationCauseCode::BuiltinDerived(derived_obligation) => {
|
||||
let ty = derived_obligation.parent_trait_pred.skip_binder().self_ty();
|
||||
debug!(
|
||||
parent_trait_ref = ?derived_obligation.parent_trait_pred,
|
||||
|
@ -2719,7 +2714,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
| ObligationCauseCode::MethodReceiver
|
||||
| ObligationCauseCode::ReturnNoExpression
|
||||
| ObligationCauseCode::UnifyReceiver(..)
|
||||
| ObligationCauseCode::MiscObligation
|
||||
| ObligationCauseCode::Misc
|
||||
| ObligationCauseCode::WellFormed(..)
|
||||
| ObligationCauseCode::MatchImpl(..)
|
||||
| ObligationCauseCode::ReturnValue(_)
|
||||
|
@ -2748,13 +2743,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
ObligationCauseCode::TupleElem => {
|
||||
err.note("only the last element of a tuple may have a dynamically sized type");
|
||||
}
|
||||
ObligationCauseCode::ItemObligation(_)
|
||||
| ObligationCauseCode::ExprItemObligation(..) => {
|
||||
ObligationCauseCode::MiscItem(_) | ObligationCauseCode::MiscItemInExpr(..) => {
|
||||
// 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.
|
||||
}
|
||||
ObligationCauseCode::BindingObligation(item_def_id, span)
|
||||
| ObligationCauseCode::ExprBindingObligation(item_def_id, span, ..) => {
|
||||
ObligationCauseCode::Where(item_def_id, span)
|
||||
| ObligationCauseCode::WhereInExpr(item_def_id, span, ..) => {
|
||||
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 mut multispan = MultiSpan::from(span);
|
||||
|
@ -3175,7 +3169,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
ObligationCauseCode::SharedStatic => {
|
||||
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 ty = parent_trait_ref.skip_binder().self_ty();
|
||||
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(..)) {
|
||||
false
|
||||
} else {
|
||||
if let ObligationCauseCode::BuiltinDerivedObligation(data) = &*data.parent_code
|
||||
{
|
||||
if let ObligationCauseCode::BuiltinDerived(data) = &*data.parent_code {
|
||||
let parent_trait_ref =
|
||||
self.resolve_vars_if_possible(data.parent_trait_pred);
|
||||
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 =
|
||||
self.resolve_vars_if_possible(data.derived.parent_trait_pred);
|
||||
let parent_def_id = parent_trait_pred.def_id();
|
||||
|
@ -3367,9 +3360,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
if is_auto_trait {
|
||||
// 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`.
|
||||
while let ObligationCauseCode::BuiltinDerivedObligation(derived) =
|
||||
&*data.parent_code
|
||||
{
|
||||
while let ObligationCauseCode::BuiltinDerived(derived) = &*data.parent_code {
|
||||
let child_trait_ref =
|
||||
self.resolve_vars_if_possible(derived.parent_trait_pred);
|
||||
let child_def_id = child_trait_ref.def_id();
|
||||
|
@ -3381,7 +3372,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
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`.
|
||||
let child_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_predicate = parent_trait_ref;
|
||||
// #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)),
|
||||
);
|
||||
}
|
||||
ObligationCauseCode::FunctionArgumentObligation {
|
||||
arg_hir_id,
|
||||
call_hir_id,
|
||||
ref parent_code,
|
||||
..
|
||||
ObligationCauseCode::FunctionArg {
|
||||
arg_hir_id, call_hir_id, ref parent_code, ..
|
||||
} => {
|
||||
self.note_function_argument_obligation(
|
||||
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 msg = format!(
|
||||
"the requirement `{predicate}` appears on the `impl`'s {kind} \
|
||||
|
@ -3694,7 +3682,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
err: &mut Diag<'_>,
|
||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||
) {
|
||||
if let ObligationCauseCode::ImplDerivedObligation(_) = obligation.cause.code()
|
||||
if let ObligationCauseCode::ImplDerived(_) = obligation.cause.code()
|
||||
&& self
|
||||
.tcx
|
||||
.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
|
||||
// trait_pred `S: Sum<<Self as Iterator>::Item>` and predicate `i32: Sum<&()>`
|
||||
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 where_clauses =
|
||||
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,
|
||||
// since the suggestion would make no sense in turbofish or call
|
||||
let (ObligationCauseCode::BinOp { .. }
|
||||
| ObligationCauseCode::FunctionArgumentObligation { .. }) = obligation.cause.code()
|
||||
let (ObligationCauseCode::BinOp { .. } | ObligationCauseCode::FunctionArg { .. }) =
|
||||
obligation.cause.code()
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
@ -4407,7 +4395,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
return;
|
||||
}
|
||||
|
||||
if let ObligationCauseCode::FunctionArgumentObligation {
|
||||
if let ObligationCauseCode::FunctionArg {
|
||||
call_hir_id,
|
||||
arg_hir_id,
|
||||
parent_code: _,
|
||||
|
|
|
@ -391,7 +391,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
if let ObligationCauseCode::CompareImplItemObligation {
|
||||
if let ObligationCauseCode::CompareImplItem {
|
||||
impl_item_def_id,
|
||||
trait_item_def_id,
|
||||
kind: _,
|
||||
|
@ -1017,7 +1017,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
if let Some((_, Some(parent))) = obligation.cause.code().parent() {
|
||||
// If we have a derived obligation, then the parent will be a `AsyncFn*` goal.
|
||||
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()
|
||||
&& let Some(typeck_results) = &self.typeck_results
|
||||
&& let ty::Closure(closure_def_id, _) | ty::CoroutineClosure(closure_def_id, _) =
|
||||
|
@ -1104,8 +1104,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
) -> Result<(), ErrorGuaranteed> {
|
||||
if let ObligationCauseCode::FunctionArgumentObligation { arg_hir_id, .. } =
|
||||
obligation.cause.code()
|
||||
if let ObligationCauseCode::FunctionArg { arg_hir_id, .. } = obligation.cause.code()
|
||||
&& let Node::Expr(arg) = self.tcx.hir_node(*arg_hir_id)
|
||||
&& let arg = arg.peel_borrows()
|
||||
&& let hir::ExprKind::Path(hir::QPath::Resolved(
|
||||
|
@ -1534,10 +1533,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
*err,
|
||||
);
|
||||
let code = error.obligation.cause.code().peel_derives().peel_match_impls();
|
||||
if let ObligationCauseCode::BindingObligation(..)
|
||||
| ObligationCauseCode::ItemObligation(..)
|
||||
| ObligationCauseCode::ExprBindingObligation(..)
|
||||
| ObligationCauseCode::ExprItemObligation(..) = code
|
||||
if let ObligationCauseCode::Where(..)
|
||||
| ObligationCauseCode::MiscItem(..)
|
||||
| ObligationCauseCode::WhereInExpr(..)
|
||||
| ObligationCauseCode::MiscItemInExpr(..) = code
|
||||
{
|
||||
self.note_obligation_cause_code(
|
||||
error.obligation.cause.body_id,
|
||||
|
@ -1611,10 +1610,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
|
||||
let is_normalized_term_expected = !matches!(
|
||||
obligation.cause.code().peel_derives(),
|
||||
ObligationCauseCode::ItemObligation(_)
|
||||
| ObligationCauseCode::BindingObligation(_, _)
|
||||
| ObligationCauseCode::ExprItemObligation(..)
|
||||
| ObligationCauseCode::ExprBindingObligation(..)
|
||||
ObligationCauseCode::MiscItem(_)
|
||||
| ObligationCauseCode::Where(_, _)
|
||||
| ObligationCauseCode::MiscItemInExpr(..)
|
||||
| ObligationCauseCode::WhereInExpr(..)
|
||||
| ObligationCauseCode::Coercion { .. }
|
||||
);
|
||||
|
||||
|
@ -2211,7 +2210,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
code: &ObligationCauseCode<'tcx>,
|
||||
) -> Option<(Ty<'tcx>, Option<Span>)> {
|
||||
match code {
|
||||
ObligationCauseCode::BuiltinDerivedObligation(data) => {
|
||||
ObligationCauseCode::BuiltinDerived(data) => {
|
||||
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_pred);
|
||||
match self.get_parent_trait_ref(&data.parent_code) {
|
||||
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)
|
||||
}
|
||||
_ => None,
|
||||
|
@ -2446,8 +2445,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
if let ObligationCauseCode::ItemObligation(def_id)
|
||||
| ObligationCauseCode::ExprItemObligation(def_id, ..) = *obligation.cause.code()
|
||||
if let ObligationCauseCode::MiscItem(def_id)
|
||||
| ObligationCauseCode::MiscItemInExpr(def_id, ..) = *obligation.cause.code()
|
||||
{
|
||||
self.suggest_fully_qualified_path(&mut err, def_id, span, trait_ref.def_id());
|
||||
}
|
||||
|
@ -2882,8 +2881,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
else {
|
||||
return;
|
||||
};
|
||||
let (ObligationCauseCode::BindingObligation(item_def_id, span)
|
||||
| ObligationCauseCode::ExprBindingObligation(item_def_id, span, ..)) =
|
||||
let (ObligationCauseCode::Where(item_def_id, span)
|
||||
| ObligationCauseCode::WhereInExpr(item_def_id, span, ..)) =
|
||||
*obligation.cause.code().peel_derives()
|
||||
else {
|
||||
return;
|
||||
|
@ -3003,7 +3002,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
obligated_types: &mut Vec<Ty<'tcx>>,
|
||||
cause_code: &ObligationCauseCode<'tcx>,
|
||||
) -> 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 self_ty = parent_trait_ref.skip_binder().self_ty();
|
||||
if obligated_types.iter().any(|ot| ot == &self_ty) {
|
||||
|
@ -3180,8 +3179,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
ObligationCauseCode::RustCall => {
|
||||
err.primary_message("functions with the \"rust-call\" ABI must take a single non-self tuple argument");
|
||||
}
|
||||
ObligationCauseCode::BindingObligation(def_id, _)
|
||||
| ObligationCauseCode::ItemObligation(def_id)
|
||||
ObligationCauseCode::Where(def_id, _) | ObligationCauseCode::MiscItem(def_id)
|
||||
if self.tcx.is_fn_trait(*def_id) =>
|
||||
{
|
||||
err.code(E0059);
|
||||
|
@ -3570,7 +3568,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
match self.tcx.sess.source_map().span_to_snippet(const_span) {
|
||||
Ok(snippet) => {
|
||||
let code = format!("[(); {snippet}{cast}]:");
|
||||
let def_id = if let ObligationCauseCode::CompareImplItemObligation {
|
||||
let def_id = if let ObligationCauseCode::CompareImplItem {
|
||||
trait_item_def_id,
|
||||
..
|
||||
} = obligation.cause.code()
|
||||
|
|
|
@ -574,9 +574,9 @@ pub fn normalize_inherent_projection<'a, 'b, 'tcx>(
|
|||
// diagnostics which is not ideal.
|
||||
// Consider creating separate cause codes for this specific situation.
|
||||
if span.is_dummy() {
|
||||
ObligationCauseCode::ItemObligation(alias_ty.def_id)
|
||||
ObligationCauseCode::MiscItem(alias_ty.def_id)
|
||||
} 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!(
|
||||
obligation.cause.code(),
|
||||
ObligationCauseCode::CompareImplItemObligation { .. }
|
||||
ObligationCauseCode::CompareImplItem { .. }
|
||||
| ObligationCauseCode::CheckAssociatedTypeBounds { .. }
|
||||
| ObligationCauseCode::AscribeUserTypeProvePredicate(..)
|
||||
) {
|
||||
|
@ -2123,13 +2123,13 @@ fn assoc_ty_own_obligations<'cx, 'tcx>(
|
|||
ObligationCause::new(
|
||||
obligation.cause.span,
|
||||
obligation.cause.body_id,
|
||||
ObligationCauseCode::ItemObligation(obligation.predicate.def_id),
|
||||
ObligationCauseCode::MiscItem(obligation.predicate.def_id),
|
||||
)
|
||||
} else {
|
||||
ObligationCause::new(
|
||||
obligation.cause.span,
|
||||
obligation.cause.body_id,
|
||||
ObligationCauseCode::BindingObligation(obligation.predicate.def_id, span),
|
||||
ObligationCauseCode::Where(obligation.predicate.def_id, span),
|
||||
)
|
||||
};
|
||||
nested.push(Obligation::with_depth(
|
||||
|
|
|
@ -1396,7 +1396,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
debug!(?args, "impl args");
|
||||
|
||||
let cause = obligation.derived_cause(|derived| {
|
||||
ObligationCauseCode::ImplDerivedObligation(Box::new(ImplDerivedObligationCause {
|
||||
ObligationCauseCode::ImplDerived(Box::new(ImplDerivedObligationCause {
|
||||
derived,
|
||||
impl_or_alias_def_id: impl_def_id,
|
||||
impl_def_predicate_index: None,
|
||||
|
|
|
@ -2771,14 +2771,12 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
|
|||
cause.clone()
|
||||
} else {
|
||||
cause.clone().derived_cause(parent_trait_pred, |derived| {
|
||||
ObligationCauseCode::ImplDerivedObligation(Box::new(
|
||||
ImplDerivedObligationCause {
|
||||
derived,
|
||||
impl_or_alias_def_id: def_id,
|
||||
impl_def_predicate_index: Some(index),
|
||||
span,
|
||||
},
|
||||
))
|
||||
ObligationCauseCode::ImplDerived(Box::new(ImplDerivedObligationCause {
|
||||
derived,
|
||||
impl_or_alias_def_id: def_id,
|
||||
impl_def_predicate_index: Some(index),
|
||||
span,
|
||||
}))
|
||||
})
|
||||
};
|
||||
let clause = normalize_with_depth_to(
|
||||
|
|
|
@ -566,9 +566,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
|||
iter::zip(predicates, origins.into_iter().rev())
|
||||
.map(|((pred, span), origin_def_id)| {
|
||||
let code = if span.is_dummy() {
|
||||
ObligationCauseCode::ItemObligation(origin_def_id)
|
||||
ObligationCauseCode::MiscItem(origin_def_id)
|
||||
} else {
|
||||
ObligationCauseCode::BindingObligation(origin_def_id, span)
|
||||
ObligationCauseCode::Where(origin_def_id, span)
|
||||
};
|
||||
let cause = self.cause(code);
|
||||
traits::Obligation::with_depth(
|
||||
|
@ -683,7 +683,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
|
|||
}
|
||||
|
||||
ty::Pat(subty, _) => {
|
||||
self.require_sized(subty, ObligationCauseCode::MiscObligation);
|
||||
self.require_sized(subty, ObligationCauseCode::Misc);
|
||||
}
|
||||
|
||||
ty::Tuple(tys) => {
|
||||
|
|
Loading…
Reference in New Issue