1
Fork 0

More rename fallout

This commit is contained in:
Michael Goulet 2024-05-09 20:25:11 -04:00
parent 534e267d48
commit 9108294a6c
25 changed files with 93 additions and 91 deletions

View file

@ -2059,7 +2059,7 @@ 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::Where(CRATE_DEF_ID.to_def_id(), predicate_span)) Some(ObligationCauseCode::SpannedItem(CRATE_DEF_ID.to_def_id(), predicate_span))
} else { } else {
None None
} }

View file

@ -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::Where(proj.def_id, pred_span), ObligationCauseCode::SpannedItem(proj.def_id, pred_span),
), ),
self.param_env, self.param_env,
pred, pred,
@ -2014,7 +2014,7 @@ pub(super) fn check_type_bounds<'tcx>(
let code = if span.is_dummy() { let code = if span.is_dummy() {
ObligationCauseCode::MiscItem(trait_ty.def_id) ObligationCauseCode::MiscItem(trait_ty.def_id)
} else { } else {
ObligationCauseCode::Where(trait_ty.def_id, span) ObligationCauseCode::SpannedItem(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,7 +2251,7 @@ fn try_report_async_mismatch<'tcx>(
}; };
for error in errors { for error in errors {
if let ObligationCauseCode::Where(def_id, _) = *error.root_obligation.cause.code() if let ObligationCauseCode::SpannedItem(def_id, _) = *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

@ -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::Where(impl2_node.def_id(), span), traits::ObligationCauseCode::SpannedItem(impl2_node.def_id(), span),
) )
}, },
); );

View file

