summaryrefslogtreecommitdiffstats
path: root/tests/ui/dst
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/dst')
-rw-r--r--tests/ui/dst/issue-90528-unsizing-suggestion-1.rs20
-rw-r--r--tests/ui/dst/issue-90528-unsizing-suggestion-1.stderr56
-rw-r--r--tests/ui/dst/issue-90528-unsizing-suggestion-2.rs28
-rw-r--r--tests/ui/dst/issue-90528-unsizing-suggestion-2.stderr94
-rw-r--r--tests/ui/dst/issue-90528-unsizing-suggestion-3.rs22
-rw-r--r--tests/ui/dst/issue-90528-unsizing-suggestion-3.stderr75
-rw-r--r--tests/ui/dst/issue-90528-unsizing-suggestion-4.rs26
-rw-r--r--tests/ui/dst/issue-90528-unsizing-suggestion-4.stderr79
8 files changed, 400 insertions, 0 deletions
diff --git a/tests/ui/dst/issue-90528-unsizing-suggestion-1.rs b/tests/ui/dst/issue-90528-unsizing-suggestion-1.rs
new file mode 100644
index 000000000..52863e22b
--- /dev/null
+++ b/tests/ui/dst/issue-90528-unsizing-suggestion-1.rs
@@ -0,0 +1,20 @@
+// Issue #90528: provide helpful suggestions when a trait bound is unsatisfied
+// due to a missed unsizing coercion.
+//
+// This test exercises array literals and a trait implemented on immutable slices.
+
+trait Read {}
+
+impl Read for &[u8] {}
+
+fn wants_read(_: impl Read) {}
+
+fn main() {
+ wants_read([0u8]);
+ //~^ ERROR the trait bound `[u8; 1]: Read` is not satisfied
+ wants_read(&[0u8]);
+ //~^ ERROR the trait bound `&[u8; 1]: Read` is not satisfied
+ wants_read(&[0u8][..]);
+ wants_read(&mut [0u8]);
+ //~^ ERROR the trait bound `&mut [u8; 1]: Read` is not satisfied
+}
diff --git a/tests/ui/dst/issue-90528-unsizing-suggestion-1.stderr b/tests/ui/dst/issue-90528-unsizing-suggestion-1.stderr
new file mode 100644
index 000000000..27ef3fe97
--- /dev/null
+++ b/tests/ui/dst/issue-90528-unsizing-suggestion-1.stderr
@@ -0,0 +1,56 @@
+error[E0277]: the trait bound `[u8; 1]: Read` is not satisfied
+ --> $DIR/issue-90528-unsizing-suggestion-1.rs:13:16
+ |
+LL | wants_read([0u8]);
+ | ---------- ^^^^^ the trait `Read` is not implemented for `[u8; 1]`
+ | |
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Read` is implemented for `&[u8]`
+note: required by a bound in `wants_read`
+ --> $DIR/issue-90528-unsizing-suggestion-1.rs:10:23
+ |
+LL | fn wants_read(_: impl Read) {}
+ | ^^^^ required by this bound in `wants_read`
+help: convert the array to a `&[u8]` slice instead
+ |
+LL | wants_read(&[0u8][..]);
+ | + ++++
+
+error[E0277]: the trait bound `&[u8; 1]: Read` is not satisfied
+ --> $DIR/issue-90528-unsizing-suggestion-1.rs:15:16
+ |
+LL | wants_read(&[0u8]);
+ | ---------- ^^^^^^ the trait `Read` is not implemented for `&[u8; 1]`
+ | |
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Read` is implemented for `&[u8]`
+note: required by a bound in `wants_read`
+ --> $DIR/issue-90528-unsizing-suggestion-1.rs:10:23
+ |
+LL | fn wants_read(_: impl Read) {}
+ | ^^^^ required by this bound in `wants_read`
+help: convert the array to a `&[u8]` slice instead
+ |
+LL | wants_read(&[0u8][..]);
+ | ++++
+
+error[E0277]: the trait bound `&mut [u8; 1]: Read` is not satisfied
+ --> $DIR/issue-90528-unsizing-suggestion-1.rs:18:16
+ |
+LL | wants_read(&mut [0u8]);
+ | ---------- ^^^^^^^^^^ the trait `Read` is not implemented for `&mut [u8; 1]`
+ | |
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Read` is implemented for `&[u8]`
+note: required by a bound in `wants_read`
+ --> $DIR/issue-90528-unsizing-suggestion-1.rs:10:23
+ |
+LL | fn wants_read(_: impl Read) {}
+ | ^^^^ required by this bound in `wants_read`
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/dst/issue-90528-unsizing-suggestion-2.rs b/tests/ui/dst/issue-90528-unsizing-suggestion-2.rs
new file mode 100644
index 000000000..f2762ad42
--- /dev/null
+++ b/tests/ui/dst/issue-90528-unsizing-suggestion-2.rs
@@ -0,0 +1,28 @@
+// Issue #90528: provide helpful suggestions when a trait bound is unsatisfied
+// due to a missed unsizing coercion.
+//
+// This test exercises array variables and a trait implemented on immmutable slices.
+
+trait Read {}
+
+impl Read for &[u8] {}
+
+fn wants_read(_: impl Read) {}
+
+fn main() {
+ let x = [0u8];
+ wants_read(x);
+ //~^ ERROR the trait bound `[u8; 1]: Read` is not satisfied
+ wants_read(&x);
+ //~^ ERROR the trait bound `&[u8; 1]: Read` is not satisfied
+ wants_read(&x[..]);
+
+ let x = &[0u8];
+ wants_read(x);
+ //~^ ERROR the trait bound `&[u8; 1]: Read` is not satisfied
+ wants_read(&x);
+ //~^ ERROR the trait bound `&&[u8; 1]: Read` is not satisfied
+ wants_read(*x);
+ //~^ ERROR the trait bound `[u8; 1]: Read` is not satisfied
+ wants_read(&x[..]);
+}
diff --git a/tests/ui/dst/issue-90528-unsizing-suggestion-2.stderr b/tests/ui/dst/issue-90528-unsizing-suggestion-2.stderr
new file mode 100644
index 000000000..ae0c4ca50
--- /dev/null
+++ b/tests/ui/dst/issue-90528-unsizing-suggestion-2.stderr
@@ -0,0 +1,94 @@
+error[E0277]: the trait bound `[u8; 1]: Read` is not satisfied
+ --> $DIR/issue-90528-unsizing-suggestion-2.rs:14:16
+ |
+LL | wants_read(x);
+ | ---------- ^ the trait `Read` is not implemented for `[u8; 1]`
+ | |
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Read` is implemented for `&[u8]`
+note: required by a bound in `wants_read`
+ --> $DIR/issue-90528-unsizing-suggestion-2.rs:10:23
+ |
+LL | fn wants_read(_: impl Read) {}
+ | ^^^^ required by this bound in `wants_read`
+help: convert the array to a `&[u8]` slice instead
+ |
+LL | wants_read(&x[..]);
+ | + ++++
+
+error[E0277]: the trait bound `&[u8; 1]: Read` is not satisfied
+ --> $DIR/issue-90528-unsizing-suggestion-2.rs:16:16
+ |
+LL | wants_read(&x);
+ | ---------- ^^ the trait `Read` is not implemented for `&[u8; 1]`
+ | |
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Read` is implemented for `&[u8]`
+note: required by a bound in `wants_read`
+ --> $DIR/issue-90528-unsizing-suggestion-2.rs:10:23
+ |
+LL | fn wants_read(_: impl Read) {}
+ | ^^^^ required by this bound in `wants_read`
+help: convert the array to a `&[u8]` slice instead
+ |
+LL | wants_read(&x[..]);
+ | ++++
+
+error[E0277]: the trait bound `&[u8; 1]: Read` is not satisfied
+ --> $DIR/issue-90528-unsizing-suggestion-2.rs:21:16
+ |
+LL | wants_read(x);
+ | ---------- ^ the trait `Read` is not implemented for `&[u8; 1]`
+ | |
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Read` is implemented for `&[u8]`
+note: required by a bound in `wants_read`
+ --> $DIR/issue-90528-unsizing-suggestion-2.rs:10:23
+ |
+LL | fn wants_read(_: impl Read) {}
+ | ^^^^ required by this bound in `wants_read`
+help: convert the array to a `&[u8]` slice instead
+ |
+LL | wants_read(&x[..]);
+ | + ++++
+
+error[E0277]: the trait bound `&&[u8; 1]: Read` is not satisfied
+ --> $DIR/issue-90528-unsizing-suggestion-2.rs:23:16
+ |
+LL | wants_read(&x);
+ | ---------- ^^ the trait `Read` is not implemented for `&&[u8; 1]`
+ | |
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Read` is implemented for `&[u8]`
+note: required by a bound in `wants_read`
+ --> $DIR/issue-90528-unsizing-suggestion-2.rs:10:23
+ |
+LL | fn wants_read(_: impl Read) {}
+ | ^^^^ required by this bound in `wants_read`
+
+error[E0277]: the trait bound `[u8; 1]: Read` is not satisfied
+ --> $DIR/issue-90528-unsizing-suggestion-2.rs:25:16
+ |
+LL | wants_read(*x);
+ | ---------- ^^ the trait `Read` is not implemented for `[u8; 1]`
+ | |
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Read` is implemented for `&[u8]`
+note: required by a bound in `wants_read`
+ --> $DIR/issue-90528-unsizing-suggestion-2.rs:10:23
+ |
+LL | fn wants_read(_: impl Read) {}
+ | ^^^^ required by this bound in `wants_read`
+help: convert the array to a `&[u8]` slice instead
+ |
+LL | wants_read(&*x[..]);
+ | + ++++
+
+error: aborting due to 5 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/dst/issue-90528-unsizing-suggestion-3.rs b/tests/ui/dst/issue-90528-unsizing-suggestion-3.rs
new file mode 100644
index 000000000..218843d05
--- /dev/null
+++ b/tests/ui/dst/issue-90528-unsizing-suggestion-3.rs
@@ -0,0 +1,22 @@
+// Issue #90528: provide helpful suggestions when a trait bound is unsatisfied
+// due to a missed unsizing coercion.
+//
+// This test exercises array literals and a trait implemented on mutable slices.
+
+trait Write {}
+
+impl Write for &mut [u8] {}
+
+fn wants_write(_: impl Write) {}
+
+fn main() {
+ wants_write([0u8]);
+ //~^ ERROR the trait bound `[u8; 1]: Write` is not satisfied
+ wants_write(&mut [0u8]);
+ //~^ ERROR the trait bound `&mut [u8; 1]: Write` is not satisfied
+ wants_write(&mut [0u8][..]);
+ wants_write(&[0u8]);
+ //~^ ERROR the trait bound `&[u8; 1]: Write` is not satisfied
+ wants_write(&[0u8][..]);
+ //~^ ERROR the trait bound `&[u8]: Write` is not satisfied
+}
diff --git a/tests/ui/dst/issue-90528-unsizing-suggestion-3.stderr b/tests/ui/dst/issue-90528-unsizing-suggestion-3.stderr
new file mode 100644
index 000000000..774d5ba3c
--- /dev/null
+++ b/tests/ui/dst/issue-90528-unsizing-suggestion-3.stderr
@@ -0,0 +1,75 @@
+error[E0277]: the trait bound `[u8; 1]: Write` is not satisfied
+ --> $DIR/issue-90528-unsizing-suggestion-3.rs:13:17
+ |
+LL | wants_write([0u8]);
+ | ----------- ^^^^^ the trait `Write` is not implemented for `[u8; 1]`
+ | |
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Write` is implemented for `&mut [u8]`
+note: required by a bound in `wants_write`
+ --> $DIR/issue-90528-unsizing-suggestion-3.rs:10:24
+ |
+LL | fn wants_write(_: impl Write) {}
+ | ^^^^^ required by this bound in `wants_write`
+help: convert the array to a `&mut [u8]` slice instead
+ |
+LL | wants_write(&mut [0u8][..]);
+ | ++++ ++++
+
+error[E0277]: the trait bound `&mut [u8; 1]: Write` is not satisfied
+ --> $DIR/issue-90528-unsizing-suggestion-3.rs:15:17
+ |
+LL | wants_write(&mut [0u8]);
+ | ----------- ^^^^^^^^^^ the trait `Write` is not implemented for `&mut [u8; 1]`
+ | |
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Write` is implemented for `&mut [u8]`
+note: required by a bound in `wants_write`
+ --> $DIR/issue-90528-unsizing-suggestion-3.rs:10:24
+ |
+LL | fn wants_write(_: impl Write) {}
+ | ^^^^^ required by this bound in `wants_write`
+help: convert the array to a `&mut [u8]` slice instead
+ |
+LL | wants_write(&mut [0u8][..]);
+ | ++++
+
+error[E0277]: the trait bound `&[u8; 1]: Write` is not satisfied
+ --> $DIR/issue-90528-unsizing-suggestion-3.rs:18:17
+ |
+LL | wants_write(&[0u8]);
+ | ----------- ^^^^^^ the trait `Write` is not implemented for `&[u8; 1]`
+ | |
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Write` is implemented for `&mut [u8]`
+note: required by a bound in `wants_write`
+ --> $DIR/issue-90528-unsizing-suggestion-3.rs:10:24
+ |
+LL | fn wants_write(_: impl Write) {}
+ | ^^^^^ required by this bound in `wants_write`
+
+error[E0277]: the trait bound `&[u8]: Write` is not satisfied
+ --> $DIR/issue-90528-unsizing-suggestion-3.rs:20:17
+ |
+LL | wants_write(&[0u8][..]);
+ | ----------- ^^^^^^^^^^ the trait `Write` is not implemented for `&[u8]`
+ | |
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Write` is implemented for `&mut [u8]`
+note: required by a bound in `wants_write`
+ --> $DIR/issue-90528-unsizing-suggestion-3.rs:10:24
+ |
+LL | fn wants_write(_: impl Write) {}
+ | ^^^^^ required by this bound in `wants_write`
+help: consider changing this borrow's mutability
+ |
+LL | wants_write(&mut [0u8][..]);
+ | ~~~~
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/dst/issue-90528-unsizing-suggestion-4.rs b/tests/ui/dst/issue-90528-unsizing-suggestion-4.rs
new file mode 100644
index 000000000..eae953c61
--- /dev/null
+++ b/tests/ui/dst/issue-90528-unsizing-suggestion-4.rs
@@ -0,0 +1,26 @@
+// Issue #90528: provide helpful suggestions when a trait bound is unsatisfied
+// due to a missed unsizing coercion.
+//
+// This test exercises array variables and a trait implemented on mutable slices.
+
+trait Write {}
+
+impl Write for &mut [u8] {}
+
+fn wants_write(_: impl Write) {}
+
+fn main() {
+ let mut x = [0u8];
+ wants_write(x);
+ //~^ ERROR the trait bound `[u8; 1]: Write` is not satisfied
+ wants_write(&mut x);
+ //~^ ERROR the trait bound `&mut [u8; 1]: Write` is not satisfied
+ wants_write(&mut x[..]);
+
+ let x = &mut [0u8];
+ wants_write(x);
+ //~^ ERROR the trait bound `&mut [u8; 1]: Write` is not satisfied
+ wants_write(*x);
+ //~^ ERROR the trait bound `[u8; 1]: Write` is not satisfied
+ wants_write(&mut x[..]);
+}
diff --git a/tests/ui/dst/issue-90528-unsizing-suggestion-4.stderr b/tests/ui/dst/issue-90528-unsizing-suggestion-4.stderr
new file mode 100644
index 000000000..a4020ee07
--- /dev/null
+++ b/tests/ui/dst/issue-90528-unsizing-suggestion-4.stderr
@@ -0,0 +1,79 @@
+error[E0277]: the trait bound `[u8; 1]: Write` is not satisfied
+ --> $DIR/issue-90528-unsizing-suggestion-4.rs:14:17
+ |
+LL | wants_write(x);
+ | ----------- ^ the trait `Write` is not implemented for `[u8; 1]`
+ | |
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Write` is implemented for `&mut [u8]`
+note: required by a bound in `wants_write`
+ --> $DIR/issue-90528-unsizing-suggestion-4.rs:10:24
+ |
+LL | fn wants_write(_: impl Write) {}
+ | ^^^^^ required by this bound in `wants_write`
+help: convert the array to a `&mut [u8]` slice instead
+ |
+LL | wants_write(&mut x[..]);
+ | ++++ ++++
+
+error[E0277]: the trait bound `&mut [u8; 1]: Write` is not satisfied
+ --> $DIR/issue-90528-unsizing-suggestion-4.rs:16:17
+ |
+LL | wants_write(&mut x);
+ | ----------- ^^^^^^ the trait `Write` is not implemented for `&mut [u8; 1]`
+ | |
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Write` is implemented for `&mut [u8]`
+note: required by a bound in `wants_write`
+ --> $DIR/issue-90528-unsizing-suggestion-4.rs:10:24
+ |
+LL | fn wants_write(_: impl Write) {}
+ | ^^^^^ required by this bound in `wants_write`
+help: convert the array to a `&mut [u8]` slice instead
+ |
+LL | wants_write(&mut x[..]);
+ | ++++
+
+error[E0277]: the trait bound `&mut [u8; 1]: Write` is not satisfied
+ --> $DIR/issue-90528-unsizing-suggestion-4.rs:21:17
+ |
+LL | wants_write(x);
+ | ----------- ^ the trait `Write` is not implemented for `&mut [u8; 1]`
+ | |
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Write` is implemented for `&mut [u8]`
+note: required by a bound in `wants_write`
+ --> $DIR/issue-90528-unsizing-suggestion-4.rs:10:24
+ |
+LL | fn wants_write(_: impl Write) {}
+ | ^^^^^ required by this bound in `wants_write`
+help: convert the array to a `&mut [u8]` slice instead
+ |
+LL | wants_write(&mut x[..]);
+ | ++++ ++++
+
+error[E0277]: the trait bound `[u8; 1]: Write` is not satisfied
+ --> $DIR/issue-90528-unsizing-suggestion-4.rs:23:17
+ |
+LL | wants_write(*x);
+ | ----------- ^^ the trait `Write` is not implemented for `[u8; 1]`
+ | |
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Write` is implemented for `&mut [u8]`
+note: required by a bound in `wants_write`
+ --> $DIR/issue-90528-unsizing-suggestion-4.rs:10:24
+ |
+LL | fn wants_write(_: impl Write) {}
+ | ^^^^^ required by this bound in `wants_write`
+help: convert the array to a `&mut [u8]` slice instead
+ |
+LL | wants_write(&mut *x[..]);
+ | ++++ ++++
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0277`.