about summary refs log tree commit diff
path: root/tests/ui
diff options
context:
space:
mode:
authorxizheyin <xizheyin@smail.nju.edu.cn>2025-04-01 13:22:45 +0800
committerxizheyin <xizheyin@smail.nju.edu.cn>2025-04-01 14:27:28 +0800
commit27b866d59a3e5ccbaf9723a37d353db6d2079f16 (patch)
tree63b2b521141f15af93cb84d5c2102a26b511f320 /tests/ui
parentae8ab87de4d8caab5d91a027bc19bb5d5e8a3691 (diff)
downloadrust-27b866d59a3e5ccbaf9723a37d353db6d2079f16.tar.gz
rust-27b866d59a3e5ccbaf9723a37d353db6d2079f16.zip
Add ui test ui/traits/object/suggestion-trait-object-issue-139174.rs
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
Diffstat (limited to 'tests/ui')
-rw-r--r--tests/ui/traits/object/suggestion-trait-object-issue-139174.rs24
-rw-r--r--tests/ui/traits/object/suggestion-trait-object-issue-139174.stderr55
2 files changed, 79 insertions, 0 deletions
diff --git a/tests/ui/traits/object/suggestion-trait-object-issue-139174.rs b/tests/ui/traits/object/suggestion-trait-object-issue-139174.rs
new file mode 100644
index 00000000000..f8fa410b7d4
--- /dev/null
+++ b/tests/ui/traits/object/suggestion-trait-object-issue-139174.rs
@@ -0,0 +1,24 @@
+//@compile-flags: --edition 2021
+
+fn f<'a>(x: Box<dyn Fn() -> Option<usize + 'a>>) -> usize {
+    //~^ ERROR expected trait, found builtin type `usize`
+    //~| ERROR expected a type, found a trait [E0782]
+    0
+}
+
+fn create_adder<'a>(x: i32) -> usize + 'a {
+    //~^ ERROR expected trait, found builtin type `usize`
+    //~| ERROR expected a type, found a trait [E0782]
+    move |y| x + y
+}
+
+struct Struct<'a>{
+    x: usize + 'a,
+    //~^ ERROR expected trait, found builtin type `usize`
+    //~| ERROR expected a type, found a trait [E0782]
+}
+
+
+fn main() {
+
+}
diff --git a/tests/ui/traits/object/suggestion-trait-object-issue-139174.stderr b/tests/ui/traits/object/suggestion-trait-object-issue-139174.stderr
new file mode 100644
index 00000000000..ddee0d5586b
--- /dev/null
+++ b/tests/ui/traits/object/suggestion-trait-object-issue-139174.stderr
@@ -0,0 +1,55 @@
+error[E0404]: expected trait, found builtin type `usize`
+  --> $DIR/suggestion-trait-object-issue-139174.rs:3:36
+   |
+LL | fn f<'a>(x: Box<dyn Fn() -> Option<usize + 'a>>) -> usize {
+   |                                    ^^^^^ not a trait
+
+error[E0404]: expected trait, found builtin type `usize`
+  --> $DIR/suggestion-trait-object-issue-139174.rs:9:32
+   |
+LL | fn create_adder<'a>(x: i32) -> usize + 'a {
+   |                                ^^^^^ not a trait
+
+error[E0404]: expected trait, found builtin type `usize`
+  --> $DIR/suggestion-trait-object-issue-139174.rs:16:8
+   |
+LL |     x: usize + 'a,
+   |        ^^^^^ not a trait
+
+error[E0782]: expected a type, found a trait
+  --> $DIR/suggestion-trait-object-issue-139174.rs:3:36
+   |
+LL | fn f<'a>(x: Box<dyn Fn() -> Option<usize + 'a>>) -> usize {
+   |                                    ^^^^^^^^^^
+   |
+help: you can add the `dyn` keyword if you want a trait object
+   |
+LL | fn f<'a>(x: Box<dyn Fn() -> Option<dyn usize + 'a>>) -> usize {
+   |                                    +++
+
+error[E0782]: expected a type, found a trait
+  --> $DIR/suggestion-trait-object-issue-139174.rs:9:32
+   |
+LL | fn create_adder<'a>(x: i32) -> usize + 'a {
+   |                                ^^^^^^^^^^
+   |
+help: `usize + 'a` is dyn-incompatible, use `impl usize + 'a` to return an opaque type, as long as you return a single underlying type
+   |
+LL | fn create_adder<'a>(x: i32) -> impl usize + 'a {
+   |                                ++++
+
+error[E0782]: expected a type, found a trait
+  --> $DIR/suggestion-trait-object-issue-139174.rs:16:8
+   |
+LL |     x: usize + 'a,
+   |        ^^^^^^^^^^
+   |
+help: you can add the `dyn` keyword if you want a trait object
+   |
+LL |     x: dyn usize + 'a,
+   |        +++
+
+error: aborting due to 6 previous errors
+
+Some errors have detailed explanations: E0404, E0782.
+For more information about an error, try `rustc --explain E0404`.