Skip to content

Commit f3c13bf

Browse files
committed
Allow casting *mut dyn T->*mut (dyn T + Send) if T has Send super trait
1 parent 073f3a2 commit f3c13bf

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

compiler/rustc_hir_typeck/src/cast.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -869,9 +869,16 @@ impl<'a, 'tcx> CastCheck<'tcx> {
869869
// `dyn Src = dyn Dst`, this checks for matching traits/generics
870870
fcx.demand_eqtype(self.span, src_obj, dst_obj);
871871

872-
// Check that `SrcAuto` is a superset of `DstAuto`.
872+
// Check that `SrcAuto` (+auto traits implied by `Src`) is a superset of `DstAuto`.
873873
// Emit an FCW otherwise.
874-
let src_auto = src_tty.auto_traits().collect::<FxHashSet<_>>();
874+
let src_auto: FxHashSet<_> = src_tty
875+
.auto_traits()
876+
.chain(
877+
tcx.supertrait_def_ids(src_principal.def_id())
878+
.filter(|def_id| tcx.trait_is_auto(*def_id)),
879+
)
880+
.collect();
881+
875882
let added = dst_tty
876883
.auto_traits()
877884
.filter(|trait_did| !src_auto.contains(trait_did))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@ check-pass
2+
3+
trait Trait: Send {}
4+
impl Trait for () {}
5+
6+
fn main() {
7+
// This is OK: `Trait` has `Send` super trait.
8+
&() as *const dyn Trait as *const (dyn Trait + Send);
9+
}

0 commit comments

Comments
 (0)