diff options
| author | 许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com> | 2024-12-08 14:45:24 +0800 |
|---|---|---|
| committer | 许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com> | 2024-12-08 15:32:04 +0800 |
| commit | 3a33522ca87202d52cb568d7710cfc3543aaf39e (patch) | |
| tree | 65e1a9d6849a85ef3f9422a3dfe794f0546ae8f2 /tests | |
| parent | b815a9361423e7d18ab7458650ee366f8cf5e3d0 (diff) | |
| download | rust-3a33522ca87202d52cb568d7710cfc3543aaf39e.tar.gz rust-3a33522ca87202d52cb568d7710cfc3543aaf39e.zip | |
Adjust `assoc-oddities-3.rs`
- Include the original MCVE as reported in <https://github.com/rust-lang/rust/issues/28777>. - Document the intention of the test.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/parser/assoc/assoc-oddities-3.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/ui/parser/assoc/assoc-oddities-3.rs b/tests/ui/parser/assoc/assoc-oddities-3.rs index ffde2ccf786..1a41c4be023 100644 --- a/tests/ui/parser/assoc/assoc-oddities-3.rs +++ b/tests/ui/parser/assoc/assoc-oddities-3.rs @@ -1,3 +1,10 @@ +//! Check that braces has the expected precedence in relation to index op and some arithmetic +//! bin-ops involving nested braces. +//! +//! This is a regression test for [Wrapping expr in curly braces changes the operator precedence +//! #28777](https://github.com/rust-lang/rust/issues/28777), which was fixed by +//! <https://github.com/rust-lang/rust/pull/30375>. + //@ run-pass fn that_odd_parse(c: bool, n: usize) -> u32 { @@ -7,7 +14,28 @@ fn that_odd_parse(c: bool, n: usize) -> u32 { x + if c { a } else { b }[n] } +/// See [Wrapping expr in curly braces changes the operator precedence +/// #28777](https://github.com/rust-lang/rust/issues/28777). This was fixed by +/// <https://github.com/rust-lang/rust/pull/30375>. #30375 added the `that_odd_parse` example above, +/// but that is not *quite* the same original example as reported in #28777, so we also include the +/// original example here. +fn check_issue_28777() { + // Before #30375 fixed the precedence... + + // ... `v1` evaluated to 9, indicating a parse of `(1 + 2) * 3`, while + let v1 = { 1 + { 2 } * { 3 } }; + + // `v2` evaluated to 7, indicating a parse of `1 + (2 * 3)`. + let v2 = 1 + { 2 } * { 3 }; + + // Check that both now evaluate to 7, as was fixed by #30375. + assert_eq!(v1, 7); + assert_eq!(v2, 7); +} + fn main() { assert_eq!(4, that_odd_parse(true, 1)); assert_eq!(8, that_odd_parse(false, 1)); + + check_issue_28777(); } |
