diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-01-27 10:48:46 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-27 10:48:46 +0100 |
| commit | 9a4417659e60a677f3dc0204c28cedfc6a6e4d91 (patch) | |
| tree | 3e183cd47492d7ec85c5ac5e38ea18d81b9c3452 /tests/ui/parser | |
| parent | 04521fd10e6eefb113ca1cefd02862599fd08640 (diff) | |
| parent | a5d9def321df76de6fb90ed836bf062b557636d6 (diff) | |
| download | rust-9a4417659e60a677f3dc0204c28cedfc6a6e4d91.tar.gz rust-9a4417659e60a677f3dc0204c28cedfc6a6e4d91.zip | |
Rollup merge of #118182 - estebank:issue-118164, r=davidtwco
Properly recover from trailing attr in body When encountering an attribute in a body, we try to recover from an attribute on an expression (as opposed to a statement). We need to properly clean up when the attribute is at the end of the body where a tail expression would be. Fix #118164, fix #118575.
Diffstat (limited to 'tests/ui/parser')
| -rw-r--r-- | tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body.rs | 9 | ||||
| -rw-r--r-- | tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body.stderr | 27 |
2 files changed, 36 insertions, 0 deletions
diff --git a/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body.rs b/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body.rs new file mode 100644 index 00000000000..a7412f51782 --- /dev/null +++ b/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body.rs @@ -0,0 +1,9 @@ +// Issue #118164: recovery path leaving unemitted error behind +fn bar() -> String { + #[cfg(feature = )] + [1, 2, 3].iter().map().collect::<String>() //~ ERROR expected `;`, found `#` + #[attr] //~ ERROR expected statement after outer attribute +} +fn main() { + let _ = bar(); +} diff --git a/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body.stderr b/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body.stderr new file mode 100644 index 00000000000..dd0081cc2df --- /dev/null +++ b/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body.stderr @@ -0,0 +1,27 @@ +error: expected `;`, found `#` + --> $DIR/properly-recover-from-trailing-outer-attribute-in-body.rs:4:47 + | +LL | #[cfg(feature = )] + | ------------------ only `;` terminated statements or tail expressions are allowed after this attribute +LL | [1, 2, 3].iter().map().collect::<String>() + | ^ expected `;` here +LL | #[attr] + | - unexpected token + | +help: add `;` here + | +LL | [1, 2, 3].iter().map().collect::<String>(); + | + +help: alternatively, consider surrounding the expression with a block + | +LL | { [1, 2, 3].iter().map().collect::<String>() } + | + + + +error: expected statement after outer attribute + --> $DIR/properly-recover-from-trailing-outer-attribute-in-body.rs:5:5 + | +LL | #[attr] + | ^^^^^^^ + +error: aborting due to 2 previous errors + |
