about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrian Koropoff <bkoropoff@gmail.com>2014-09-15 19:22:17 -0700
committerBrian Koropoff <bkoropoff@gmail.com>2014-09-16 19:21:42 -0700
commit0e230c04dd2b66b6d7e13312c0f0bf37b306d52b (patch)
treef85bee811d982bffd506b1dbd18c2f790ff768f5
parent3863b68df490dab6bcaccef39039382d47ffb226 (diff)
downloadrust-0e230c04dd2b66b6d7e13312c0f0bf37b306d52b.tar.gz
rust-0e230c04dd2b66b6d7e13312c0f0bf37b306d52b.zip
Add regression test for issue #17283
-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);
+    }
+}