@@ -615,7 +615,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
615615 ) ] ;
616616
617617 let mut has_unsized_tuple_coercion = false ;
618- let mut has_trait_upcasting_coercion = false ;
618+ let mut has_trait_upcasting_coercion = None ;
619619
620620 // Keep resolving `CoerceUnsized` and `Unsize` predicates to avoid
621621 // emitting a coercion in cases like `Foo<$1>` -> `Foo<$2>`, where
@@ -635,7 +635,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
635635 && data_a. principal_def_id ( ) != data_b. principal_def_id ( )
636636 {
637637 debug ! ( "coerce_unsized: found trait upcasting coercion" ) ;
638- has_trait_upcasting_coercion = true ;
638+ has_trait_upcasting_coercion = Some ( ( self_ty , unsize_ty ) ) ;
639639 }
640640 if let ty:: Tuple ( ..) = unsize_ty. kind ( ) {
641641 debug ! ( "coerce_unsized: found unsized tuple coercion" ) ;
@@ -706,14 +706,19 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
706706 . emit ( ) ;
707707 }
708708
709- if has_trait_upcasting_coercion && !self . tcx ( ) . features ( ) . trait_upcasting {
710- feature_err (
709+ if let Some ( ( sub, sup) ) = has_trait_upcasting_coercion
710+ && !self . tcx ( ) . features ( ) . trait_upcasting
711+ {
712+ // Renders better when we erase regions, since they're not really the point here.
713+ let ( sub, sup) = self . tcx . erase_regions ( ( sub, sup) ) ;
714+ let mut err = feature_err (
711715 & self . tcx . sess . parse_sess ,
712716 sym:: trait_upcasting,
713717 self . cause . span ,
714- "trait upcasting coercion is experimental" ,
715- )
716- . emit ( ) ;
718+ & format ! ( "cannot cast `{sub}` to `{sup}`, trait upcasting coercion is experimental" ) ,
719+ ) ;
720+ err. note ( & format ! ( "required when coercing `{source}` into `{target}`" ) ) ;
721+ err. emit ( ) ;
717722 }
718723
719724 Ok ( coercion)
0 commit comments