Skip to content

Commit

Permalink
Rollup merge of #118201 - compiler-errors:obligation-causes, r=cjgillot
Browse files Browse the repository at this point in the history
Miscellaneous `ObligationCauseCode` cleanups

Remove some dead code/unused `ObligationCauseCode`s.
  • Loading branch information
compiler-errors committed Nov 25, 2023
2 parents 3b2f33e + ca56739 commit f4b7f35
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 39 deletions.
6 changes: 0 additions & 6 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2909,9 +2909,6 @@ impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> {
CompareImplItemObligation { kind: ty::AssocKind::Const, .. } => {
"const is compatible with trait"
}
ExprAssignable => "expression is assignable",
IfExpression { .. } => "`if` and `else` have incompatible types",
IfExpressionWithNoElse => "`if` missing an `else` returns `()`",
MainFunctionType => "`main` function has the correct type",
StartFunctionType => "`#[start]` function has the correct type",
LangFunctionType(_) => "lang item function has the correct type",
Expand All @@ -2932,9 +2929,6 @@ impl IntoDiagnosticArg for ObligationCauseAsDiagArg<'_> {
CompareImplItemObligation { kind: ty::AssocKind::Fn, .. } => "method_compat",
CompareImplItemObligation { kind: ty::AssocKind::Type, .. } => "type_compat",
CompareImplItemObligation { kind: ty::AssocKind::Const, .. } => "const_compat",
ExprAssignable => "expr_assignable",
IfExpression { .. } => "if_else_different",
IfExpressionWithNoElse => "no_else",
MainFunctionType => "fn_main_correct_type",
StartFunctionType => "fn_start_correct_type",
LangFunctionType(_) => "fn_lang_correct_type",
Expand Down
15 changes: 2 additions & 13 deletions compiler/rustc_middle/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,6 @@ pub enum ObligationCauseCode<'tcx> {
/// A tuple is WF only if its middle elements are `Sized`.
TupleElem,

/// This is the trait reference from the given projection.
ProjectionWf(ty::AliasTy<'tcx>),

/// Must satisfy all of the where-clause predicates of the
/// given item.
ItemObligation(DefId),
Expand Down Expand Up @@ -343,7 +340,8 @@ pub enum ObligationCauseCode<'tcx> {
parent_code: InternedObligationCauseCode<'tcx>,
},

/// Error derived when matching traits/impls; see ObligationCause for more details
/// Error derived when checking an impl item is compatible with
/// its corresponding trait item's definition
CompareImplItemObligation {
impl_item_def_id: LocalDefId,
trait_item_def_id: DefId,
Expand Down Expand Up @@ -372,9 +370,6 @@ pub enum ObligationCauseCode<'tcx> {
origin_expr: bool,
},

/// Constants in patterns must have `Structural` type.
ConstPatternStructural,

/// Computing common supertype in an if expression
IfExpression(Box<IfExpressionCause<'tcx>>),

Expand Down Expand Up @@ -407,9 +402,6 @@ pub enum ObligationCauseCode<'tcx> {
/// `return` with an expression
ReturnValue(hir::HirId),

/// Return type of this function
ReturnType,

/// Opaque return type of this function
OpaqueReturnType(Option<(Ty<'tcx>, Span)>),

Expand All @@ -419,9 +411,6 @@ pub enum ObligationCauseCode<'tcx> {
/// #[feature(trivial_bounds)] is not enabled
TrivialBound,

/// If `X` is the concrete type of an opaque type `impl Y`, then `X` must implement `Y`
OpaqueType,

AwaitableExpr(hir::HirId),

ForLoopIterator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2592,11 +2592,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
| ObligationCauseCode::MethodReceiver
| ObligationCauseCode::ReturnNoExpression
| ObligationCauseCode::UnifyReceiver(..)
| ObligationCauseCode::OpaqueType
| ObligationCauseCode::MiscObligation
| ObligationCauseCode::WellFormed(..)
| ObligationCauseCode::MatchImpl(..)
| ObligationCauseCode::ReturnType
| ObligationCauseCode::ReturnValue(_)
| ObligationCauseCode::BlockTailExpression(..)
| ObligationCauseCode::AwaitableExpr(_)
Expand All @@ -2607,7 +2605,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
| ObligationCauseCode::BinOp { .. }
| ObligationCauseCode::AscribeUserTypeProvePredicate(..)
| ObligationCauseCode::DropImpl
| ObligationCauseCode::ConstParam(_) => {}
| ObligationCauseCode::ConstParam(_)
| ObligationCauseCode::ReferenceOutlivesReferent(..)
| ObligationCauseCode::ObjectTypeBound(..) => {}
ObligationCauseCode::RustCall => {
if let Some(pred) = predicate.to_opt_poly_trait_pred()
&& Some(pred.def_id()) == self.tcx.lang_items().sized_trait()
Expand All @@ -2621,19 +2621,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
ObligationCauseCode::TupleElem => {
err.note("only the last element of a tuple may have a dynamically sized type");
}
ObligationCauseCode::ProjectionWf(data) => {
err.note(format!("required so that the projection `{data}` is well-formed"));
}
ObligationCauseCode::ReferenceOutlivesReferent(ref_ty) => {
err.note(format!(
"required so that reference `{ref_ty}` does not outlive its referent"
));
}
ObligationCauseCode::ObjectTypeBound(object_ty, region) => {
err.note(format!(
"required so that the lifetime bound of `{region}` for `{object_ty}` is satisfied",
));
}
ObligationCauseCode::ItemObligation(_)
| ObligationCauseCode::ExprItemObligation(..) => {
// We hold the `DefId` of the item introducing the obligation, but displaying it
Expand Down Expand Up @@ -2985,9 +2972,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
"all values live across `{what}` must have a statically known size"
));
}
ObligationCauseCode::ConstPatternStructural => {
err.note("constants used for pattern-matching must derive `PartialEq` and `Eq`");
}
ObligationCauseCode::SharedStatic => {
err.note("shared static variables must have a type that implements `Sync`");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,6 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
| ObligationCauseCode::ExprItemObligation(..)
| ObligationCauseCode::ExprBindingObligation(..)
| ObligationCauseCode::Coercion { .. }
| ObligationCauseCode::OpaqueType
);

// constrain inference variables a bit more to nested obligations from normalize so
Expand Down

0 comments on commit f4b7f35

Please sign in to comment.