Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ccd8ad7

Browse files
committedMay 11, 2023
Note base types of coercion
1 parent 9a767b6 commit ccd8ad7

File tree

64 files changed

+140
-223
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+140
-223
lines changed
 

‎compiler/rustc_middle/src/traits/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,6 @@ pub enum ObligationCauseCode<'tcx> {
281281
/// A type like `Box<Foo<'a> + 'b>` is WF only if `'b: 'a`.
282282
ObjectTypeBound(Ty<'tcx>, ty::Region<'tcx>),
283283

284-
/// Obligation incurred due to an object cast.
285-
ObjectCastObligation(/* Concrete type */ Ty<'tcx>, /* Object type */ Ty<'tcx>),
286-
287284
/// Obligation incurred due to a coercion.
288285
Coercion {
289286
source: Ty<'tcx>,

‎compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -796,9 +796,17 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
796796
err.span_label(span, explanation);
797797
}
798798

799-
if let ObligationCauseCode::ObjectCastObligation(concrete_ty, obj_ty) = obligation.cause.code().peel_derives() &&
800-
Some(trait_ref.def_id()) == self.tcx.lang_items().sized_trait() {
801-
self.suggest_borrowing_for_object_cast(&mut err, &root_obligation, *concrete_ty, *obj_ty);
799+
if let ObligationCauseCode::Coercion { source, target } =
800+
*obligation.cause.code().peel_derives()
801+
{
802+
if Some(trait_ref.def_id()) == self.tcx.lang_items().sized_trait() {
803+
self.suggest_borrowing_for_object_cast(
804+
&mut err,
805+
&root_obligation,
806+
source,
807+
target,
808+
);
809+
}
802810
}
803811

804812
let UnsatisfiedConst(unsatisfied_const) = self
@@ -1505,7 +1513,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
15051513
| ObligationCauseCode::BindingObligation(_, _)
15061514
| ObligationCauseCode::ExprItemObligation(..)
15071515
| ObligationCauseCode::ExprBindingObligation(..)
1508-
| ObligationCauseCode::ObjectCastObligation(..)
1516+
| ObligationCauseCode::Coercion { .. }
15091517
| ObligationCauseCode::OpaqueType
15101518
);
15111519

0 commit comments

Comments
 (0)
Please sign in to comment.