Skip to content

Commit 27b866d

Browse files
committed
Add ui test ui/traits/object/suggestion-trait-object-issue-139174.rs
Signed-off-by: xizheyin <[email protected]>
1 parent ae8ab87 commit 27b866d

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//@compile-flags: --edition 2021
2+
3+
fn f<'a>(x: Box<dyn Fn() -> Option<usize + 'a>>) -> usize {
4+
//~^ ERROR expected trait, found builtin type `usize`
5+
//~| ERROR expected a type, found a trait [E0782]
6+
0
7+
}
8+
9+
fn create_adder<'a>(x: i32) -> usize + 'a {
10+
//~^ ERROR expected trait, found builtin type `usize`
11+
//~| ERROR expected a type, found a trait [E0782]
12+
move |y| x + y
13+
}
14+
15+
struct Struct<'a>{
16+
x: usize + 'a,
17+
//~^ ERROR expected trait, found builtin type `usize`
18+
//~| ERROR expected a type, found a trait [E0782]
19+
}
20+
21+
22+
fn main() {
23+
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
error[E0404]: expected trait, found builtin type `usize`
2+
--> $DIR/suggestion-trait-object-issue-139174.rs:3:36
3+
|
4+
LL | fn f<'a>(x: Box<dyn Fn() -> Option<usize + 'a>>) -> usize {
5+
| ^^^^^ not a trait
6+
7+
error[E0404]: expected trait, found builtin type `usize`
8+
--> $DIR/suggestion-trait-object-issue-139174.rs:9:32
9+
|
10+
LL | fn create_adder<'a>(x: i32) -> usize + 'a {
11+
| ^^^^^ not a trait
12+
13+
error[E0404]: expected trait, found builtin type `usize`
14+
--> $DIR/suggestion-trait-object-issue-139174.rs:16:8
15+
|
16+
LL | x: usize + 'a,
17+
| ^^^^^ not a trait
18+
19+
error[E0782]: expected a type, found a trait
20+
--> $DIR/suggestion-trait-object-issue-139174.rs:3:36
21+
|
22+
LL | fn f<'a>(x: Box<dyn Fn() -> Option<usize + 'a>>) -> usize {
23+
| ^^^^^^^^^^
24+
|
25+
help: you can add the `dyn` keyword if you want a trait object
26+
|
27+
LL | fn f<'a>(x: Box<dyn Fn() -> Option<dyn usize + 'a>>) -> usize {
28+
| +++
29+
30+
error[E0782]: expected a type, found a trait
31+
--> $DIR/suggestion-trait-object-issue-139174.rs:9:32
32+
|
33+
LL | fn create_adder<'a>(x: i32) -> usize + 'a {
34+
| ^^^^^^^^^^
35+
|
36+
help: `usize + 'a` is dyn-incompatible, use `impl usize + 'a` to return an opaque type, as long as you return a single underlying type
37+
|
38+
LL | fn create_adder<'a>(x: i32) -> impl usize + 'a {
39+
| ++++
40+
41+
error[E0782]: expected a type, found a trait
42+
--> $DIR/suggestion-trait-object-issue-139174.rs:16:8
43+
|
44+
LL | x: usize + 'a,
45+
| ^^^^^^^^^^
46+
|
47+
help: you can add the `dyn` keyword if you want a trait object
48+
|
49+
LL | x: dyn usize + 'a,
50+
| +++
51+
52+
error: aborting due to 6 previous errors
53+
54+
Some errors have detailed explanations: E0404, E0782.
55+
For more information about an error, try `rustc --explain E0404`.

0 commit comments

Comments
 (0)