about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-04-17 10:48:20 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-05-23 16:02:24 +0000
commit4387eea7f76e82d6f6050df99196c15d53b4914a (patch)
tree13e4ae81eb7106b610471a2c03b1d731d3e3d384
parent7f292f41a0c6c5ebbc915d487dd49741f9982684 (diff)
downloadrust-4387eea7f76e82d6f6050df99196c15d53b4914a.tar.gz
rust-4387eea7f76e82d6f6050df99196c15d53b4914a.zip
Support constraining opaque types while trait upcasting with binders
-rw-r--r--compiler/rustc_trait_selection/src/traits/select/mod.rs2
-rw-r--r--tests/ui/traits/trait-upcasting/type-checking-test-opaques.rs3
-rw-r--r--tests/ui/traits/trait-upcasting/type-checking-test-opaques.stderr9
3 files changed, 3 insertions, 11 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs
index ee4b81b046f..696b1c15115 100644
--- a/compiler/rustc_trait_selection/src/traits/select/mod.rs
+++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs
@@ -2594,7 +2594,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
                         self.infcx
                             .at(&obligation.cause, obligation.param_env)
                             .eq(
-                                DefineOpaqueTypes::No,
+                                DefineOpaqueTypes::Yes,
                                 upcast_principal.map_bound(|trait_ref| {
                                     ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref)
                                 }),
diff --git a/tests/ui/traits/trait-upcasting/type-checking-test-opaques.rs b/tests/ui/traits/trait-upcasting/type-checking-test-opaques.rs
index edad62fa4db..a3a1ce29465 100644
--- a/tests/ui/traits/trait-upcasting/type-checking-test-opaques.rs
+++ b/tests/ui/traits/trait-upcasting/type-checking-test-opaques.rs
@@ -1,5 +1,7 @@
 #![feature(trait_upcasting, type_alias_impl_trait)]
 
+//@ check-pass
+
 type Tait = impl Sized;
 
 trait Foo<'a>: Bar<'a, 'a, Tait> {}
@@ -15,7 +17,6 @@ fn test_correct2<'a>(x: &dyn Foo<'a>) {
 
 fn test_correct3<'a>(x: &dyn Foo<'a>, _: Tait) {
     let _ = x as &dyn Bar<'_, '_, ()>;
-    //~^ ERROR: non-primitive cast
 }
 
 fn main() {}
diff --git a/tests/ui/traits/trait-upcasting/type-checking-test-opaques.stderr b/tests/ui/traits/trait-upcasting/type-checking-test-opaques.stderr
deleted file mode 100644
index b2982f581ea..00000000000
--- a/tests/ui/traits/trait-upcasting/type-checking-test-opaques.stderr
+++ /dev/null
@@ -1,9 +0,0 @@
-error[E0605]: non-primitive cast: `&dyn Foo<'a>` as `&dyn Bar<'_, '_, ()>`
-  --> $DIR/type-checking-test-opaques.rs:17:13
-   |
-LL |     let _ = x as &dyn Bar<'_, '_, ()>;
-   |             ^^^^^^^^^^^^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
-
-error: aborting due to 1 previous error
-
-For more information about this error, try `rustc --explain E0605`.