about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-09-17 08:49:26 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-09-17 08:49:26 -0700
commitf4da040e62d55bb6ab28b7605d4ee12ef6f969a1 (patch)
treeaeaffef8eae75438bac92129dd0a6ecefacf4328 /src/test
parent04c537ff56ee12fd093a06e23541d9d07e94a2cf (diff)
parent0e230c04dd2b66b6d7e13312c0f0bf37b306d52b (diff)
downloadrust-f4da040e62d55bb6ab28b7605d4ee12ef6f969a1.tar.gz
rust-f4da040e62d55bb6ab28b7605d4ee12ef6f969a1.zip
rollup merge of #17290 : bkoropoff/issue-17283
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/issue-17283.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/test/compile-fail/issue-17283.rs b/src/test/compile-fail/issue-17283.rs
new file mode 100644
index 00000000000..122c1f08395
--- /dev/null
+++ b/src/test/compile-fail/issue-17283.rs
@@ -0,0 +1,37 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Test that the parser does not attempt to parse struct literals
+// within assignments in if expressions.
+
+struct Foo {
+    foo: uint
+}
+
+fn main() {
+    let x = 1u;
+    let y: Foo;
+
+    // `x { ... }` should not be interpreted as a struct literal here
+    if x = x {
+        //~^ ERROR mismatched types: expected `bool`, found `()` (expected bool, found ())
+        println!("{}", x);
+    }
+    // Explicit parentheses on the left should match behavior of above
+    if (x = x) {
+        //~^ ERROR mismatched types: expected `bool`, found `()` (expected bool, found ())
+        println!("{}", x);
+    }
+    // The struct literal interpretation is fine with explicit parentheses on the right
+    if y = (Foo { foo: x }) {
+        //~^ ERROR mismatched types: expected `bool`, found `()` (expected bool, found ())
+        println!("{}", x);
+    }
+}