add tests
This commit is contained in:
parent
742b48dc39
commit
ff68673387
2 changed files with 81 additions and 0 deletions
40
src/test/ui/suggestions/match-ergonomics.rs
Normal file
40
src/test/ui/suggestions/match-ergonomics.rs
Normal file
|
@ -0,0 +1,40 @@
|
|||
fn main() {
|
||||
let x = vec![1i32];
|
||||
match &x[..] {
|
||||
[&v] => {}, //~ ERROR mismatched types
|
||||
_ => {},
|
||||
}
|
||||
match x {
|
||||
[&v] => {}, //~ ERROR expected an array or slice
|
||||
_ => {},
|
||||
}
|
||||
match &x[..] {
|
||||
[v] => {},
|
||||
_ => {},
|
||||
}
|
||||
match &x[..] {
|
||||
&[v] => {},
|
||||
_ => {},
|
||||
}
|
||||
match x {
|
||||
[v] => {}, //~ ERROR expected an array or slice
|
||||
_ => {},
|
||||
}
|
||||
let y = 1i32;
|
||||
match &y {
|
||||
&v => {},
|
||||
_ => {},
|
||||
}
|
||||
match y {
|
||||
&v => {}, //~ ERROR mismatched types
|
||||
_ => {},
|
||||
}
|
||||
match &y {
|
||||
v => {},
|
||||
_ => {},
|
||||
}
|
||||
match y {
|
||||
v => {},
|
||||
_ => {},
|
||||
}
|
||||
}
|
41
src/test/ui/suggestions/match-ergonomics.stderr
Normal file
41
src/test/ui/suggestions/match-ergonomics.stderr
Normal file
|
@ -0,0 +1,41 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/match-ergonomics.rs:4:10
|
||||
|
|
||||
LL | [&v] => {},
|
||||
| ^^
|
||||
| |
|
||||
| expected i32, found reference
|
||||
| help: you can probaly remove the explicit borrow: `v`
|
||||
|
|
||||
= note: expected type `i32`
|
||||
found type `&_`
|
||||
|
||||
error[E0529]: expected an array or slice, found `std::vec::Vec<i32>`
|
||||
--> $DIR/match-ergonomics.rs:8:9
|
||||
|
|
||||
LL | [&v] => {},
|
||||
| ^^^^ pattern cannot match with input type `std::vec::Vec<i32>`
|
||||
|
||||
error[E0529]: expected an array or slice, found `std::vec::Vec<i32>`
|
||||
--> $DIR/match-ergonomics.rs:20:9
|
||||
|
|
||||
LL | [v] => {},
|
||||
| ^^^ pattern cannot match with input type `std::vec::Vec<i32>`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/match-ergonomics.rs:29:9
|
||||
|
|
||||
LL | &v => {},
|
||||
| ^^ expected i32, found reference
|
||||
|
|
||||
= note: expected type `i32`
|
||||
found type `&_`
|
||||
help: you can rely on match ergonomics and remove the explicit borrow
|
||||
|
|
||||
LL | v => {},
|
||||
| ^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0308, E0529.
|
||||
For more information about an error, try `rustc --explain E0308`.
|
Loading…
Reference in a new issue