summaryrefslogtreecommitdiffstats
path: root/tests/ui/dst/dst-bad-coerce1.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/dst/dst-bad-coerce1.rs
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/dst/dst-bad-coerce1.rs')
-rw-r--r--tests/ui/dst/dst-bad-coerce1.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/ui/dst/dst-bad-coerce1.rs b/tests/ui/dst/dst-bad-coerce1.rs
new file mode 100644
index 000000000..7ef237e39
--- /dev/null
+++ b/tests/ui/dst/dst-bad-coerce1.rs
@@ -0,0 +1,36 @@
+// Attempt to change the type as well as unsizing.
+
+#![feature(unsized_tuple_coercion)]
+
+struct Fat<T: ?Sized> {
+ ptr: T
+}
+
+struct Foo;
+trait Bar { fn bar(&self) {} }
+
+pub fn main() {
+ // With a vec of isize.
+ let f1 = Fat { ptr: [1, 2, 3] };
+ let f2: &Fat<[isize; 3]> = &f1;
+ let f3: &Fat<[usize]> = f2;
+ //~^ ERROR mismatched types
+
+ // With a trait.
+ let f1 = Fat { ptr: Foo };
+ let f2: &Fat<Foo> = &f1;
+ let f3: &Fat<dyn Bar> = f2;
+ //~^ ERROR `Foo: Bar` is not satisfied
+
+ // Tuple with a vec of isize.
+ let f1 = ([1, 2, 3],);
+ let f2: &([isize; 3],) = &f1;
+ let f3: &([usize],) = f2;
+ //~^ ERROR mismatched types
+
+ // Tuple with a trait.
+ let f1 = (Foo,);
+ let f2: &(Foo,) = &f1;
+ let f3: &(dyn Bar,) = f2;
+ //~^ ERROR `Foo: Bar` is not satisfied
+}