diff options
| author | Michael Goulet <michael@errs.io> | 2024-05-09 20:25:11 -0400 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2024-05-10 10:42:57 -0400 |
| commit | 9108294a6c37c36ce561eade9d1c321a5d75bddd (patch) | |
| tree | fdd6c21c7d8333a60949a06ca2507d0822418e93 | |
| parent | 534e267d488a698ee8839452377e1d3201eede65 (diff) | |
| download | rust-9108294a6c37c36ce561eade9d1c321a5d75bddd.tar.gz rust-9108294a6c37c36ce561eade9d1c321a5d75bddd.zip | |
More rename fallout
25 files changed, 93 insertions, 91 deletions
diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index 2120d3e61f7..e61c1ee98cd 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -2059,7 +2059,7 @@ 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::Where(CRATE_DEF_ID.to_def_id(), predicate_span)) + Some(ObligationCauseCode::SpannedItem(CRATE_DEF_ID.to_def_id(), predicate_span)) } else { None } diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index 97b60d137e6..00f223f2ca3 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -819,7 +819,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'_, 'tcx> { ObligationCause::new( self.span, self.body_id, - ObligationCauseCode::Where(proj.def_id, pred_span), + ObligationCauseCode::SpannedItem(proj.def_id, pred_span), ), self.param_env, pred, @@ -2014,7 +2014,7 @@ pub(super) fn check_type_bounds<'tcx>( let code = if span.is_dummy() { ObligationCauseCode::MiscItem(trait_ty.def_id) } 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) }; @@ -2251,7 +2251,7 @@ fn try_report_async_mismatch<'tcx>( }; 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 && let Some(proj) = error.root_obligation.predicate.to_opt_poly_projection_pred() && let Some(proj) = proj.no_bound_vars() diff --git a/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs b/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs index 9486e241f98..77dbb23fcb6 100644 --- a/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs +++ b/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs @@ -212,7 +212,7 @@ fn get_impl_args( traits::ObligationCause::new( impl1_span, impl1_def_id, - traits::ObligationCauseCode::Where(impl2_node.def_id(), span), + traits::ObligationCauseCode::SpannedItem(impl2_node.def_id(), span), ) }, ); diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 970f25983de..cdf17f3a113 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -3083,14 +3083,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { polarity: ty::PredicatePolarity::Positive, }), |derived| { - ObligationCauseCode::ImplDerived(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::ImplDerivedCause { + derived, + impl_or_alias_def_id: impl_def_id, + impl_def_predicate_index: Some(idx), + span, + })) }, ) }, diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 0ca7d496d8b..8e9b12cb606 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -1415,7 +1415,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if span.is_dummy() { ObligationCauseCode::MiscItemInExpr(def_id, hir_id, idx) } else { - ObligationCauseCode::WhereInExpr(def_id, span, hir_id, idx) + ObligationCauseCode::SpannedItemInExpr(def_id, span, hir_id, idx) } }) } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs index 5e136bb6afd..d1336d58eed 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs @@ -15,7 +15,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { error: &mut traits::FulfillmentError<'tcx>, ) -> bool { 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() else { return false; @@ -512,7 +512,7 @@ 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::WhereInExpr(_, _, _, _) => { + traits::ObligationCauseCode::SpannedItemInExpr(_, _, _, _) => { // 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) @@ -555,7 +555,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// only a partial success - but it cannot be refined even further. fn blame_specific_expr_if_possible_for_derived_predicate_obligation( &self, - obligation: &traits::ImplDerivedObligationCause<'tcx>, + obligation: &traits::ImplDerivedCause<'tcx>, expr: &'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. diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 3e05f47646c..f82aeb63734 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -33,7 +33,6 @@ use rustc_index::IndexVec; use rustc_infer::infer::error_reporting::{FailureCode, ObligationCauseExt}; use rustc_infer::infer::TypeTrace; use rustc_infer::infer::{DefineOpaqueTypes, InferOk}; -use rustc_middle::traits::ObligationCauseCode::ExprBindingObligation; use rustc_middle::ty::adjustment::AllowTwoPhase; use rustc_middle::ty::visit::TypeVisitableExt; use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt}; @@ -2014,7 +2013,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { for (span, code) in errors_causecode { self.dcx().try_steal_modify_and_emit_err(span, StashKey::MaybeForgetReturn, |err| { 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() { 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 // 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 (span, predicate, cause) in &remap_cause { if *predicate == error.obligation.predicate diff --git a/compiler/rustc_hir_typeck/src/method/confirm.rs b/compiler/rustc_hir_typeck/src/method/confirm.rs index 1d697b25641..7cb60c792ba 100644 --- a/compiler/rustc_hir_typeck/src/method/confirm.rs +++ b/compiler/rustc_hir_typeck/src/method/confirm.rs @@ -567,7 +567,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { let code = if span.is_dummy() { ObligationCauseCode::MiscItemInExpr(def_id, self.call_expr.hir_id, idx) } 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) }, diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 021200d9d53..8d5696d3e5c 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -1408,7 +1408,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { idx, ) } else { - ObligationCauseCode::WhereInExpr( + ObligationCauseCode::SpannedItemInExpr( impl_def_id, span, self.scope_expr_id, diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 31677525d2a..aa814d2b457 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -830,8 +830,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { (data.impl_or_alias_def_id, data.span) } Some( - ObligationCauseCode::WhereInExpr(def_id, span, _, _) - | ObligationCauseCode::Where(def_id, span), + ObligationCauseCode::SpannedItemInExpr(def_id, span, _, _) + | ObligationCauseCode::SpannedItem(def_id, span), ) => (*def_id, *span), _ => continue, }; diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 5c74420af92..8354dfe3bf3 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -883,8 +883,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { err.help("...or use `match` instead of `let...else`"); } _ => { - if let ObligationCauseCode::Where(_, span) - | ObligationCauseCode::WhereInExpr(_, span, ..) = cause.code().peel_derives() + if let ObligationCauseCode::SpannedItem(_, span) + | ObligationCauseCode::SpannedItemInExpr(_, span, ..) = + cause.code().peel_derives() && let TypeError::RegionsPlaceholderMismatch = terr { err.span_note(*span, "the lifetime requirement is introduced here"); @@ -2011,7 +2012,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { trace: &TypeTrace<'tcx>, terr: TypeError<'tcx>, ) -> Vec<TypeErrorAdditionalDiags> { - use crate::traits::ObligationCauseCode::{BlockTailExpression, MatchExpressionArm}; let mut suggestions = Vec::new(); let span = trace.cause.span(); let values = self.resolve_vars_if_possible(trace.values); @@ -2078,8 +2078,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { } } let code = trace.cause.code(); - if let &(MatchExpressionArm(box MatchExpressionArmCause { source, .. }) - | BlockTailExpression(.., source)) = code + if let &(ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause { + source, + .. + }) + | ObligationCauseCode::BlockTailExpression(.., source)) = code && let hir::MatchSource::TryDesugar(_) = source && let Some((expected_ty, found_ty, _)) = self.values_str(trace.values) { diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mismatched_static_lifetime.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mismatched_static_lifetime.rs index 26a9e695929..30116b43297 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mismatched_static_lifetime.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mismatched_static_lifetime.rs @@ -38,8 +38,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { let ObligationCauseCode::MatchImpl(parent, impl_def_id) = code else { return None; }; - let (ObligationCauseCode::Where(_, binding_span) - | ObligationCauseCode::WhereInExpr(_, binding_span, ..)) = *parent.code() + let (ObligationCauseCode::SpannedItem(_, binding_span) + | ObligationCauseCode::SpannedItemInExpr(_, binding_span, ..)) = *parent.code() else { return None; }; diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs index b4cf727bf8f..7f3e23716f9 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs @@ -4,13 +4,13 @@ use crate::errors::{ConsiderBorrowingParamHelp, RelationshipHelp, TraitImplDiff} use crate::infer::error_reporting::nice_region_error::NiceRegionError; use crate::infer::lexical_region_resolve::RegionResolutionError; use crate::infer::{Subtype, ValuePairs}; -use crate::traits::ObligationCauseCode::CompareImplItemObligation; use rustc_errors::ErrorGuaranteed; use rustc_hir as hir; use rustc_hir::def::Res; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::Visitor; use rustc_middle::hir::nested_filter; +use rustc_middle::traits::ObligationCauseCode; use rustc_middle::ty::error::ExpectedFound; use rustc_middle::ty::print::RegionHighlightMode; use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitor}; @@ -31,7 +31,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { _, ) = error.clone() && 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 && let ValuePairs::PolySigs(ExpectedFound { expected, found }) = sub_trace.values { diff --git a/compiler/rustc_infer/src/infer/error_reporting/note.rs b/compiler/rustc_infer/src/infer/error_reporting/note.rs index 8a65f9622d2..b1d978867cb 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/note.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/note.rs @@ -357,12 +357,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { infer::Subtype(box ref trace) if matches!( &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`. - if let ObligationCauseCode::Where(_, span) - | ObligationCauseCode::WhereInExpr(_, span, ..) = + if let ObligationCauseCode::SpannedItem(_, span) + | ObligationCauseCode::SpannedItemInExpr(_, span, ..) = &trace.cause.code().peel_derives() { let span = *span; @@ -370,7 +371,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { .with_span_note(span, "the lifetime requirement is introduced here") } else { unreachable!( - "control flow ensures we have a `BindingObligation` or `ExprBindingObligation` here..." + "control flow ensures we have a `BindingObligation` or `SpannedItemInExpr` here..." ) } } diff --git a/compiler/rustc_infer/src/infer/outlives/obligations.rs b/compiler/rustc_infer/src/infer/outlives/obligations.rs index 21abd90916a..58eeec9956d 100644 --- a/compiler/rustc_infer/src/infer/outlives/obligations.rs +++ b/compiler/rustc_infer/src/infer/outlives/obligations.rs @@ -103,8 +103,8 @@ impl<'tcx> InferCtxt<'tcx> { cause.span, sup_type, match cause.code().peel_derives() { - ObligationCauseCode::Where(_, span) - | ObligationCauseCode::WhereInExpr(_, span, ..) => Some(*span), + ObligationCauseCode::SpannedItem(_, span) + | ObligationCauseCode::SpannedItemInExpr(_, span, ..) => Some(*span), _ => None, }, ) diff --git a/compiler/rustc_infer/src/traits/mod.rs b/compiler/rustc_infer/src/traits/mod.rs index ce6b3e8f487..85510cf2dcc 100644 --- a/compiler/rustc_infer/src/traits/mod.rs +++ b/compiler/rustc_infer/src/traits/mod.rs @@ -105,7 +105,7 @@ impl<'tcx> PredicateObligation<'tcx> { impl<'tcx> PolyTraitObligation<'tcx> { pub fn derived_cause( &self, - variant: impl FnOnce(DerivedObligationCause<'tcx>) -> ObligationCauseCode<'tcx>, + variant: impl FnOnce(DerivedCause<'tcx>) -> ObligationCauseCode<'tcx>, ) -> ObligationCause<'tcx> { self.cause.clone().derived_cause(self.predicate, variant) } diff --git a/compiler/rustc_infer/src/traits/util.rs b/compiler/rustc_infer/src/traits/util.rs index 1104df570a8..d8d84b777e0 100644 --- a/compiler/rustc_infer/src/traits/util.rs +++ b/compiler/rustc_infer/src/traits/util.rs @@ -129,7 +129,7 @@ impl<'tcx> Elaboratable<'tcx> for PredicateObligation<'tcx> { index: usize, ) -> Self { let cause = self.cause.clone().derived_cause(parent_trait_pred, |derived| { - ObligationCauseCode::ImplDerived(Box::new(traits::ImplDerivedObligationCause { + ObligationCauseCode::ImplDerived(Box::new(traits::ImplDerivedCause { derived, impl_or_alias_def_id: parent_trait_pred.def_id(), impl_def_predicate_index: Some(index), diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index c38e984af73..5e5f28a54e8 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -165,7 +165,7 @@ impl<'tcx> ObligationCause<'tcx> { pub fn derived_cause( mut self, parent_trait_pred: ty::PolyTraitPredicate<'tcx>, - variant: impl FnOnce(DerivedObligationCause<'tcx>) -> ObligationCauseCode<'tcx>, + variant: impl FnOnce(DerivedCause<'tcx>) -> ObligationCauseCode<'tcx>, ) -> ObligationCause<'tcx> { /*! * 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 // chain. Ideally, we should have a way to configure this either // by using -Z verbose-internals or just a CLI argument. - self.code = - variant(DerivedObligationCause { parent_trait_pred, parent_code: self.code }).into(); + self.code = variant(DerivedCause { parent_trait_pred, parent_code: self.code }).into(); self } @@ -254,16 +253,16 @@ pub enum ObligationCauseCode<'tcx> { /// Like `MiscItem`, but carries the span of the /// 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` /// indicates exactly which predicate it is in the list of /// instantiated predicates. MiscItemInExpr(DefId, HirId, usize), - /// Combines `ExprItemObligation` and `BindingObligation`. - WhereInExpr(DefId, Span, HirId, usize), + /// Combines `SpannedItem` and `MiscItemInExpr`. + SpannedItemInExpr(DefId, Span, HirId, usize), /// A type like `&'a T` is WF only if `T: 'a`. ReferenceOutlivesReferent(Ty<'tcx>), @@ -327,16 +326,18 @@ pub enum ObligationCauseCode<'tcx> { /// Derived obligation (i.e. theoretical `where` clause) on a built-in /// implementation like `Copy` or `Sized`. - BuiltinDerived(DerivedObligationCause<'tcx>), + BuiltinDerived(DerivedCause<'tcx>), /// Derived obligation (i.e. `where` clause) on an user-provided impl /// or a trait alias. - ImplDerived(Box<ImplDerivedObligationCause<'tcx>>), + ImplDerived(Box<ImplDerivedCause<'tcx>>), /// 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. arg_hir_id: HirId, /// The node of the function call. @@ -347,7 +348,7 @@ pub enum ObligationCauseCode<'tcx> { /// Error derived when checking an impl item is compatible with /// its corresponding trait item's definition - CompareImplItemObligation { + CompareImplItem { impl_item_def_id: LocalDefId, trait_item_def_id: DefId, kind: ty::AssocKind, @@ -495,8 +496,8 @@ pub enum WellFormedLoc { #[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)] #[derive(TypeVisitable, TypeFoldable)] -pub struct ImplDerivedObligationCause<'tcx> { - pub derived: DerivedObligationCause<'tcx>, +pub struct ImplDerivedCause<'tcx> { + pub derived: DerivedCause<'tcx>, /// 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, /// 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::BuiltinDerived(derived) | ObligationCauseCode::WellFormedDerived(derived) - | ObligationCauseCode::ImplDerived(box ImplDerivedObligationCause { - derived, .. - }) => Some((&derived.parent_code, Some(derived.parent_trait_pred))), + | ObligationCauseCode::ImplDerived(box ImplDerivedCause { derived, .. }) => { + Some((&derived.parent_code, Some(derived.parent_trait_pred))) + } _ => None, } } @@ -592,7 +593,7 @@ pub struct IfExpressionCause<'tcx> { #[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)] #[derive(TypeVisitable, TypeFoldable)] -pub struct DerivedObligationCause<'tcx> { +pub struct DerivedCause<'tcx> { /// The trait predicate of the parent obligation that led to the /// current obligation. Note that only trait obligations lead to /// derived obligations, so we just store the trait predicate here diff --git a/compiler/rustc_trait_selection/src/solve/fulfill.rs b/compiler/rustc_trait_selection/src/solve/fulfill.rs index 410890e6680..4cc041fca8c 100644 --- a/compiler/rustc_trait_selection/src/solve/fulfill.rs +++ b/compiler/rustc_trait_selection/src/solve/fulfill.rs @@ -425,7 +425,7 @@ 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::ImplDerived(Box::new(traits::ImplDerivedObligationCause { + ObligationCauseCode::ImplDerived(Box::new(traits::ImplDerivedCause { derived, impl_or_alias_def_id: impl_def_id, impl_def_predicate_index: Some(idx), @@ -435,8 +435,7 @@ fn derive_cause<'tcx>( } } ProbeKind::TraitCandidate { source: CandidateSource::BuiltinImpl(..), result: _ } => { - cause = cause - .derived_cause(parent_trait_pred, ObligationCauseCode::BuiltinDerivedObligation); + cause = cause.derived_cause(parent_trait_pred, ObligationCauseCode::BuiltinDerived); } _ => {} }; diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 86615475607..9839f4768e2 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -7,7 +7,7 @@ use super::{ use crate::errors; use crate::infer::InferCtxt; -use crate::traits::{ImplDerivedObligationCause, NormalizeExt, ObligationCtxt}; +use crate::traits::{ImplDerivedCause, NormalizeExt, ObligationCtxt}; use hir::def::CtorOf; use rustc_data_structures::fx::FxHashSet; @@ -1400,10 +1400,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { if let ObligationCauseCode::ImplDerived(cause) = &*code { try_borrowing(cause.derived.parent_trait_pred, &[]) - } else if let ObligationCauseCode::Where(_, _) + } else if let ObligationCauseCode::SpannedItem(_, _) | ObligationCauseCode::MiscItem(_) | ObligationCauseCode::MiscItemInExpr(..) - | ObligationCauseCode::WhereInExpr(..) = code + | ObligationCauseCode::SpannedItemInExpr(..) = code { try_borrowing(poly_trait_pred, &never_suggest_borrow) } else { @@ -2099,10 +2099,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { cause: &ObligationCauseCode<'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 // 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 Some(pred) = predicates.predicates.get(*idx) && 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 // doesn't add user usable information. It always point at an associated item. } - ObligationCauseCode::Where(item_def_id, span) - | ObligationCauseCode::WhereInExpr(item_def_id, span, ..) => { + ObligationCauseCode::SpannedItem(item_def_id, span) + | ObligationCauseCode::SpannedItemInExpr(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); @@ -3799,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::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 where_clauses = 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, predicate: ty::Predicate<'_>, generics: &hir::Generics<'_>, - data: &ImplDerivedObligationCause<'_>, + data: &ImplDerivedCause<'_>, ) { let ty::PredicateKind::Clause(clause) = predicate.kind().skip_binder() else { return; diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs index e85a2b50bf4..f3a4e933164 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs @@ -1533,9 +1533,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { *err, ); let code = error.obligation.cause.code().peel_derives().peel_match_impls(); - if let ObligationCauseCode::Where(..) + if let ObligationCauseCode::SpannedItem(..) | ObligationCauseCode::MiscItem(..) - | ObligationCauseCode::WhereInExpr(..) + | ObligationCauseCode::SpannedItemInExpr(..) | ObligationCauseCode::MiscItemInExpr(..) = code { self.note_obligation_cause_code( @@ -1611,9 +1611,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { let is_normalized_term_expected = !matches!( obligation.cause.code().peel_derives(), ObligationCauseCode::MiscItem(_) - | ObligationCauseCode::Where(_, _) + | ObligationCauseCode::SpannedItem(_, _) | ObligationCauseCode::MiscItemInExpr(..) - | ObligationCauseCode::WhereInExpr(..) + | ObligationCauseCode::SpannedItemInExpr(..) | ObligationCauseCode::Coercion { .. } ); @@ -2881,8 +2881,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { else { return; }; - let (ObligationCauseCode::Where(item_def_id, span) - | ObligationCauseCode::WhereInExpr(item_def_id, span, ..)) = + let (ObligationCauseCode::SpannedItem(item_def_id, span) + | ObligationCauseCode::SpannedItemInExpr(item_def_id, span, ..)) = *obligation.cause.code().peel_derives() else { return; @@ -3179,7 +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::Where(def_id, _) | ObligationCauseCode::MiscItem(def_id) + ObligationCauseCode::SpannedItem(def_id, _) | ObligationCauseCode::MiscItem(def_id) if self.tcx.is_fn_trait(*def_id) => { err.code(E0059); diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 5cffd1fe8ee..e99ecff44f9 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -576,7 +576,7 @@ pub fn normalize_inherent_projection<'a, 'b, 'tcx>( if span.is_dummy() { ObligationCauseCode::MiscItem(alias_ty.def_id) } 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( obligation.cause.span, obligation.cause.body_id, - ObligationCauseCode::Where(obligation.predicate.def_id, span), + ObligationCauseCode::SpannedItem(obligation.predicate.def_id, span), ) }; nested.push(Obligation::with_depth( diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 5e06ef1c2da..0b91dd72e3b 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -26,7 +26,7 @@ use crate::traits::vtable::{ VtblSegment, }; use crate::traits::{ - ImplDerivedObligationCause, ImplSource, ImplSourceUserDefinedData, Normalized, Obligation, + ImplDerivedCause, ImplSource, ImplSourceUserDefinedData, Normalized, Obligation, ObligationCause, PolyTraitObligation, PredicateObligation, Selection, SelectionError, 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); }; - let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerivedObligation); + let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerived); self.collect_predicates_for_types( obligation.param_env, cause, @@ -435,7 +435,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ) -> Vec<PredicateObligation<'tcx>> { debug!(?nested, "vtable_auto_impl"); 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 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 = 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` 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 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 // first check it like a regular impl candidate. @@ -1396,7 +1396,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { debug!(?args, "impl args"); let cause = obligation.derived_cause(|derived| { - ObligationCauseCode::ImplDerived(Box::new(ImplDerivedObligationCause { + ObligationCauseCode::ImplDerived(Box::new(ImplDerivedCause { derived, impl_or_alias_def_id: impl_def_id, impl_def_predicate_index: None, diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index b95f784cd9b..50353a1fd2f 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -13,8 +13,8 @@ use super::util; use super::util::closure_trait_ref_and_return_type; use super::wf; use super::{ - ImplDerivedObligationCause, Normalized, Obligation, ObligationCause, ObligationCauseCode, - Overflow, PolyTraitObligation, PredicateObligation, Selection, SelectionError, SelectionResult, + ImplDerivedCause, Normalized, Obligation, ObligationCause, ObligationCauseCode, Overflow, + PolyTraitObligation, PredicateObligation, Selection, SelectionError, SelectionResult, TraitQueryMode, }; @@ -2771,7 +2771,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { cause.clone() } else { cause.clone().derived_cause(parent_trait_pred, |derived| { - ObligationCauseCode::ImplDerived(Box::new(ImplDerivedObligationCause { + ObligationCauseCode::ImplDerived(Box::new(ImplDerivedCause { derived, impl_or_alias_def_id: def_id, impl_def_predicate_index: Some(index), diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index 73c1b2d24db..d4eb3af3b64 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -382,7 +382,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { if let Some(parent_trait_pred) = predicate.to_opt_poly_trait_pred() { cause = cause.derived_cause( parent_trait_pred, - traits::ObligationCauseCode::WellFormedDerivedObligation, + traits::ObligationCauseCode::WellFormedDerived, ); } 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() { ObligationCauseCode::MiscItem(origin_def_id) } else { - ObligationCauseCode::Where(origin_def_id, span) + ObligationCauseCode::SpannedItem(origin_def_id, span) }; let cause = self.cause(code); traits::Obligation::with_depth( |
