about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-05-24 13:41:20 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-06-19 08:28:31 +0000
commit4dcb70b8cf3a12bb3bf0ef38cd05e6ab3720402c (patch)
tree303c206f9ad2e8b64d5b0a53d31a0b9eb2f8f8c4
parent9889a6f5d3f07eb2c8480060f46d5c0e710bba8e (diff)
downloadrust-4dcb70b8cf3a12bb3bf0ef38cd05e6ab3720402c.tar.gz
rust-4dcb70b8cf3a12bb3bf0ef38cd05e6ab3720402c.zip
Allow constraining opaque types during unsizing
-rw-r--r--compiler/rustc_trait_selection/src/traits/select/confirmation.rs6
-rw-r--r--tests/ui/impl-trait/unsize_adt.rs5
-rw-r--r--tests/ui/impl-trait/unsize_adt.stderr17
-rw-r--r--tests/ui/impl-trait/unsize_slice.rs5
-rw-r--r--tests/ui/impl-trait/unsize_slice.stderr17
-rw-r--r--tests/ui/impl-trait/unsize_tuple.rs5
-rw-r--r--tests/ui/impl-trait/unsize_tuple.stderr17
7 files changed, 12 insertions, 60 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs
index af599108c49..84c744be381 100644
--- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs
+++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs
@@ -1228,7 +1228,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
                 let InferOk { obligations, .. } = self
                     .infcx
                     .at(&obligation.cause, obligation.param_env)
-                    .eq(DefineOpaqueTypes::No, b, a)
+                    .eq(DefineOpaqueTypes::Yes, b, a)
                     .map_err(|_| Unimplemented)?;
 
                 ImplSource::Builtin(BuiltinImplSource::Misc, obligations)
@@ -1276,7 +1276,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
                 let InferOk { obligations, .. } = self
                     .infcx
                     .at(&obligation.cause, obligation.param_env)
-                    .eq(DefineOpaqueTypes::No, target, new_struct)
+                    .eq(DefineOpaqueTypes::Yes, target, new_struct)
                     .map_err(|_| Unimplemented)?;
                 nested.extend(obligations);
 
@@ -1309,7 +1309,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
                 let InferOk { mut obligations, .. } = self
                     .infcx
                     .at(&obligation.cause, obligation.param_env)
-                    .eq(DefineOpaqueTypes::No, target, new_tuple)
+                    .eq(DefineOpaqueTypes::Yes, target, new_tuple)
                     .map_err(|_| Unimplemented)?;
 
                 // Add a nested `T: Unsize<U>` predicate.
diff --git a/tests/ui/impl-trait/unsize_adt.rs b/tests/ui/impl-trait/unsize_adt.rs
index fce5094bd40..825384b61e8 100644
--- a/tests/ui/impl-trait/unsize_adt.rs
+++ b/tests/ui/impl-trait/unsize_adt.rs
@@ -1,4 +1,6 @@
-//! Test that we do not allow unsizing `Foo<[Opaque; N]>` to `Foo<[Concrete]>`.
+//! Test that we allow unsizing `Foo<[Opaque; N]>` to `Foo<[Concrete]>`.
+
+//@check-pass
 
 struct Foo<T: ?Sized>(T);
 
@@ -6,7 +8,6 @@ fn hello() -> Foo<[impl Sized; 2]> {
     if false {
         let x = hello();
         let _: &Foo<[i32]> = &x;
-        //~^ ERROR: mismatched types
     }
     todo!()
 }
