Skip to content

Commit 3a33522

Browse files
committed
Adjust assoc-oddities-3.rs
- Include the original MCVE as reported in <rust-lang#28777>. - Document the intention of the test.
1 parent b815a93 commit 3a33522

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Diff for: tests/ui/parser/assoc/assoc-oddities-3.rs

+28
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
//! Check that braces has the expected precedence in relation to index op and some arithmetic
2+
//! bin-ops involving nested braces.
3+
//!
4+
//! This is a regression test for [Wrapping expr in curly braces changes the operator precedence
5+
//! #28777](https://github.com/rust-lang/rust/issues/28777), which was fixed by
6+
//! <https://github.com/rust-lang/rust/pull/30375>.
7+
18
//@ run-pass
29

310
fn that_odd_parse(c: bool, n: usize) -> u32 {
@@ -7,7 +14,28 @@ fn that_odd_parse(c: bool, n: usize) -> u32 {
714
x + if c { a } else { b }[n]
815
}
916

17+
/// See [Wrapping expr in curly braces changes the operator precedence
18+
/// #28777](https://github.com/rust-lang/rust/issues/28777). This was fixed by
19+
/// <https://github.com/rust-lang/rust/pull/30375>. #30375 added the `that_odd_parse` example above,
20+
/// but that is not *quite* the same original example as reported in #28777, so we also include the
21+
/// original example here.
22+
fn check_issue_28777() {
23+
// Before #30375 fixed the precedence...
24+
25+
// ... `v1` evaluated to 9, indicating a parse of `(1 + 2) * 3`, while
26+
let v1 = { 1 + { 2 } * { 3 } };
27+
28+
// `v2` evaluated to 7, indicating a parse of `1 + (2 * 3)`.
29+
let v2 = 1 + { 2 } * { 3 };
30+
31+
// Check that both now evaluate to 7, as was fixed by #30375.
32+
assert_eq!(v1, 7);
33+
assert_eq!(v2, 7);
34+
}
35+
1036
fn main() {
1137
assert_eq!(4, that_odd_parse(true, 1));
1238
assert_eq!(8, that_odd_parse(false, 1));
39+
40+
check_issue_28777();
1341
}

0 commit comments

Comments
 (0)