• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // run-rustfix
2 // rustfix-only-machine-applicable
3 #![allow(unused_variables)]
4 #![allow(dead_code)]
5 #![allow(unused_must_use)]
6 
foo() -> i327 fn foo() -> i32 {
8     {2} + {2} //~ ERROR expected expression, found `+`
9     //~^ ERROR mismatched types
10 }
11 
bar() -> i3212 fn bar() -> i32 {
13     {2} + 2 //~ ERROR leading `+` is not supported
14     //~^ ERROR mismatched types
15 }
16 
zul() -> u3217 fn zul() -> u32 {
18     let foo = 3;
19     { 42 } + foo; //~ ERROR expected expression, found `+`
20     //~^ ERROR mismatched types
21     32
22 }
23 
baz() -> i3224 fn baz() -> i32 {
25     { 3 } * 3 //~ ERROR type `{integer}` cannot be dereferenced
26     //~^ ERROR mismatched types
27 }
28 
moo(x: u32) -> bool29 fn moo(x: u32) -> bool {
30     match x {
31         _ => 1,
32     } > 0 //~ ERROR expected expression
33 }
34 
qux() -> u3235 fn qux() -> u32 {
36     {2} - 2 //~ ERROR cannot apply unary operator `-` to type `u32`
37     //~^ ERROR mismatched types
38 }
39 
space_cadet() -> bool40 fn space_cadet() -> bool {
41     { true } | { true } //~ ERROR E0308
42     //~^ ERROR expected parameter name
43 }
44 
revenge_from_mars() -> bool45 fn revenge_from_mars() -> bool {
46     { true } && { true } //~ ERROR E0308
47     //~^ ERROR mismatched types
48 }
49 
attack_from_mars() -> bool50 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.
asteroids() -> impl FnOnce() -> bool63 fn asteroids() -> impl FnOnce() -> bool {
64     { foo() } || { true } //~ ERROR E0308
65 }
66 
67 // https://github.com/rust-lang/rust/issues/105179
68 fn r#match() -> i32 {
69     match () { () => 1 } + match () { () => 1 } //~ ERROR expected expression, found `+`
70     //~^ ERROR mismatched types
71 }
72 
73 // https://github.com/rust-lang/rust/issues/102171
74 fn r#unsafe() -> i32 {
75     unsafe { 1 } + unsafe { 1 } //~ ERROR expected expression, found `+`
76     //~^ ERROR mismatched types
77 }
78 
main()79 fn main() {}
80