-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
3 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
27 changes: 27 additions & 0 deletions
27
tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|