]> git.proxmox.com Git - rustc.git/blob - src/test/ui/type/type-check/assignment-in-if.rs
New upstream version 1.66.0+dfsg1
[rustc.git] / src / test / ui / type / type-check / assignment-in-if.rs
1 // Test that the parser does not attempt to parse struct literals
2 // within assignments in if expressions.
3
4 #![allow(unused_parens)]
5
6 struct Foo {
7 foo: usize
8 }
9
10 fn main() {
11 let x = 1;
12 let y: Foo;
13
14 // `x { ... }` should not be interpreted as a struct literal here
15 if x = x {
16 //~^ ERROR mismatched types
17 println!("{}", x);
18 }
19 // Explicit parentheses on the left should match behavior of above
20 if (x = x) {
21 //~^ ERROR mismatched types
22 println!("{}", x);
23 }
24 // The struct literal interpretation is fine with explicit parentheses on the right
25 if y = (Foo { foo: x }) {
26 //~^ ERROR mismatched types
27 println!("{}", x);
28 }
29 // "invalid left-hand side of assignment" error is suppresed
30 if 3 = x {
31 //~^ ERROR mismatched types
32 println!("{}", x);
33 }
34 if (
35 if true {
36 x = 4 //~ ERROR mismatched types
37 } else {
38 x = 5 //~ ERROR mismatched types
39 }
40 ) {
41 println!("{}", x);
42 }
43
44 if x == x && x = x && x == x {
45 //~^ ERROR mismatched types
46 //~| ERROR mismatched types
47 //~| ERROR mismatched types
48 println!("{}", x);
49 }
50
51 if x == x && x == x && x = x {
52 //~^ ERROR mismatched types
53 //~| ERROR mismatched types
54 println!("{}", x);
55 }
56
57 if x = 1 && x == 1 {
58 //~^ ERROR mismatched types
59 //~| ERROR mismatched types
60 println!("{}", x);
61 }
62 }