about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2021-08-29 16:25:30 +0200
committerGitHub <noreply@github.com>2021-08-29 16:25:30 +0200
commitfdb4b7c46261c61847ce3dbe3d77c4f102041973 (patch)
treeaf6dc39e694ae37c90ac51bab508df8f62e68628
parent3e1a15bb12c203b42069dd06a3afa621e4b61567 (diff)
parentbee13d18af34ce6056a0b76fb7652cafda52cb69 (diff)
downloadrust-fdb4b7c46261c61847ce3dbe3d77c4f102041973.tar.gz
rust-fdb4b7c46261c61847ce3dbe3d77c4f102041973.zip
Rollup merge of #88357 - lcnr:stabilize-relaxed_struct_unsize, r=Mark-Simulacrum
add unsized coercion test

we had no tests in our test suite for this case
-rw-r--r--src/test/ui/unsized/param-mentioned-by-different-field.rs10
-rw-r--r--src/test/ui/unsized/param-mentioned-by-different-field.stderr14
2 files changed, 24 insertions, 0 deletions
diff --git a/src/test/ui/unsized/param-mentioned-by-different-field.rs b/src/test/ui/unsized/param-mentioned-by-different-field.rs
new file mode 100644
index 00000000000..cda94b306d3
--- /dev/null
+++ b/src/test/ui/unsized/param-mentioned-by-different-field.rs
@@ -0,0 +1,10 @@
+// We must not allow this with our current setup as `T`
+// is mentioned both in the tail of `Foo` and by another
+// field.
+struct Foo<T: ?Sized>(Box<T>, T);
+
+fn main() {
+    let x: Foo<[u8; 1]> = Foo(Box::new([2]), [3]);
+    let y: &Foo<[u8]> = &x; //~ ERROR mismatched types
+    assert_eq!(y.0.len(), 1);
+}
diff --git a/src/test/ui/unsized/param-mentioned-by-different-field.stderr b/src/test/ui/unsized/param-mentioned-by-different-field.stderr
new file mode 100644
index 00000000000..d18fa6456f3
--- /dev/null
+++ b/src/test/ui/unsized/param-mentioned-by-different-field.stderr
@@ -0,0 +1,14 @@
+error[E0308]: mismatched types
+  --> $DIR/param-mentioned-by-different-field.rs:8:25
+   |
+LL |     let y: &Foo<[u8]> = &x;
+   |            ----------   ^^ expected slice `[u8]`, found array `[u8; 1]`
+   |            |
+   |            expected due to this
+   |
+   = note: expected reference `&Foo<[u8]>`
+              found reference `&Foo<[u8; 1]>`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.