]> git.lizzy.rs Git - rust.git/blob - src/test/ui/parser/expr-as-stmt.rs
Merge commit 'e8dca3e87d164d2806098c462c6ce41301341f68' into sync_from_cg_gcc
[rust.git] / src / test / ui / parser / expr-as-stmt.rs
1 // run-rustfix
2 // rustfix-only-machine-applicable
3 #![allow(unused_variables)]
4 #![allow(dead_code)]
5 #![allow(unused_must_use)]
6
7 fn foo() -> i32 {
8     {2} + {2} //~ ERROR expected expression, found `+`
9     //~^ ERROR mismatched types
10 }
11
12 fn bar() -> i32 {
13     {2} + 2 //~ ERROR leading `+` is not supported
14     //~^ ERROR mismatched types
15 }
16
17 fn zul() -> u32 {
18     let foo = 3;
19     { 42 } + foo; //~ ERROR expected expression, found `+`
20     //~^ ERROR mismatched types
21     32
22 }
23
24 fn baz() -> i32 {
25     { 3 } * 3 //~ ERROR type `{integer}` cannot be dereferenced
26     //~^ ERROR mismatched types
27 }
28
29 fn moo(x: u32) -> bool {
30     match x {
31         _ => 1,
32     } > 0 //~ ERROR expected expression
33 }
34
35 fn qux() -> u32 {
36     {2} - 2 //~ ERROR cannot apply unary operator `-` to type `u32`
37     //~^ ERROR mismatched types
38 }
39
40 fn space_cadet() -> bool {
41     { true } | { true } //~ ERROR E0308
42     //~^ ERROR expected parameter name
43 }
44
45 fn revenge_from_mars() -> bool {
46     { true } && { true } //~ ERROR E0308
47     //~^ ERROR mismatched types
48 }
49
50 fn attack_from_mars() -> bool {
51     { true } || { true } //~ ERROR E0308
52     //~^ ERROR mismatched types
53 }
54
55 // This gets corrected by adding a semicolon, instead of parens.
56 // It's placed here to help keep track of the way this diagnostic
57 // needs to interact with type checking to avoid MachineApplicable
58 // suggestions that actually break stuff.
59 //
60 // If you're wondering what happens if that `foo()` is a `true` like
61 // all the ones above use? Nothing. It makes neither suggestion in
62 // that case.
63 fn asteroids() -> impl FnOnce() -> bool {
64     { foo() } || { true } //~ ERROR E0308
65 }
66
67 fn main() {}