about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2023-08-15 14:29:48 +0200
committerGitHub <noreply@github.com>2023-08-15 14:29:48 +0200
commite4b9e72e58a8a5987bd391aa8c7bf7008c2c9e2e (patch)
treef5eb2fb833d285f89c5a6a929f4d16083801dd30
parent0e7f9e576f8980cd7e8bdb1a145b535992b17945 (diff)
parente8ab56fbb4be702e3f31afb257ace2498434c30b (diff)
downloadrust-e4b9e72e58a8a5987bd391aa8c7bf7008c2c9e2e.tar.gz
rust-e4b9e72e58a8a5987bd391aa8c7bf7008c2c9e2e.zip
Rollup merge of #114827 - compiler-errors:next-solver-dyn-safe-candidates, r=lcnr
Only consider object candidates for object-safe dyn types in new solver

We apparently allow this per RFC2027 :skull:

r? lcnr
-rw-r--r--compiler/rustc_trait_selection/src/solve/assembly/mod.rs5
-rw-r--r--tests/ui/rfcs/rfc-2027-object-safe-for-dispatch/manual-self-impl-for-unsafe-obj.rs2
2 files changed, 7 insertions, 0 deletions
diff --git a/compiler/rustc_trait_selection/src/solve/assembly/mod.rs b/compiler/rustc_trait_selection/src/solve/assembly/mod.rs
index 3750b3750bf..5bfa8348600 100644
--- a/compiler/rustc_trait_selection/src/solve/assembly/mod.rs
+++ b/compiler/rustc_trait_selection/src/solve/assembly/mod.rs
@@ -826,6 +826,11 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
             ty::Dynamic(bounds, ..) => bounds,
         };
 
+        // Do not consider built-in object impls for non-object-safe types.
+        if bounds.principal_def_id().is_some_and(|def_id| !tcx.check_is_object_safe(def_id)) {
+            return;
+        }
+
         // Consider all of the auto-trait and projection bounds, which don't
         // need to be recorded as a `BuiltinImplSource::Object` since they don't
         // really have a vtable base...
diff --git a/tests/ui/rfcs/rfc-2027-object-safe-for-dispatch/manual-self-impl-for-unsafe-obj.rs b/tests/ui/rfcs/rfc-2027-object-safe-for-dispatch/manual-self-impl-for-unsafe-obj.rs
index 721890db4fb..c27e8c4b019 100644
--- a/tests/ui/rfcs/rfc-2027-object-safe-for-dispatch/manual-self-impl-for-unsafe-obj.rs
+++ b/tests/ui/rfcs/rfc-2027-object-safe-for-dispatch/manual-self-impl-for-unsafe-obj.rs
@@ -1,5 +1,7 @@
 // Check that we can manually implement an object-unsafe trait for its trait object.
 
+// revisions: current next
+//[next] compile-flags: -Ztrait-solver=next
 // run-pass
 
 #![feature(object_safe_for_dispatch)]