]> git.proxmox.com Git - rustc.git/blame - 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
CommitLineData
1a4d82fc
JJ
1// Test that the parser does not attempt to parse struct literals
2// within assignments in if expressions.
3
b039eaaf
SL
4#![allow(unused_parens)]
5
1a4d82fc
JJ
6struct Foo {
7 foo: usize
8}
9
10fn main() {
c34b1796 11 let x = 1;
1a4d82fc
JJ
12 let y: Foo;
13
14 // `x { ... }` should not be interpreted as a struct literal here
15 if x = x {
85aaf69f 16 //~^ ERROR mismatched types
1a4d82fc
JJ
17 println!("{}", x);
18 }
19 // Explicit parentheses on the left should match behavior of above
20 if (x = x) {
85aaf69f 21 //~^ ERROR mismatched types
1a4d82fc
JJ
22 println!("{}", x);
23 }
24 // The struct literal interpretation is fine with explicit parentheses on the right
25 if y = (Foo { foo: x }) {
85aaf69f 26 //~^ ERROR mismatched types
041b39d2
XL
27 println!("{}", x);
28 }
dfeec247 29 // "invalid left-hand side of assignment" error is suppresed
041b39d2
XL
30 if 3 = x {
31 //~^ ERROR mismatched types
041b39d2
XL
32 println!("{}", x);
33 }
532ac7d7
XL
34 if (
35 if true {
36 x = 4 //~ ERROR mismatched types
37 } else {
38 x = 5 //~ ERROR mismatched types
39 }
40 ) {
1a4d82fc
JJ
41 println!("{}", x);
42 }
2b03887a
FG
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 }
1a4d82fc 62}