Add ui test ui/traits/object/suggestion-trait-object-issue-139174.rs
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
This commit is contained in:
parent
ae8ab87de4
commit
27b866d59a
2 changed files with 79 additions and 0 deletions
|
@ -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() {
|
||||
|
||||
}
|
|
@ -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`.
|
Loading…
Add table
Add a link
Reference in a new issue