about summary refs log tree commit diff
path: root/tests/ui/rust-2021
diff options
context:
space:
mode:
authorVulnBandit <183613941+VulnBandit@users.noreply.github.com>2024-10-04 16:10:28 +0200
committerVulnBandit <183613941+VulnBandit@users.noreply.github.com>2024-10-11 17:36:04 +0200
commit9a2772e1c2d6e770e13716d4691bc0a943cd7d61 (patch)
treed4139674416b2f6a564533e7574f2eb295457e67 /tests/ui/rust-2021
parent484c8e78cb915bf1aca57ec62953324fe76b5d37 (diff)
downloadrust-9a2772e1c2d6e770e13716d4691bc0a943cd7d61.tar.gz
rust-9a2772e1c2d6e770e13716d4691bc0a943cd7d61.zip
Don't assume traits used as type are trait objs
Diffstat (limited to 'tests/ui/rust-2021')
-rw-r--r--tests/ui/rust-2021/ice-return-unsized-can-impl-2.rs15
-rw-r--r--tests/ui/rust-2021/ice-return-unsized-can-impl-2.stderr57
-rw-r--r--tests/ui/rust-2021/ice-return-unsized-can-impl.rs16
-rw-r--r--tests/ui/rust-2021/ice-return-unsized-can-impl.stderr30
-rw-r--r--tests/ui/rust-2021/ice-unsized-fn-params-2.rs12
-rw-r--r--tests/ui/rust-2021/ice-unsized-fn-params-2.stderr19
-rw-r--r--tests/ui/rust-2021/ice-unsized-fn-params.rs18
-rw-r--r--tests/ui/rust-2021/ice-unsized-fn-params.stderr57
8 files changed, 224 insertions, 0 deletions
diff --git a/tests/ui/rust-2021/ice-return-unsized-can-impl-2.rs b/tests/ui/rust-2021/ice-return-unsized-can-impl-2.rs
new file mode 100644
index 00000000000..e57e9ce4844
--- /dev/null
+++ b/tests/ui/rust-2021/ice-return-unsized-can-impl-2.rs
@@ -0,0 +1,15 @@
+// Doesn't trigger ICE when returning unsized trait that can be impl
+// issue https://github.com/rust-lang/rust/issues/125512
+//@ edition:2021
+#![feature(dyn_compatible_for_dispatch)]
+trait B {
+    fn f(a: A) -> A;
+    //~^ ERROR: expected a type, found a trait
+    //~| ERROR: expected a type, found a trait
+}
+trait A {
+    fn concrete(b: B) -> B;
+    //~^ ERROR: expected a type, found a trait
+    //~| ERROR: expected a type, found a trait
+}
+fn main() {}
diff --git a/tests/ui/rust-2021/ice-return-unsized-can-impl-2.stderr b/tests/ui/rust-2021/ice-return-unsized-can-impl-2.stderr
new file mode 100644
index 00000000000..b8a9a5c8129
--- /dev/null
+++ b/tests/ui/rust-2021/ice-return-unsized-can-impl-2.stderr
@@ -0,0 +1,57 @@
+error[E0782]: expected a type, found a trait
+  --> $DIR/ice-return-unsized-can-impl-2.rs:11:20
+   |
+LL |     fn concrete(b: B) -> B;
+   |                    ^
+   |
+   = note: `B` it is dyn-incompatible, so it can't be `dyn`
+help: use a new generic type parameter, constrained by `B`
+   |
+LL |     fn concrete<T: B>(b: T) -> B;
+   |                ++++++    ~
+help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference
+   |
+LL |     fn concrete(b: impl B) -> B;
+   |                    ++++
+
+error[E0782]: expected a type, found a trait
+  --> $DIR/ice-return-unsized-can-impl-2.rs:11:26
+   |
+LL |     fn concrete(b: B) -> B;
+   |                          ^
+   |
+help: `B` is dyn-incompatible, use `impl B` to return an opaque type, as long as you return a single underlying type
+   |
+LL |     fn concrete(b: B) -> impl B;
+   |                          ++++
+
+error[E0782]: expected a type, found a trait
+  --> $DIR/ice-return-unsized-can-impl-2.rs:6:13
+   |
+LL |     fn f(a: A) -> A;
+   |             ^
+   |
+   = note: `A` it is dyn-incompatible, so it can't be `dyn`
+help: use a new generic type parameter, constrained by `A`
+   |
+LL |     fn f<T: A>(a: T) -> A;
+   |         ++++++    ~
+help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference
+   |
+LL |     fn f(a: impl A) -> A;
+   |             ++++
+
+error[E0782]: expected a type, found a trait
+  --> $DIR/ice-return-unsized-can-impl-2.rs:6:19
+   |
+LL |     fn f(a: A) -> A;
+   |                   ^
+   |
+help: `A` is dyn-incompatible, use `impl A` to return an opaque type, as long as you return a single underlying type
+   |
+LL |     fn f(a: A) -> impl A;
+   |                   ++++
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0782`.
diff --git a/tests/ui/rust-2021/ice-return-unsized-can-impl.rs b/tests/ui/rust-2021/ice-return-unsized-can-impl.rs
new file mode 100644
index 00000000000..055b11b4424
--- /dev/null
+++ b/tests/ui/rust-2021/ice-return-unsized-can-impl.rs
@@ -0,0 +1,16 @@
+// Doesn't trigger ICE when returning unsized trait that can be impl
+// issue https://github.com/rust-lang/rust/issues/120482
+//@ edition:2021
+#![feature(dyn_compatible_for_dispatch)]
+
+trait B {
+    fn bar(&self, x: &Self);
+}
+
+trait A {
+    fn g(new: B) -> B;
+    //~^ ERROR: expected a type, found a trait
+    //~| ERROR: expected a type, found a trait
+}
+
+fn main() {}
diff --git a/tests/ui/rust-2021/ice-return-unsized-can-impl.stderr b/tests/ui/rust-2021/ice-return-unsized-can-impl.stderr
new file mode 100644
index 00000000000..c0969570e92
--- /dev/null
+++ b/tests/ui/rust-2021/ice-return-unsized-can-impl.stderr
@@ -0,0 +1,30 @@
+error[E0782]: expected a type, found a trait
+  --> $DIR/ice-return-unsized-can-impl.rs:11:15
+   |
+LL |     fn g(new: B) -> B;
+   |               ^
+   |
+   = note: `B` it is dyn-incompatible, so it can't be `dyn`
+help: use a new generic type parameter, constrained by `B`
+   |
+LL |     fn g<T: B>(new: T) -> B;
+   |         ++++++      ~
+help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference
+   |
+LL |     fn g(new: impl B) -> B;
+   |               ++++
+
+error[E0782]: expected a type, found a trait
+  --> $DIR/ice-return-unsized-can-impl.rs:11:21
+   |
+LL |     fn g(new: B) -> B;
+   |                     ^
+   |
+help: `B` is dyn-incompatible, use `impl B` to return an opaque type, as long as you return a single underlying type
+   |
+LL |     fn g(new: B) -> impl B;
+   |                     ++++
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0782`.
diff --git a/tests/ui/rust-2021/ice-unsized-fn-params-2.rs b/tests/ui/rust-2021/ice-unsized-fn-params-2.rs
new file mode 100644
index 00000000000..2b4f7bd088f
--- /dev/null
+++ b/tests/ui/rust-2021/ice-unsized-fn-params-2.rs
@@ -0,0 +1,12 @@
+//@ edition:2021
+// Test that it doesn't trigger an ICE when using an unsized fn params.
+// https://github.com/rust-lang/rust/issues/120241
+#![feature(dyn_compatible_for_dispatch)]
+#![feature(unsized_fn_params)]
+
+fn guard(_s: Copy) -> bool {
+    //~^ ERROR: expected a type, found a trait
+    panic!()
+}
+
+fn main() {}
diff --git a/tests/ui/rust-2021/ice-unsized-fn-params-2.stderr b/tests/ui/rust-2021/ice-unsized-fn-params-2.stderr
new file mode 100644
index 00000000000..d35c8ab3e42
--- /dev/null
+++ b/tests/ui/rust-2021/ice-unsized-fn-params-2.stderr
@@ -0,0 +1,19 @@
+error[E0782]: expected a type, found a trait
+  --> $DIR/ice-unsized-fn-params-2.rs:7:14
+   |
+LL | fn guard(_s: Copy) -> bool {
+   |              ^^^^
+   |
+   = note: `Copy` it is dyn-incompatible, so it can't be `dyn`
+help: use a new generic type parameter, constrained by `Copy`
+   |
+LL | fn guard<T: Copy>(_s: T) -> bool {
+   |         +++++++++     ~
+help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference
+   |
+LL | fn guard(_s: impl Copy) -> bool {
+   |              ++++
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0782`.
diff --git a/tests/ui/rust-2021/ice-unsized-fn-params.rs b/tests/ui/rust-2021/ice-unsized-fn-params.rs
new file mode 100644
index 00000000000..6d8c1c3f152
--- /dev/null
+++ b/tests/ui/rust-2021/ice-unsized-fn-params.rs
@@ -0,0 +1,18 @@
+//@ edition:2021
+// Test that it doesn't trigger an ICE when using an unsized fn params.
+// https://github.com/rust-lang/rust/issues/120241
+#![feature(dyn_compatible_for_dispatch)]
+
+trait B {
+    fn f(a: A) -> A;
+    //~^ ERROR: expected a type, found a trait
+    //~| ERROR: expected a type, found a trait
+}
+
+trait A {
+    fn g(b: B) -> B;
+    //~^ ERROR: expected a type, found a trait
+    //~| ERROR: expected a type, found a trait
+}
+
+fn main() {}
diff --git a/tests/ui/rust-2021/ice-unsized-fn-params.stderr b/tests/ui/rust-2021/ice-unsized-fn-params.stderr
new file mode 100644
index 00000000000..d56e9981a28
--- /dev/null
+++ b/tests/ui/rust-2021/ice-unsized-fn-params.stderr
@@ -0,0 +1,57 @@
+error[E0782]: expected a type, found a trait
+  --> $DIR/ice-unsized-fn-params.rs:13:13
+   |
+LL |     fn g(b: B) -> B;
+   |             ^
+   |
+   = note: `B` it is dyn-incompatible, so it can't be `dyn`
+help: use a new generic type parameter, constrained by `B`
+   |
+LL |     fn g<T: B>(b: T) -> B;
+   |         ++++++    ~
+help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference
+   |
+LL |     fn g(b: impl B) -> B;
+   |             ++++
+
+error[E0782]: expected a type, found a trait
+  --> $DIR/ice-unsized-fn-params.rs:13:19
+   |
+LL |     fn g(b: B) -> B;
+   |                   ^
+   |
+help: `B` is dyn-incompatible, use `impl B` to return an opaque type, as long as you return a single underlying type
+   |
+LL |     fn g(b: B) -> impl B;
+   |                   ++++
+
+error[E0782]: expected a type, found a trait
+  --> $DIR/ice-unsized-fn-params.rs:7:13
+   |
+LL |     fn f(a: A) -> A;
+   |             ^
+   |
+   = note: `A` it is dyn-incompatible, so it can't be `dyn`
+help: use a new generic type parameter, constrained by `A`
+   |
+LL |     fn f<T: A>(a: T) -> A;
+   |         ++++++    ~
+help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference
+   |
+LL |     fn f(a: impl A) -> A;
+   |             ++++
+
+error[E0782]: expected a type, found a trait
+  --> $DIR/ice-unsized-fn-params.rs:7:19
+   |
+LL |     fn f(a: A) -> A;
+   |                   ^
+   |
+help: `A` is dyn-incompatible, use `impl A` to return an opaque type, as long as you return a single underlying type
+   |
+LL |     fn f(a: A) -> impl A;
+   |                   ++++
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0782`.