1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // This test has some extra semis in it that the pretty-printer won't
12 // reproduce so we don't want to automatically reformat it
18 * When you write a block-expression thing followed by
19 * a lone unary operator, you can get a surprising parse:
29 * These will parse as subtraction and multiplication binops.
30 * To get them to parse "the way you want" you need to brace
36 * or alternatively, semi-separate them:
41 * This seems a little wonky, but the alternative is to lower
42 * precedence of such block-like exprs to the point where
43 * you have to parenthesize them to get them to occur in the
44 * RHS of a binop. For example, you'd have to write:
46 * 12 + (if (foo) { 13 } else { 14 });
50 * 12 + if (foo) { 13 } else { 14 };
52 * Since we want to maintain the ability to write the latter,
53 * we leave the parens-burden on the trailing unop case.
61 assert_eq!(if (true) { 12i } else { 12 } - num, 0);
62 assert_eq!(12i - if (true) { 12i } else { 12 }, 0);
63 if (true) { 12i; } {-num};
64 if (true) { 12i; }; {-num};
65 if (true) { 12i; };;; -num;