Skip to content

Commit eac4916

Browse files
committed
Disallow dyn Trait -> dyn Auto back
I think it's fine, but let's ask T-lang separately.
1 parent bb651d3 commit eac4916

File tree

1 file changed

+16
-6
lines changed
  • compiler/rustc_hir_typeck/src

1 file changed

+16
-6
lines changed

compiler/rustc_hir_typeck/src/cast.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -840,8 +840,16 @@ impl<'a, 'tcx> CastCheck<'tcx> {
840840
// contain wrappers, which we do not care about.
841841
//
842842
// e.g. we want to allow `dyn T -> (dyn T,)`, etc.
843-
let src_obj = tcx.mk_ty_from_kind(ty::Dynamic(src_tty, tcx.lifetimes.re_erased, ty::Dyn));
844-
let dst_obj = tcx.mk_ty_from_kind(ty::Dynamic(dst_tty, tcx.lifetimes.re_erased, ty::Dyn));
843+
let src_obj = tcx.mk_ty_from_kind(ty::Dynamic(
844+
src_tty,
845+
tcx.lifetimes.re_erased,
846+
ty::Dyn,
847+
));
848+
let dst_obj = tcx.mk_ty_from_kind(ty::Dynamic(
849+
dst_tty,
850+
tcx.lifetimes.re_erased,
851+
ty::Dyn,
852+
));
845853

846854
// `dyn Src: Unsize<dyn Dst>`
847855
let cause = fcx.misc(self.span);
@@ -853,7 +861,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
853861
tcx,
854862
tcx.require_lang_item(LangItem::Unsize, Some(self.span)),
855863
[src_obj, dst_obj],
856-
)
864+
),
857865
);
858866

859867
fcx.register_predicate(obligation);
@@ -866,9 +874,11 @@ impl<'a, 'tcx> CastCheck<'tcx> {
866874
}
867875

868876
// dyn Auto -> dyn Auto'? ok.
869-
(None, None)
870-
// dyn Trait -> dyn Auto? ok.
871-
| (Some(_), None)=> Ok(CastKind::PtrPtrCast),
877+
(None, None) => Ok(CastKind::PtrPtrCast),
878+
879+
// dyn Trait -> dyn Auto? should be ok, but we used to not allow it.
880+
// FIXME: allow this
881+
(Some(_), None) => Err(CastError::DifferingKinds),
872882

873883
// dyn Auto -> dyn Trait? not ok.
874884
(None, Some(_)) => Err(CastError::DifferingKinds),

0 commit comments

Comments
 (0)