Allow casting *mut dyn T
->*mut (dyn T + Send)
if T
has Send
super trait
This commit is contained in:
parent
073f3a263b
commit
f3c13bf280
@ -869,9 +869,16 @@ fn check_ptr_ptr_cast(
|
||||
// `dyn Src = dyn Dst`, this checks for matching traits/generics
|
||||
fcx.demand_eqtype(self.span, src_obj, dst_obj);
|
||||
|
||||
// Check that `SrcAuto` is a superset of `DstAuto`.
|
||||
// Check that `SrcAuto` (+auto traits implied by `Src`) is a superset of `DstAuto`.
|
||||
// Emit an FCW otherwise.
|
||||
let src_auto = src_tty.auto_traits().collect::<FxHashSet<_>>();
|
||||
let src_auto: FxHashSet<_> = src_tty
|
||||
.auto_traits()
|
||||
.chain(
|
||||
tcx.supertrait_def_ids(src_principal.def_id())
|
||||
.filter(|def_id| tcx.trait_is_auto(*def_id)),
|
||||
)
|
||||
.collect();
|
||||
|
||||
let added = dst_tty
|
||||
.auto_traits()
|
||||
.filter(|trait_did| !src_auto.contains(trait_did))
|
||||
|
9
tests/ui/cast/ptr-to-trait-obj-add-super-auto.rs
Normal file
9
tests/ui/cast/ptr-to-trait-obj-add-super-auto.rs
Normal file
@ -0,0 +1,9 @@
|
||||
//@ check-pass
|
||||
|
||||
trait Trait: Send {}
|
||||
impl Trait for () {}
|
||||
|
||||
fn main() {
|
||||
// This is OK: `Trait` has `Send` super trait.
|
||||
&() as *const dyn Trait as *const (dyn Trait + Send);
|
||||
}
|
Loading…
Reference in New Issue
Block a user