@ -3083,14 +3083,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
polarity: ty::PredicatePolarity::Positive, polarity: ty::PredicatePolarity::Positive,
}), }),
|derived| { |derived| {
ObligationCauseCode::ImplDerived(Box::new( ObligationCauseCode::ImplDerived(Box::new(traits::ImplDerivedCause {
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

@ -1415,7 +1415,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if span.is_dummy() { if span.is_dummy() {
ObligationCauseCode::MiscItemInExpr(def_id, hir_id, idx) ObligationCauseCode::MiscItemInExpr(def_id, hir_id, idx)
} else { } else {
ObligationCauseCode::WhereInExpr(def_id, span, hir_id, idx) ObligationCauseCode::SpannedItemInExpr(def_id, span, hir_id, idx)
} }
}) })
} }

View file

@ -15,7 +15,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
error: &mut traits::FulfillmentError<'tcx>, error: &mut traits::FulfillmentError<'tcx>,
) -> bool { ) -> bool {
let (ObligationCauseCode::MiscItemInExpr(def_id, hir_id, idx) let (ObligationCauseCode::MiscItemInExpr(def_id, hir_id, idx)
| ObligationCauseCode::WhereInExpr(def_id, _, hir_id, idx)) = | ObligationCauseCode::SpannedItemInExpr(def_id, _, hir_id, idx)) =
*error.obligation.cause.code().peel_derives() *error.obligation.cause.code().peel_derives()
else { else {
return false; return false;
@ -512,7 +512,7 @@ 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::WhereInExpr(_, _, _, _) => { traits::ObligationCauseCode::SpannedItemInExpr(_, _, _, _) => {
// 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)
@ -555,7 +555,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// only a partial success - but it cannot be refined even further. /// only a partial success - but it cannot be refined even further.
fn blame_specific_expr_if_possible_for_derived_predicate_obligation( fn blame_specific_expr_if_possible_for_derived_predicate_obligation(
&self, &self,
obligation: &traits::ImplDerivedObligationCause<'tcx>, obligation: &traits::ImplDerivedCause<'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>> {
// First, we attempt to refine the `expr` for our span using the parent obligation. // First, we attempt to refine the `expr` for our span using the parent obligation.

View file

@ -33,7 +33,6 @@ use rustc_index::IndexVec;
use rustc_infer::infer::error_reporting::{FailureCode, ObligationCauseExt}; use rustc_infer::infer::error_reporting::{FailureCode, ObligationCauseExt};
use rustc_infer::infer::TypeTrace; use rustc_infer::infer::TypeTrace;
use rustc_infer::infer::{DefineOpaqueTypes, InferOk}; use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
use rustc_middle::traits::ObligationCauseCode::ExprBindingObligation;
use rustc_middle::ty::adjustment::AllowTwoPhase; use rustc_middle::ty::adjustment::AllowTwoPhase;
use rustc_middle::ty::visit::TypeVisitableExt; use rustc_middle::ty::visit::TypeVisitableExt;
use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt}; use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt};
@ -2014,7 +2013,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
for (span, code) in errors_causecode { for (span, code) in errors_causecode {
self.dcx().try_steal_modify_and_emit_err(span, StashKey::MaybeForgetReturn, |err| { self.dcx().try_steal_modify_and_emit_err(span, StashKey::MaybeForgetReturn, |err| {
if let Some(fn_sig) = self.body_fn_sig() if let Some(fn_sig) = self.body_fn_sig()
&& let ExprBindingObligation(_, _, binding_hir_id, ..) = code && let ObligationCauseCode::SpannedItemInExpr(_, _, binding_hir_id, ..) = code
&& !fn_sig.output().is_unit() && !fn_sig.output().is_unit()
{ {
let mut block_num = 0; let mut block_num = 0;
@ -2103,7 +2102,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// //
// This is because due to normalization, we often register duplicate // This is because due to normalization, we often register duplicate
// obligations with misc obligations that are basically impossible to // obligations with misc obligations that are basically impossible to
// line back up with a useful ExprBindingObligation. // line back up with a useful SpannedItemInExpr.
for error in not_adjusted { for error in not_adjusted {
for (span, predicate, cause) in &remap_cause { for (span, predicate, cause) in &remap_cause {
if *predicate == error.obligation.predicate if *predicate == error.obligation.predicate

View file

@ -567,7 +567,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
let code = if span.is_dummy() { let code = if span.is_dummy() {
ObligationCauseCode::MiscItemInExpr(def_id, self.call_expr.hir_id, idx) ObligationCauseCode::MiscItemInExpr(def_id, self.call_expr.hir_id, idx)
} else { } else {
ObligationCauseCode::WhereInExpr(def_id, span, self.call_expr.hir_id, idx) ObligationCauseCode::SpannedItemInExpr(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

@ -1408,7 +1408,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
idx, idx,
) )
} else { } else {
ObligationCauseCode::WhereInExpr( ObligationCauseCode::SpannedItemInExpr(
impl_def_id, impl_def_id,
span, span,
self.scope_expr_id, self.scope_expr_id,

View file

@ -830,8 +830,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
(data.impl_or_alias_def_id, data.span) (data.impl_or_alias_def_id, data.span)
} }
Some( Some(
ObligationCauseCode::WhereInExpr(def_id, span, _, _) ObligationCauseCode::SpannedItemInExpr(def_id, span, _, _)
| ObligationCauseCode::Where(def_id, span), | ObligationCauseCode::SpannedItem(def_id, span),
) => (*def_id, *span), ) => (*def_id, *span),
_ => continue, _ => continue,
}; };

View file

@ -883,8 +883,9 @@ 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::Where(_, span) if let ObligationCauseCode::SpannedItem(_, span)
| ObligationCauseCode::WhereInExpr(_, span, ..) = cause.code().peel_derives() | ObligationCauseCode::SpannedItemInExpr(_, span, ..) =
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");
@ -2011,7 +2012,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
trace: &TypeTrace<'tcx>, trace: &TypeTrace<'tcx>,
terr: TypeError<'tcx>, terr: TypeError<'tcx>,
) -> Vec<TypeErrorAdditionalDiags> { ) -> Vec<TypeErrorAdditionalDiags> {
use crate::traits::ObligationCauseCode::{BlockTailExpression, MatchExpressionArm};
let mut suggestions = Vec::new(); let mut suggestions = Vec::new();
let span = trace.cause.span(); let span = trace.cause.span();
let values = self.resolve_vars_if_possible(trace.values); let values = self.resolve_vars_if_possible(trace.values);
@ -2078,8 +2078,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
} }
} }
let code = trace.cause.code(); let code = trace.cause.code();
if let &(MatchExpressionArm(box MatchExpressionArmCause { source, .. }) if let &(ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause {
| BlockTailExpression(.., source)) = code source,
..
})
| ObligationCauseCode::BlockTailExpression(.., source)) = code
&& let hir::MatchSource::TryDesugar(_) = source && let hir::MatchSource::TryDesugar(_) = source
&& let Some((expected_ty, found_ty, _)) = self.values_str(trace.values) && let Some((expected_ty, found_ty, _)) = self.values_str(trace.values)
{ {

View file

@ -38,8 +38,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
let ObligationCauseCode::MatchImpl(parent, impl_def_id) = code else { let ObligationCauseCode::MatchImpl(parent, impl_def_id) = code else {
return None; return None;
}; };
let (ObligationCauseCode::Where(_, binding_span) let (ObligationCauseCode::SpannedItem(_, binding_span)
| ObligationCauseCode::WhereInExpr(_, binding_span, ..)) = *parent.code() | ObligationCauseCode::SpannedItemInExpr(_, binding_span, ..)) = *parent.code()
else { else {
return None; return None;
}; };

View file

@ -4,13 +4,13 @@ use crate::errors::{ConsiderBorrowingParamHelp, RelationshipHelp, TraitImplDiff}
use crate::infer::error_reporting::nice_region_error::NiceRegionError; use crate::infer::error_reporting::nice_region_error::NiceRegionError;
use crate::infer::lexical_region_resolve::RegionResolutionError; use crate::infer::lexical_region_resolve::RegionResolutionError;
use crate::infer::{Subtype, ValuePairs}; use crate::infer::{Subtype, ValuePairs};
use crate::traits::ObligationCauseCode::CompareImplItemObligation;
use rustc_errors::ErrorGuaranteed; use rustc_errors::ErrorGuaranteed;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::Res; use rustc_hir::def::Res;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::Visitor; use rustc_hir::intravisit::Visitor;
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
use rustc_middle::traits::ObligationCauseCode;
use rustc_middle::ty::error::ExpectedFound; use rustc_middle::ty::error::ExpectedFound;
use rustc_middle::ty::print::RegionHighlightMode; use rustc_middle::ty::print::RegionHighlightMode;
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitor}; use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitor};
@ -31,7 +31,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
_, _,
) = error.clone() ) = error.clone()
&& let (Subtype(sup_trace), Subtype(sub_trace)) = (&sup_origin, &sub_origin) && let (Subtype(sup_trace), Subtype(sub_trace)) = (&sup_origin, &sub_origin)
&& let CompareImplItemObligation { trait_item_def_id, .. } = sub_trace.cause.code() && let ObligationCauseCode::CompareImplItem { trait_item_def_id, .. } =
sub_trace.cause.code()
&& sub_trace.values == sup_trace.values && sub_trace.values == sup_trace.values
&& let ValuePairs::PolySigs(ExpectedFound { expected, found }) = sub_trace.values && let ValuePairs::PolySigs(ExpectedFound { expected, found }) = sub_trace.values
{ {

View file

@ -357,12 +357,13 @@ 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::Where(..) | ObligationCauseCode::WhereInExpr(..) ObligationCauseCode::SpannedItem(..)
| ObligationCauseCode::SpannedItemInExpr(..)
) => ) =>
{ {
// 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::Where(_, span) if let ObligationCauseCode::SpannedItem(_, span)
| ObligationCauseCode::WhereInExpr(_, span, ..) = | ObligationCauseCode::SpannedItemInExpr(_, span, ..) =
&trace.cause.code().peel_derives() &trace.cause.code().peel_derives()
{ {
let span = *span; let span = *span;
@ -370,7 +371,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
.with_span_note(span, "the lifetime requirement is introduced here") .with_span_note(span, "the lifetime requirement is introduced here")
} else { } else {
unreachable!( unreachable!(
"control flow ensures we have a `BindingObligation` or `ExprBindingObligation` here..." "control flow ensures we have a `BindingObligation` or `SpannedItemInExpr` here..."
) )
} }
} }

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::Where(_, span) ObligationCauseCode::SpannedItem(_, span)
| ObligationCauseCode::WhereInExpr(_, span, ..) => Some(*span), | ObligationCauseCode::SpannedItemInExpr(_, span, ..) => Some(*span),
_ => None, _ => None,
}, },
) )

View file

@ -105,7 +105,7 @@ impl<'tcx> PredicateObligation<'tcx> {
impl<'tcx> PolyTraitObligation<'tcx> { impl<'tcx> PolyTraitObligation<'tcx> {
pub fn derived_cause( pub fn derived_cause(
&self, &self,
variant: impl FnOnce(DerivedObligationCause<'tcx>) -> ObligationCauseCode<'tcx>, variant: impl FnOnce(DerivedCause<'tcx>) -> ObligationCauseCode<'tcx>,
) -> ObligationCause<'tcx> { ) -> ObligationCause<'tcx> {
self.cause.clone().derived_cause(self.predicate, variant) self.cause.clone().derived_cause(self.predicate, variant)
} }

View file

@ -129,7 +129,7 @@ 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::ImplDerived(Box::new(traits::ImplDerivedObligationCause { ObligationCauseCode::ImplDerived(Box::new(traits::ImplDerivedCause {
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),

View file

@ -165,7 +165,7 @@ impl<'tcx> ObligationCause<'tcx> {
pub fn derived_cause( pub fn derived_cause(
mut self, mut self,
parent_trait_pred: ty::PolyTraitPredicate<'tcx>, parent_trait_pred: ty::PolyTraitPredicate<'tcx>,
variant: impl FnOnce(DerivedObligationCause<'tcx>) -> ObligationCauseCode<'tcx>, variant: impl FnOnce(DerivedCause<'tcx>) -> ObligationCauseCode<'tcx>,
) -> ObligationCause<'tcx> { ) -> ObligationCause<'tcx> {
/*! /*!
* Creates a cause for obligations that are derived from * Creates a cause for obligations that are derived from
@ -180,8 +180,7 @@ impl<'tcx> ObligationCause<'tcx> {
// NOTE(flaper87): As of now, it keeps track of the whole error // NOTE(flaper87): As of now, it keeps track of the whole error
// chain. Ideally, we should have a way to configure this either // chain. Ideally, we should have a way to configure this either
// by using -Z verbose-internals or just a CLI argument. // by using -Z verbose-internals or just a CLI argument.
self.code = self.code = variant(DerivedCause { parent_trait_pred, parent_code: self.code }).into();
variant(DerivedObligationCause { parent_trait_pred, parent_code: self.code }).into();
self self
} }
@ -254,16 +253,16 @@ pub enum ObligationCauseCode<'tcx> {
/// Like `MiscItem`, 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.
Where(DefId, Span), SpannedItem(DefId, Span),
/// Like `ItemObligation`, but carries the `HirId` of the /// Like `MiscItem`, 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.
MiscItemInExpr(DefId, HirId, usize), MiscItemInExpr(DefId, HirId, usize),
/// Combines `ExprItemObligation` and `BindingObligation`. /// Combines `SpannedItem` and `MiscItemInExpr`.
WhereInExpr(DefId, Span, HirId, usize), SpannedItemInExpr(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>),
@ -327,16 +326,18 @@ 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`.
BuiltinDerived(DerivedObligationCause<'tcx>), BuiltinDerived(DerivedCause<'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.
ImplDerived(Box<ImplDerivedObligationCause<'tcx>>), ImplDerived(Box<ImplDerivedCause<'tcx>>),
/// Derived obligation for WF goals. /// Derived obligation for WF goals.
WellFormedDerived(DerivedObligationCause<'tcx>), WellFormedDerived(DerivedCause<'tcx>),
FunctionArgumentObligation { /// Derived obligation refined to point at a specific argument in
/// a call or method expression.
FunctionArg {
/// The node of the relevant argument in the function call. /// The node of the relevant argument in the function call.
arg_hir_id: HirId, arg_hir_id: HirId,
/// The node of the function call. /// The node of the function call.
@ -347,7 +348,7 @@ pub enum ObligationCauseCode<'tcx> {
/// Error derived when checking an impl item is compatible with /// Error derived when checking an impl item is compatible with
/// its corresponding trait item's definition /// its corresponding trait item's definition
CompareImplItemObligation { CompareImplItem {
impl_item_def_id: LocalDefId, impl_item_def_id: LocalDefId,
trait_item_def_id: DefId, trait_item_def_id: DefId,
kind: ty::AssocKind, kind: ty::AssocKind,
@ -495,8 +496,8 @@ pub enum WellFormedLoc {
#[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)] #[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
#[derive(TypeVisitable, TypeFoldable)] #[derive(TypeVisitable, TypeFoldable)]
pub struct ImplDerivedObligationCause<'tcx> { pub struct ImplDerivedCause<'tcx> {
pub derived: DerivedObligationCause<'tcx>, pub derived: DerivedCause<'tcx>,
/// The `DefId` of the `impl` that gave rise to the `derived` obligation. /// The `DefId` of the `impl` that gave rise to the `derived` obligation.
/// If the `derived` obligation arose from a trait alias, which conceptually has a synthetic impl, /// If the `derived` obligation arose from a trait alias, which conceptually has a synthetic impl,
/// then this will be the `DefId` of that trait alias. Care should therefore be taken to handle /// then this will be the `DefId` of that trait alias. Care should therefore be taken to handle
@ -537,9 +538,9 @@ impl<'tcx> ObligationCauseCode<'tcx> {
ObligationCauseCode::FunctionArg { parent_code, .. } => Some((parent_code, None)), ObligationCauseCode::FunctionArg { parent_code, .. } => Some((parent_code, None)),
ObligationCauseCode::BuiltinDerived(derived) ObligationCauseCode::BuiltinDerived(derived)
| ObligationCauseCode::WellFormedDerived(derived) | ObligationCauseCode::WellFormedDerived(derived)
| ObligationCauseCode::ImplDerived(box ImplDerivedObligationCause { | ObligationCauseCode::ImplDerived(box ImplDerivedCause { derived, .. }) => {
derived, .. Some((&derived.parent_code, Some(derived.parent_trait_pred)))
}) => Some((&derived.parent_code, Some(derived.parent_trait_pred))), }
_ => None, _ => None,
} }
} }
@ -592,7 +593,7 @@ pub struct IfExpressionCause<'tcx> {
#[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)] #[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
#[derive(TypeVisitable, TypeFoldable)] #[derive(TypeVisitable, TypeFoldable)]
pub struct DerivedObligationCause<'tcx> { pub struct DerivedCause<'tcx> {
/// The trait predicate of the parent obligation that led to the /// The trait predicate of the parent obligation that led to the
/// current obligation. Note that only trait obligations lead to /// current obligation. Note that only trait obligations lead to
/// derived obligations, so we just store the trait predicate here /// derived obligations, so we just store the trait predicate here

View file

@ -425,7 +425,7 @@ 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::ImplDerived(Box::new(traits::ImplDerivedObligationCause { ObligationCauseCode::ImplDerived(Box::new(traits::ImplDerivedCause {
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),
@ -435,8 +435,7 @@ fn derive_cause<'tcx>(
} }
} }
ProbeKind::TraitCandidate { source: CandidateSource::BuiltinImpl(..), result: _ } => { ProbeKind::TraitCandidate { source: CandidateSource::BuiltinImpl(..), result: _ } => {
cause = cause cause = cause.derived_cause(parent_trait_pred, ObligationCauseCode::BuiltinDerived);
.derived_cause(parent_trait_pred, ObligationCauseCode::BuiltinDerivedObligation);
} }
_ => {} _ => {}
}; };

View file

@ -7,7 +7,7 @@ use super::{
use crate::errors; use crate::errors;
use crate::infer::InferCtxt; use crate::infer::InferCtxt;
use crate::traits::{ImplDerivedObligationCause, NormalizeExt, ObligationCtxt}; use crate::traits::{ImplDerivedCause, NormalizeExt, ObligationCtxt};
use hir::def::CtorOf; use hir::def::CtorOf;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
@ -1400,10 +1400,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
if let ObligationCauseCode::ImplDerived(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::Where(_, _) } else if let ObligationCauseCode::SpannedItem(_, _)
| ObligationCauseCode::MiscItem(_) | ObligationCauseCode::MiscItem(_)
| ObligationCauseCode::MiscItemInExpr(..) | ObligationCauseCode::MiscItemInExpr(..)
| ObligationCauseCode::WhereInExpr(..) = code | ObligationCauseCode::SpannedItemInExpr(..) = code
{ {
try_borrowing(poly_trait_pred, &never_suggest_borrow) try_borrowing(poly_trait_pred, &never_suggest_borrow)
} else { } else {
@ -2099,10 +2099,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
cause: &ObligationCauseCode<'tcx>, cause: &ObligationCauseCode<'tcx>,
err: &mut Diag<'tcx>, err: &mut Diag<'tcx>,
) { ) {
// First, look for an `ExprBindingObligation`, which means we can get // First, look for an `SpannedItemInExpr`, 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::WhereInExpr(def_id, _, _, idx) = cause if let ObligationCauseCode::SpannedItemInExpr(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()
@ -2747,8 +2747,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
// 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::Where(item_def_id, span) ObligationCauseCode::SpannedItem(item_def_id, span)
| ObligationCauseCode::WhereInExpr(item_def_id, span, ..) => { | ObligationCauseCode::SpannedItemInExpr(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);
@ -3799,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::WhereInExpr(def_id, _, _, idx) = parent_code if let ObligationCauseCode::SpannedItemInExpr(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)
@ -4955,7 +4955,7 @@ fn point_at_assoc_type_restriction<G: EmissionGuarantee>(
trait_name: &str, trait_name: &str,
predicate: ty::Predicate<'_>, predicate: ty::Predicate<'_>,
generics: &hir::Generics<'_>, generics: &hir::Generics<'_>,
data: &ImplDerivedObligationCause<'_>, data: &ImplDerivedCause<'_>,
) { ) {
let ty::PredicateKind::Clause(clause) = predicate.kind().skip_binder() else { let ty::PredicateKind::Clause(clause) = predicate.kind().skip_binder() else {
return; return;

View file

@ -1533,9 +1533,9 @@ 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::Where(..) if let ObligationCauseCode::SpannedItem(..)
| ObligationCauseCode::MiscItem(..) | ObligationCauseCode::MiscItem(..)
| ObligationCauseCode::WhereInExpr(..) | ObligationCauseCode::SpannedItemInExpr(..)
| ObligationCauseCode::MiscItemInExpr(..) = code | ObligationCauseCode::MiscItemInExpr(..) = code
{ {
self.note_obligation_cause_code( self.note_obligation_cause_code(
@ -1611,9 +1611,9 @@ 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::MiscItem(_) ObligationCauseCode::MiscItem(_)
| ObligationCauseCode::Where(_, _) | ObligationCauseCode::SpannedItem(_, _)
| ObligationCauseCode::MiscItemInExpr(..) | ObligationCauseCode::MiscItemInExpr(..)
| ObligationCauseCode::WhereInExpr(..) | ObligationCauseCode::SpannedItemInExpr(..)
| ObligationCauseCode::Coercion { .. } | ObligationCauseCode::Coercion { .. }
); );
@ -2881,8 +2881,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
else { else {
return; return;
}; };
let (ObligationCauseCode::Where(item_def_id, span) let (ObligationCauseCode::SpannedItem(item_def_id, span)
| ObligationCauseCode::WhereInExpr(item_def_id, span, ..)) = | ObligationCauseCode::SpannedItemInExpr(item_def_id, span, ..)) =
*obligation.cause.code().peel_derives() *obligation.cause.code().peel_derives()
else { else {
return; return;
@ -3179,7 +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::Where(def_id, _) | ObligationCauseCode::MiscItem(def_id) ObligationCauseCode::SpannedItem(def_id, _) | ObligationCauseCode::MiscItem(def_id)
if self.tcx.is_fn_trait(*def_id) => if self.tcx.is_fn_trait(*def_id) =>
{ {
err.code(E0059); err.code(E0059);

View file

@ -576,7 +576,7 @@ pub fn normalize_inherent_projection<'a, 'b, 'tcx>(
if span.is_dummy() { if span.is_dummy() {
ObligationCauseCode::MiscItem(alias_ty.def_id) ObligationCauseCode::MiscItem(alias_ty.def_id)
} else { } else {
ObligationCauseCode::Where(alias_ty.def_id, span) ObligationCauseCode::SpannedItem(alias_ty.def_id, span)
}, },
); );
@ -2129,7 +2129,7 @@ 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::Where(obligation.predicate.def_id, span), ObligationCauseCode::SpannedItem(obligation.predicate.def_id, span),
) )
}; };
nested.push(Obligation::with_depth( nested.push(Obligation::with_depth(

View file

@ -26,7 +26,7 @@ use crate::traits::vtable::{
VtblSegment, VtblSegment,
}; };
use crate::traits::{ use crate::traits::{
ImplDerivedObligationCause, ImplSource, ImplSourceUserDefinedData, Normalized, Obligation, ImplDerivedCause, ImplSource, ImplSourceUserDefinedData, Normalized, Obligation,
ObligationCause, PolyTraitObligation, PredicateObligation, Selection, SelectionError, ObligationCause, PolyTraitObligation, PredicateObligation, Selection, SelectionError,
SignatureMismatch, TraitNotObjectSafe, TraitObligation, Unimplemented, SignatureMismatch, TraitNotObjectSafe, TraitObligation, Unimplemented,
}; };
@ -275,7 +275,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
bug!("obligation {:?} had matched a builtin impl but now doesn't", obligation); bug!("obligation {:?} had matched a builtin impl but now doesn't", obligation);
}; };
let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerivedObligation); let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerived);
self.collect_predicates_for_types( self.collect_predicates_for_types(
obligation.param_env, obligation.param_env,
cause, cause,
@ -435,7 +435,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
) -> Vec<PredicateObligation<'tcx>> { ) -> Vec<PredicateObligation<'tcx>> {
debug!(?nested, "vtable_auto_impl"); debug!(?nested, "vtable_auto_impl");
ensure_sufficient_stack(|| { ensure_sufficient_stack(|| {
let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerivedObligation); let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerived);
let poly_trait_ref = obligation.predicate.to_poly_trait_ref(); let poly_trait_ref = obligation.predicate.to_poly_trait_ref();
let trait_ref = self.infcx.enter_forall_and_leak_universe(poly_trait_ref); let trait_ref = self.infcx.enter_forall_and_leak_universe(poly_trait_ref);
@ -723,7 +723,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let mut nested = let mut nested =
self.equate_trait_refs(obligation.with(tcx, placeholder_predicate), trait_ref)?; self.equate_trait_refs(obligation.with(tcx, placeholder_predicate), trait_ref)?;
let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerivedObligation); let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerived);
// Confirm the `type Output: Sized;` bound that is present on `FnOnce` // Confirm the `type Output: Sized;` bound that is present on `FnOnce`
let output_ty = self.infcx.enter_forall_and_leak_universe(sig.output()); let output_ty = self.infcx.enter_forall_and_leak_universe(sig.output());
@ -1381,7 +1381,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let self_ty = obligation.self_ty().map_bound(|ty| self.infcx.shallow_resolve(ty)); let self_ty = obligation.self_ty().map_bound(|ty| self.infcx.shallow_resolve(ty));
let mut nested = vec![]; let mut nested = vec![];
let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerivedObligation); let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerived);
// If we have a custom `impl const Drop`, then // If we have a custom `impl const Drop`, then
// first check it like a regular impl candidate. // first check it like a regular impl candidate.
@ -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::ImplDerived(Box::new(ImplDerivedObligationCause { ObligationCauseCode::ImplDerived(Box::new(ImplDerivedCause {
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

@ -13,8 +13,8 @@ use super::util;
use super::util::closure_trait_ref_and_return_type; use super::util::closure_trait_ref_and_return_type;
use super::wf; use super::wf;
use super::{ use super::{
ImplDerivedObligationCause, Normalized, Obligation, ObligationCause, ObligationCauseCode, ImplDerivedCause, Normalized, Obligation, ObligationCause, ObligationCauseCode, Overflow,
Overflow, PolyTraitObligation, PredicateObligation, Selection, SelectionError, SelectionResult, PolyTraitObligation, PredicateObligation, Selection, SelectionError, SelectionResult,
TraitQueryMode, TraitQueryMode,
}; };
@ -2771,7 +2771,7 @@ 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::ImplDerived(Box::new(ImplDerivedObligationCause { ObligationCauseCode::ImplDerived(Box::new(ImplDerivedCause {
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),

View file

@ -382,7 +382,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
if let Some(parent_trait_pred) = predicate.to_opt_poly_trait_pred() { if let Some(parent_trait_pred) = predicate.to_opt_poly_trait_pred() {
cause = cause.derived_cause( cause = cause.derived_cause(
parent_trait_pred, parent_trait_pred,
traits::ObligationCauseCode::WellFormedDerivedObligation, traits::ObligationCauseCode::WellFormedDerived,
); );
} }
extend_cause_with_original_assoc_item_obligation(tcx, item, &mut cause, predicate); extend_cause_with_original_assoc_item_obligation(tcx, item, &mut cause, predicate);
@ -568,7 +568,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
let code = if span.is_dummy() { let code = if span.is_dummy() {
ObligationCauseCode::MiscItem(origin_def_id) ObligationCauseCode::MiscItem(origin_def_id)
} else { } else {
ObligationCauseCode::Where(origin_def_id, span) ObligationCauseCode::SpannedItem(origin_def_id, span)
}; };
let cause = self.cause(code); let cause = self.cause(code);
traits::Obligation::with_depth( traits::Obligation::with_depth(