@@ -257,6 +257,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
257257 match self . get_safe_transmute_error_and_reason (
258258 obligation. clone ( ) ,
259259 main_trait_predicate,
260+ root_obligation,
260261 span,
261262 ) {
262263 GetSafeTransmuteErrorAndReason :: Silent => {
@@ -2797,6 +2798,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
27972798 & self ,
27982799 obligation : PredicateObligation < ' tcx > ,
27992800 trait_pred : ty:: PolyTraitPredicate < ' tcx > ,
2801+ root_obligation : & PredicateObligation < ' tcx > ,
28002802 span : Span ,
28012803 ) -> GetSafeTransmuteErrorAndReason {
28022804 use rustc_transmute:: Answer ;
@@ -2913,11 +2915,28 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
29132915 safe_transmute_explanation : Some ( safe_transmute_explanation) ,
29142916 }
29152917 }
2916- // Should never get a Yes at this point! We already ran it before, and did not get a Yes.
2917- Answer :: Yes => span_bug ! (
2918- span,
2919- "Inconsistent rustc_transmute::is_transmutable(...) result, got Yes" ,
2920- ) ,
2918+ // The normalized types pass, but the original check failed.
2919+ // This can happen when type aliases were normalized for diagnostics.
2920+ // Retry with root_obligation's types to get the real error.
2921+ Answer :: Yes => {
2922+ if obligation. predicate != root_obligation. predicate {
2923+ if let ty:: PredicateKind :: Clause ( ty:: ClauseKind :: Trait ( root_pred) ) =
2924+ root_obligation. predicate . kind ( ) . skip_binder ( )
2925+ && root_pred. def_id ( ) == trait_pred. trait_ref . def_id
2926+ {
2927+ return self . get_safe_transmute_error_and_reason (
2928+ root_obligation. clone ( ) ,
2929+ root_obligation. predicate . kind ( ) . rebind ( root_pred) ,
2930+ root_obligation,
2931+ span,
2932+ ) ;
2933+ }
2934+ }
2935+ span_bug ! (
2936+ span,
2937+ "Inconsistent rustc_transmute::is_transmutable(...) result, got Yes" ,
2938+ )
2939+ }
29212940 // Reached when a different obligation (namely `Freeze`) causes the
29222941 // transmutability analysis to fail. In this case, silence the
29232942 // transmutability error message in favor of that more specific
0 commit comments