@@ -876,20 +876,14 @@ impl<'a, 'tcx> CastCheck<'tcx> {
876
876
// A<dyn Src<...> + SrcAuto> -> B<dyn Dst<...> + DstAuto>. need to make sure
877
877
// - `Src` and `Dst` traits are the same
878
878
// - traits have the same generic arguments
879
- // - `SrcAuto` is a superset of `DstAuto`
880
- ( Some ( src_principal) , Some ( dst_principal) ) => {
879
+ // - projections are the same
880
+ // - `SrcAuto` (+auto traits implied by `Src`) is a superset of `DstAuto`
881
+ //
882
+ // Note that trait upcasting goes through a different mechanism (`coerce_unsized`)
883
+ // and is unaffected by this check.
884
+ ( Some ( src_principal) , Some ( _) ) => {
881
885
let tcx = fcx. tcx ;
882
886
883
- // Check that the traits are actually the same.
884
- // The `dyn Src = dyn Dst` check below would suffice,
885
- // but this may produce a better diagnostic.
886
- //
887
- // Note that trait upcasting goes through a different mechanism (`coerce_unsized`)
888
- // and is unaffected by this check.
889
- if src_principal. def_id ( ) != dst_principal. def_id ( ) {
890
- return Err ( CastError :: DifferingKinds { src_kind, dst_kind } ) ;
891
- }
892
-
893
887
// We need to reconstruct trait object types.
894
888
// `m_src` and `m_dst` won't work for us here because they will potentially
895
889
// contain wrappers, which we do not care about.
@@ -912,8 +906,8 @@ impl<'a, 'tcx> CastCheck<'tcx> {
912
906
ty:: Dyn ,
913
907
) ) ;
914
908
915
- // `dyn Src = dyn Dst`, this checks for matching traits/generics
916
- // This is `demand_eqtype`, but inlined to give a better error.
909
+ // `dyn Src = dyn Dst`, this checks for matching traits/generics/projections
910
+ // This is `fcx. demand_eqtype`, but inlined to give a better error.
917
911
let cause = fcx. misc ( self . span ) ;
918
912
if fcx
919
913
. at ( & cause, fcx. param_env )
0 commit comments