Skip to content

Commit b89751b

Browse files
author
Lukas Markeffsky
committed
clean up *dyn casts (with principals)
- remove a redundant check, because we always emit the "better diagnostic" now - clean up the comments a bit
1 parent 1350eea commit b89751b

File tree

1 file changed

+8
-14
lines changed
  • compiler/rustc_hir_typeck/src

1 file changed

+8
-14
lines changed

Diff for: compiler/rustc_hir_typeck/src/cast.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -876,20 +876,14 @@ impl<'a, 'tcx> CastCheck<'tcx> {
876876
// A<dyn Src<...> + SrcAuto> -> B<dyn Dst<...> + DstAuto>. need to make sure
877877
// - `Src` and `Dst` traits are the same
878878
// - 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(_)) => {
881885
let tcx = fcx.tcx;
882886

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-
893887
// We need to reconstruct trait object types.
894888
// `m_src` and `m_dst` won't work for us here because they will potentially
895889
// contain wrappers, which we do not care about.
@@ -912,8 +906,8 @@ impl<'a, 'tcx> CastCheck<'tcx> {
912906
ty::Dyn,
913907
));
914908

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.
917911
let cause = fcx.misc(self.span);
918912
if fcx
919913
.at(&cause, fcx.param_env)

0 commit comments

Comments
 (0)