@@ -615,7 +615,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
615
615
) ] ;
616
616
617
617
let mut has_unsized_tuple_coercion = false ;
618
- let mut has_trait_upcasting_coercion = false ;
618
+ let mut has_trait_upcasting_coercion = None ;
619
619
620
620
// Keep resolving `CoerceUnsized` and `Unsize` predicates to avoid
621
621
// emitting a coercion in cases like `Foo<$1>` -> `Foo<$2>`, where
@@ -635,7 +635,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
635
635
&& data_a. principal_def_id ( ) != data_b. principal_def_id ( )
636
636
{
637
637
debug ! ( "coerce_unsized: found trait upcasting coercion" ) ;
638
- has_trait_upcasting_coercion = true ;
638
+ has_trait_upcasting_coercion = Some ( ( self_ty , unsize_ty ) ) ;
639
639
}
640
640
if let ty:: Tuple ( ..) = unsize_ty. kind ( ) {
641
641
debug ! ( "coerce_unsized: found unsized tuple coercion" ) ;
@@ -706,14 +706,19 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
706
706
. emit ( ) ;
707
707
}
708
708
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 (
711
715
& self . tcx . sess . parse_sess ,
712
716
sym:: trait_upcasting,
713
717
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 ( ) ;
717
722
}
718
723
719
724
Ok ( coercion)
0 commit comments