summaryrefslogtreecommitdiffstats
path: root/tests/ui/dst
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/dst')
-rw-r--r--tests/ui/dst/issue-113447.fixed25
-rw-r--r--tests/ui/dst/issue-113447.rs25
-rw-r--r--tests/ui/dst/issue-113447.stderr25
-rw-r--r--tests/ui/dst/issue-90528-unsizing-not-suggestion-110063.rs13
-rw-r--r--tests/ui/dst/issue-90528-unsizing-not-suggestion-110063.stderr29
5 files changed, 117 insertions, 0 deletions
diff --git a/tests/ui/dst/issue-113447.fixed b/tests/ui/dst/issue-113447.fixed
new file mode 100644
index 000000000..536f680f6
--- /dev/null
+++ b/tests/ui/dst/issue-113447.fixed
@@ -0,0 +1,25 @@
+// run-rustfix
+
+pub struct Bytes;
+
+impl Bytes {
+ pub fn as_slice(&self) -> &[u8] {
+ todo!()
+ }
+}
+
+impl PartialEq<[u8]> for Bytes {
+ fn eq(&self, other: &[u8]) -> bool {
+ self.as_slice() == other
+ }
+}
+
+impl PartialEq<Bytes> for &[u8] {
+ fn eq(&self, other: &Bytes) -> bool {
+ *other == **self
+ }
+}
+
+fn main() {
+ let _ = &[0u8] == &[0xAA][..]; //~ ERROR can't compare `&[u8; 1]` with `[{integer}; 1]`
+}
diff --git a/tests/ui/dst/issue-113447.rs b/tests/ui/dst/issue-113447.rs
new file mode 100644
index 000000000..c10a4f2ff
--- /dev/null
+++ b/tests/ui/dst/issue-113447.rs
@@ -0,0 +1,25 @@
+// run-rustfix
+
+pub struct Bytes;
+
+impl Bytes {
+ pub fn as_slice(&self) -> &[u8] {
+ todo!()
+ }
+}
+
+impl PartialEq<[u8]> for Bytes {
+ fn eq(&self, other: &[u8]) -> bool {
+ self.as_slice() == other
+ }
+}
+
+impl PartialEq<Bytes> for &[u8] {
+ fn eq(&self, other: &Bytes) -> bool {
+ *other == **self
+ }
+}
+
+fn main() {
+ let _ = &[0u8] == [0xAA]; //~ ERROR can't compare `&[u8; 1]` with `[{integer}; 1]`
+}
diff --git a/tests/ui/dst/issue-113447.stderr b/tests/ui/dst/issue-113447.stderr
new file mode 100644
index 000000000..240553a67
--- /dev/null
+++ b/tests/ui/dst/issue-113447.stderr
@@ -0,0 +1,25 @@
+error[E0277]: can't compare `&[u8; 1]` with `[{integer}; 1]`
+ --> $DIR/issue-113447.rs:24:20
+ |
+LL | let _ = &[0u8] == [0xAA];
+ | ^^ no implementation for `&[u8; 1] == [{integer}; 1]`
+ |
+ = help: the trait `PartialEq<[{integer}; 1]>` is not implemented for `&[u8; 1]`
+ = help: the following other types implement trait `PartialEq<Rhs>`:
+ <[A; N] as PartialEq<[B; N]>>
+ <[A; N] as PartialEq<[B]>>
+ <[A; N] as PartialEq<&[B]>>
+ <[A; N] as PartialEq<&mut [B]>>
+ <[T] as PartialEq<Vec<U, A>>>
+ <[A] as PartialEq<[B]>>
+ <[B] as PartialEq<[A; N]>>
+ <&[u8] as PartialEq<Bytes>>
+ and 4 others
+help: convert the array to a `&[u8]` slice instead
+ |
+LL | let _ = &[0u8] == &[0xAA][..];
+ | + ++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/dst/issue-90528-unsizing-not-suggestion-110063.rs b/tests/ui/dst/issue-90528-unsizing-not-suggestion-110063.rs
new file mode 100644
index 000000000..c6ef8379f
--- /dev/null
+++ b/tests/ui/dst/issue-90528-unsizing-not-suggestion-110063.rs
@@ -0,0 +1,13 @@
+trait Test {}
+impl Test for &[u8] {}
+
+fn needs_test<T: Test>() -> T {
+ panic!()
+}
+
+fn main() {
+ needs_test::<[u8; 1]>();
+ //~^ ERROR the trait bound
+ let x: [u8; 1] = needs_test();
+ //~^ ERROR the trait bound
+}
diff --git a/tests/ui/dst/issue-90528-unsizing-not-suggestion-110063.stderr b/tests/ui/dst/issue-90528-unsizing-not-suggestion-110063.stderr
new file mode 100644
index 000000000..6752a4844
--- /dev/null
+++ b/tests/ui/dst/issue-90528-unsizing-not-suggestion-110063.stderr
@@ -0,0 +1,29 @@
+error[E0277]: the trait bound `[u8; 1]: Test` is not satisfied
+ --> $DIR/issue-90528-unsizing-not-suggestion-110063.rs:9:18
+ |
+LL | needs_test::<[u8; 1]>();
+ | ^^^^^^^ the trait `Test` is not implemented for `[u8; 1]`
+ |
+ = help: the trait `Test` is implemented for `&[u8]`
+note: required by a bound in `needs_test`
+ --> $DIR/issue-90528-unsizing-not-suggestion-110063.rs:4:18
+ |
+LL | fn needs_test<T: Test>() -> T {
+ | ^^^^ required by this bound in `needs_test`
+
+error[E0277]: the trait bound `[u8; 1]: Test` is not satisfied
+ --> $DIR/issue-90528-unsizing-not-suggestion-110063.rs:11:22
+ |
+LL | let x: [u8; 1] = needs_test();
+ | ^^^^^^^^^^ the trait `Test` is not implemented for `[u8; 1]`
+ |
+ = help: the trait `Test` is implemented for `&[u8]`
+note: required by a bound in `needs_test`
+ --> $DIR/issue-90528-unsizing-not-suggestion-110063.rs:4:18
+ |
+LL | fn needs_test<T: Test>() -> T {
+ | ^^^^ required by this bound in `needs_test`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.