diff --git a/tests/ui/impl-trait/unsize_adt.stderr b/tests/ui/impl-trait/unsize_adt.stderr
deleted file mode 100644
index 2b93b4a571b..00000000000
--- a/tests/ui/impl-trait/unsize_adt.stderr
+++ /dev/null
@@ -1,17 +0,0 @@
-error[E0308]: mismatched types
-  --> $DIR/unsize_adt.rs:8:30
-   |
-LL | fn hello() -> Foo<[impl Sized; 2]> {
-   |                    ---------- the found opaque type
-...
-LL |         let _: &Foo<[i32]> = &x;
-   |                -----------   ^^ expected `&Foo<[i32]>`, found `&Foo<[impl Sized; 2]>`
-   |                |
-   |                expected due to this
-   |
-   = note: expected reference `&Foo<[i32]>`
-              found reference `&Foo<[impl Sized; 2]>`
-
-error: aborting due to 1 previous error
-
-For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/impl-trait/unsize_slice.rs b/tests/ui/impl-trait/unsize_slice.rs
index ec0f1626564..b0cf1c7ca6d 100644
--- a/tests/ui/impl-trait/unsize_slice.rs
+++ b/tests/ui/impl-trait/unsize_slice.rs
@@ -1,10 +1,11 @@
-//! Test that we do not allow unsizing `[Opaque; N]` to `[Concrete]`.
+//! Test that we allow unsizing `[Opaque; N]` to `[Concrete]`.
+
+//@check-pass
 
 fn hello() -> [impl Sized; 2] {
     if false {
         let x = hello();
         let _: &[i32] = &x;
-        //~^ ERROR: mismatched types
     }
     todo!()
 }
diff --git a/tests/ui/impl-trait/unsize_slice.stderr b/tests/ui/impl-trait/unsize_slice.stderr
deleted file mode 100644
index 6a7fdb46163..00000000000
--- a/tests/ui/impl-trait/unsize_slice.stderr
+++ /dev/null
@@ -1,17 +0,0 @@
-error[E0308]: mismatched types
-  --> $DIR/unsize_slice.rs:6:25
-   |
-LL | fn hello() -> [impl Sized; 2] {
-   |                ---------- the found opaque type
-...
-LL |         let _: &[i32] = &x;
-   |                ------   ^^ expected `&[i32]`, found `&[impl Sized; 2]`
-   |                |
-   |                expected due to this
-   |
-   = note: expected reference `&[i32]`
-              found reference `&[impl Sized; 2]`
-
-error: aborting due to 1 previous error
-
-For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/impl-trait/unsize_tuple.rs b/tests/ui/impl-trait/unsize_tuple.rs
index 630b8fd430f..2678564f0e8 100644
--- a/tests/ui/impl-trait/unsize_tuple.rs
+++ b/tests/ui/impl-trait/unsize_tuple.rs
@@ -1,4 +1,6 @@
-//! Test that we do not allow unsizing `([Opaque; N],)` to `([Concrete],)`.
+//! Test that we allow unsizing `([Opaque; N],)` to `([Concrete],)`.
+
+//@check-pass
 
 #![feature(unsized_tuple_coercion)]
 
@@ -6,7 +8,6 @@ fn hello() -> ([impl Sized; 2],) {
     if false {
         let x = hello();
         let _: &([i32],) = &x;
-        //~^ ERROR: mismatched types
     }
     todo!()
 }
diff --git a/tests/ui/impl-trait/unsize_tuple.stderr b/tests/ui/impl-trait/unsize_tuple.stderr
deleted file mode 100644
index 8d3cf15887c..00000000000
--- a/tests/ui/impl-trait/unsize_tuple.stderr
+++ /dev/null
@@ -1,17 +0,0 @@
-error[E0308]: mismatched types
-  --> $DIR/unsize_tuple.rs:8:28
-   |
-LL | fn hello() -> ([impl Sized; 2],) {
-   |                 ---------- the found opaque type
-...
-LL |         let _: &([i32],) = &x;
-   |                ---------   ^^ expected `&([i32],)`, found `&([impl Sized; 2],)`
-   |                |
-   |                expected due to this
-   |
-   = note: expected reference `&([i32],)`
-              found reference `&([impl Sized; 2],)`
-
-error: aborting due to 1 previous error
-
-For more information about this error, try `rustc --explain E0308`.