1
Fork 0

Auto merge of #124952 - compiler-errors:no-error, r=lcnr

Rename some `FulfillmentErrorCode`/`ObligationCauseCode` variants to be less redundant

1. Rename some `FulfillmentErrorCode` variants.
2. Always use `ObligationCauseCode::` to prefix a code, rather than using a glob import and naming them through `traits::`.
3. Rename some `ObligationCauseCode` variants -- I wasn't particularly thorough with thinking of a new names for these, so could workshop them if necessary.
4. Misc stuff from renaming.

r? lcnr
This commit is contained in:
bors 2024-05-10 18:11:02 +00:00
commit 2cce088584
48 changed files with 432 additions and 393 deletions

View file

@ -33,8 +33,6 @@ use std::hash::{Hash, Hasher};
pub use self::select::{EvaluationCache, EvaluationResult, OverflowError, SelectionCache};
pub use self::ObligationCauseCode::*;
/// Depending on the stage of compilation, we want projection to be
/// more or less conservative.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, HashStable, Encodable, Decodable)]
@ -129,7 +127,7 @@ impl<'tcx> ObligationCause<'tcx> {
}
pub fn misc(span: Span, body_id: LocalDefId) -> ObligationCause<'tcx> {
ObligationCause::new(span, body_id, MiscObligation)
ObligationCause::new(span, body_id, ObligationCauseCode::Misc)
}
#[inline(always)]
@ -167,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
@ -182,15 +180,14 @@ 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
}
pub fn to_constraint_category(&self) -> ConstraintCategory<'tcx> {
match self.code() {
MatchImpl(cause, _) => cause.to_constraint_category(),
AscribeUserTypeProvePredicate(predicate_span) => {
ObligationCauseCode::MatchImpl(cause, _) => cause.to_constraint_category(),
ObligationCauseCode::AscribeUserTypeProvePredicate(predicate_span) => {
ConstraintCategory::Predicate(*predicate_span)
}
_ => ConstraintCategory::BoringNoLocation,
@ -209,7 +206,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>>>,
}
@ -225,11 +222,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)) },
}
}
}
@ -238,7 +231,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)
}
}
@ -246,7 +239,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,
@ -256,20 +249,20 @@ pub enum ObligationCauseCode<'tcx> {
/// Must satisfy all of the where-clause predicates of the
/// given item.
ItemObligation(DefId),
WhereClause(DefId),
/// Like `ItemObligation`, but carries the span of the
/// Like `WhereClause`, but carries the span of the
/// predicate when it can be identified.
BindingObligation(DefId, Span),
SpannedWhereClause(DefId, Span),
/// Like `ItemObligation`, but carries the `HirId` of the
/// Like `WhereClause`, 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),
WhereClauseInExpr(DefId, HirId, usize),
/// Combines `ExprItemObligation` and `BindingObligation`.
ExprBindingObligation(DefId, Span, HirId, usize),
/// Combines `SpannedWhereClause` and `WhereClauseInExpr`.
SpannedWhereClauseInExpr(DefId, Span, HirId, usize),
/// A type like `&'a T` is WF only if `T: 'a`.
ReferenceOutlivesReferent(Ty<'tcx>),
@ -333,16 +326,18 @@ pub enum ObligationCauseCode<'tcx> {
/// Derived obligation (i.e. theoretical `where` clause) on a built-in
/// implementation like `Copy` or `Sized`.
BuiltinDerivedObligation(DerivedObligationCause<'tcx>),
BuiltinDerived(DerivedCause<'tcx>),
/// Derived obligation (i.e. `where` clause) on an user-provided impl
/// or a trait alias.
ImplDerivedObligation(Box<ImplDerivedObligationCause<'tcx>>),
ImplDerived(Box<ImplDerivedCause<'tcx>>),
/// Derived obligation for WF goals.
WellFormedDerivedObligation(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.
@ -353,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,
@ -432,8 +427,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.
@ -501,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
@ -540,10 +535,10 @@ impl<'tcx> ObligationCauseCode<'tcx> {
pub fn parent(&self) -> Option<(&Self, Option<ty::PolyTraitPredicate<'tcx>>)> {
match self {
FunctionArgumentObligation { parent_code, .. } => Some((parent_code, None)),
BuiltinDerivedObligation(derived)
| WellFormedDerivedObligation(derived)
| ImplDerivedObligation(box ImplDerivedObligationCause { derived, .. }) => {
ObligationCauseCode::FunctionArg { parent_code, .. } => Some((parent_code, None)),
ObligationCauseCode::BuiltinDerived(derived)
| ObligationCauseCode::WellFormedDerived(derived)
| ObligationCauseCode::ImplDerived(box ImplDerivedCause { derived, .. }) => {
Some((&derived.parent_code, Some(derived.parent_trait_pred)))
}
_ => None,
@ -552,7 +547,7 @@ impl<'tcx> ObligationCauseCode<'tcx> {
pub fn peel_match_impls(&self) -> &Self {
match self {
MatchImpl(cause, _) => cause.code(),
ObligationCauseCode::MatchImpl(cause, _) => cause.code(),
_ => self,
}
}
@ -598,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