fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

master
2.0 KiB79 linesraw
1// run-rustfix
2// rustfix-only-machine-applicable
3#![allow(unused_variables)]
4#![allow(dead_code)]
5#![allow(unused_must_use)]
6
7fn foo() -> i32 {
8    ({2}) + {2} //~ ERROR expected expression, found `+`
9    //~^ ERROR mismatched types
10}
11
12fn bar() -> i32 {
13    ({2}) + 2 //~ ERROR leading `+` is not supported
14    //~^ ERROR mismatched types
15}
16
17fn zul() -> u32 {
18    let foo = 3;
19    ({ 42 }) + foo; //~ ERROR expected expression, found `+`
20    //~^ ERROR mismatched types
21    32
22}
23
24fn baz() -> i32 {
25    ({ 3 }) * 3 //~ ERROR type `{integer}` cannot be dereferenced
26    //~^ ERROR mismatched types
27}
28
29fn moo(x: u32) -> bool {
30    (match x {
31        _ => 1,
32    }) > 0 //~ ERROR expected expression
33}
34
35fn qux() -> u32 {
36    ({2}) - 2 //~ ERROR cannot apply unary operator `-` to type `u32`
37    //~^ ERROR mismatched types
38}
39
40fn space_cadet() -> bool {
41    ({ true }) | { true } //~ ERROR E0308
42    //~^ ERROR expected parameter name
43}
44
45fn revenge_from_mars() -> bool {
46    ({ true }) && { true } //~ ERROR E0308
47    //~^ ERROR mismatched types
48}
49
50fn 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.
63fn asteroids() -> impl FnOnce() -> bool {
64    { foo(); } || { true } //~ ERROR E0308
65}
66
67// https://github.com/rust-lang/rust/issues/105179
68fn 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
74fn r#unsafe() -> i32 {
75    (unsafe { 1 }) + unsafe { 1 } //~ ERROR expected expression, found `+`
76    //~^ ERROR mismatched types
77}
78
79fn main() {}