@@ -1586,6 +1586,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1586
1586
}
1587
1587
if let Some ( exp_found) = exp_found {
1588
1588
self . suggest_as_ref_where_appropriate ( span, & exp_found, diag) ;
1589
+
1590
+ if let & TypeError :: Traits ( ref exp_found_traits) = terr {
1591
+ self . note_enable_trait_upcasting_where_appropriate (
1592
+ & exp_found_traits, diag
1593
+ ) ;
1594
+ }
1589
1595
}
1590
1596
1591
1597
// In some (most?) cases cause.body_id points to actual body, but in some cases
@@ -1666,6 +1672,22 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1666
1672
}
1667
1673
}
1668
1674
1675
+ /// When encountering a coercion to a supertrait object is attempted,
1676
+ /// note that this is permitted with the "trait upcasting" feature enabled.
1677
+ fn note_enable_trait_upcasting_where_appropriate (
1678
+ & self ,
1679
+ exp_found : & ty:: error:: ExpectedFound < DefId > ,
1680
+ diag : & mut DiagnosticBuilder < ' tcx > ,
1681
+ ) {
1682
+ use rustc:: ty:: { Binder , TraitRef } ;
1683
+
1684
+ let trait_ref = Binder :: bind ( TraitRef :: identity ( self . tcx , exp_found. found ) ) ;
1685
+ let supertraits = crate :: traits:: supertraits ( self . tcx , trait_ref) ;
1686
+ if supertraits. into_iter ( ) . any ( |trait_ref| trait_ref. def_id ( ) == exp_found. expected ) {
1687
+ diag. note ( "enable the `trait_upcasting` feature to permit upcasting of trait objects" ) ;
1688
+ }
1689
+ }
1690
+
1669
1691
pub fn report_and_explain_type_error (
1670
1692
& self ,
1671
1693
trace : TypeTrace < ' tcx > ,
0 commit comments