about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_hir_typeck/src/cast.rs11
-rw-r--r--tests/ui/cast/ptr-to-trait-obj-add-super-auto.rs9
2 files changed, 18 insertions, 2 deletions
diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs
index 7b27a4b3ba7..57175f11baf 100644
--- a/compiler/rustc_hir_typeck/src/cast.rs
+++ b/compiler/rustc_hir_typeck/src/cast.rs
@@ -869,9 +869,16 @@ impl<'a, 'tcx> CastCheck<'tcx> {
                         // `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))
diff --git a/tests/ui/cast/ptr-to-trait-obj-add-super-auto.rs b/tests/ui/cast/ptr-to-trait-obj-add-super-auto.rs
new file mode 100644
index 00000000000..ac8108d8ec4
--- /dev/null
+++ b/tests/ui/cast/ptr-to-trait-obj-add-super-auto.rs
@@ -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);
+}