summaryrefslogtreecommitdiffstats
path: root/tests/ui/traits/negative-bounds
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /tests/ui/traits/negative-bounds
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/traits/negative-bounds')
-rw-r--r--tests/ui/traits/negative-bounds/associated-constraints.rs20
-rw-r--r--tests/ui/traits/negative-bounds/associated-constraints.stderr34
-rw-r--r--tests/ui/traits/negative-bounds/simple.rs42
-rw-r--r--tests/ui/traits/negative-bounds/simple.stderr70
-rw-r--r--tests/ui/traits/negative-bounds/supertrait.rs9
-rw-r--r--tests/ui/traits/negative-bounds/supertrait.stderr10
6 files changed, 185 insertions, 0 deletions
diff --git a/tests/ui/traits/negative-bounds/associated-constraints.rs b/tests/ui/traits/negative-bounds/associated-constraints.rs
new file mode 100644
index 000000000..bc1a0ef17
--- /dev/null
+++ b/tests/ui/traits/negative-bounds/associated-constraints.rs
@@ -0,0 +1,20 @@
+#![feature(negative_bounds, associated_type_bounds)]
+//~^ WARN the feature `negative_bounds` is incomplete and may not be safe to use and/or cause compiler crashes
+
+trait Trait {
+ type Assoc;
+}
+
+fn test<T: !Trait<Assoc = i32>>() {}
+//~^ ERROR associated type constraints not allowed on negative bounds
+
+fn test2<T>() where T: !Trait<Assoc = i32> {}
+//~^ ERROR associated type constraints not allowed on negative bounds
+
+fn test3<T: !Trait<Assoc: Send>>() {}
+//~^ ERROR associated type constraints not allowed on negative bounds
+
+fn test4<T>() where T: !Trait<Assoc: Send> {}
+//~^ ERROR associated type constraints not allowed on negative bounds
+
+fn main() {}
diff --git a/tests/ui/traits/negative-bounds/associated-constraints.stderr b/tests/ui/traits/negative-bounds/associated-constraints.stderr
new file mode 100644
index 000000000..335ac7e5a
--- /dev/null
+++ b/tests/ui/traits/negative-bounds/associated-constraints.stderr
@@ -0,0 +1,34 @@
+error: associated type constraints not allowed on negative bounds
+ --> $DIR/associated-constraints.rs:8:19
+ |
+LL | fn test<T: !Trait<Assoc = i32>>() {}
+ | ^^^^^^^^^^^
+
+error: associated type constraints not allowed on negative bounds
+ --> $DIR/associated-constraints.rs:11:31
+ |
+LL | fn test2<T>() where T: !Trait<Assoc = i32> {}
+ | ^^^^^^^^^^^
+
+error: associated type constraints not allowed on negative bounds
+ --> $DIR/associated-constraints.rs:14:20
+ |
+LL | fn test3<T: !Trait<Assoc: Send>>() {}
+ | ^^^^^^^^^^^
+
+error: associated type constraints not allowed on negative bounds
+ --> $DIR/associated-constraints.rs:17:31
+ |
+LL | fn test4<T>() where T: !Trait<Assoc: Send> {}
+ | ^^^^^^^^^^^
+
+warning: the feature `negative_bounds` is incomplete and may not be safe to use and/or cause compiler crashes
+ --> $DIR/associated-constraints.rs:1:12
+ |
+LL | #![feature(negative_bounds, associated_type_bounds)]
+ | ^^^^^^^^^^^^^^^
+ |
+ = note: `#[warn(incomplete_features)]` on by default
+
+error: aborting due to 4 previous errors; 1 warning emitted
+
diff --git a/tests/ui/traits/negative-bounds/simple.rs b/tests/ui/traits/negative-bounds/simple.rs
new file mode 100644
index 000000000..f6d1d5169
--- /dev/null
+++ b/tests/ui/traits/negative-bounds/simple.rs
@@ -0,0 +1,42 @@
+#![feature(negative_bounds, negative_impls)]
+//~^ WARN the feature `negative_bounds` is incomplete and may not be safe to use and/or cause compiler crashes
+
+fn not_copy<T: !Copy>() {}
+
+fn neg_param_env<T: !Copy>() {
+ not_copy::<T>();
+}
+
+fn pos_param_env<T: Copy>() {
+ not_copy::<T>();
+ //~^ ERROR the trait bound `T: !Copy` is not satisfied
+}
+
+fn unknown<T>() {
+ not_copy::<T>();
+ //~^ ERROR the trait bound `T: !Copy` is not satisfied
+}
+
+struct NotCopyable;
+impl !Copy for NotCopyable {}
+
+fn neg_impl() {
+ not_copy::<NotCopyable>();
+}
+
+#[derive(Copy, Clone)]
+struct Copyable;
+
+fn pos_impl() {
+ not_copy::<Copyable>();
+ //~^ ERROR the trait bound `Copyable: !Copy` is not satisfied
+}
+
+struct NotNecessarilyCopyable;
+
+fn unknown_impl() {
+ not_copy::<NotNecessarilyCopyable>();
+ //~^ ERROR the trait bound `NotNecessarilyCopyable: !Copy` is not satisfied
+}
+
+fn main() {}
diff --git a/tests/ui/traits/negative-bounds/simple.stderr b/tests/ui/traits/negative-bounds/simple.stderr
new file mode 100644
index 000000000..a3cab41a2
--- /dev/null
+++ b/tests/ui/traits/negative-bounds/simple.stderr
@@ -0,0 +1,70 @@
+warning: the feature `negative_bounds` is incomplete and may not be safe to use and/or cause compiler crashes
+ --> $DIR/simple.rs:1:12
+ |
+LL | #![feature(negative_bounds, negative_impls)]
+ | ^^^^^^^^^^^^^^^
+ |
+ = note: `#[warn(incomplete_features)]` on by default
+
+error[E0277]: the trait bound `T: !Copy` is not satisfied
+ --> $DIR/simple.rs:11:16
+ |
+LL | not_copy::<T>();
+ | ^ the trait `!Copy` is not implemented for `T`
+ |
+note: required by a bound in `not_copy`
+ --> $DIR/simple.rs:4:16
+ |
+LL | fn not_copy<T: !Copy>() {}
+ | ^^^^^ required by this bound in `not_copy`
+
+error[E0277]: the trait bound `T: !Copy` is not satisfied
+ --> $DIR/simple.rs:16:16
+ |
+LL | not_copy::<T>();
+ | ^ the trait `!Copy` is not implemented for `T`
+ |
+note: required by a bound in `not_copy`
+ --> $DIR/simple.rs:4:16
+ |
+LL | fn not_copy<T: !Copy>() {}
+ | ^^^^^ required by this bound in `not_copy`
+
+error[E0277]: the trait bound `Copyable: !Copy` is not satisfied
+ --> $DIR/simple.rs:31:16
+ |
+LL | not_copy::<Copyable>();
+ | ^^^^^^^^ the trait `!Copy` is not implemented for `Copyable`
+ |
+ = help: the trait `Copy` is implemented for `Copyable`
+note: required by a bound in `not_copy`
+ --> $DIR/simple.rs:4:16
+ |
+LL | fn not_copy<T: !Copy>() {}
+ | ^^^^^ required by this bound in `not_copy`
+help: consider annotating `Copyable` with `#[derive(Copy)]`
+ |
+LL + #[derive(Copy)]
+LL | struct Copyable;
+ |
+
+error[E0277]: the trait bound `NotNecessarilyCopyable: !Copy` is not satisfied
+ --> $DIR/simple.rs:38:16
+ |
+LL | not_copy::<NotNecessarilyCopyable>();
+ | ^^^^^^^^^^^^^^^^^^^^^^ the trait `!Copy` is not implemented for `NotNecessarilyCopyable`
+ |
+note: required by a bound in `not_copy`
+ --> $DIR/simple.rs:4:16
+ |
+LL | fn not_copy<T: !Copy>() {}
+ | ^^^^^ required by this bound in `not_copy`
+help: consider annotating `NotNecessarilyCopyable` with `#[derive(Copy)]`
+ |
+LL + #[derive(Copy)]
+LL | struct NotNecessarilyCopyable;
+ |
+
+error: aborting due to 4 previous errors; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/traits/negative-bounds/supertrait.rs b/tests/ui/traits/negative-bounds/supertrait.rs
new file mode 100644
index 000000000..df0884b8b
--- /dev/null
+++ b/tests/ui/traits/negative-bounds/supertrait.rs
@@ -0,0 +1,9 @@
+// check-pass
+
+#![feature(negative_bounds)]
+//~^ WARN the feature `negative_bounds` is incomplete
+
+trait A: !B {}
+trait B: !A {}
+
+fn main() {}
diff --git a/tests/ui/traits/negative-bounds/supertrait.stderr b/tests/ui/traits/negative-bounds/supertrait.stderr
new file mode 100644
index 000000000..f44753b62
--- /dev/null
+++ b/tests/ui/traits/negative-bounds/supertrait.stderr
@@ -0,0 +1,10 @@
+warning: the feature `negative_bounds` is incomplete and may not be safe to use and/or cause compiler crashes
+ --> $DIR/supertrait.rs:3:12
+ |
+LL | #![feature(negative_bounds)]
+ | ^^^^^^^^^^^^^^^
+ |
+ = note: `#[warn(incomplete_features)]` on by default
+
+warning: 1 warning emitted
+