diff options
| author | bors <bors@rust-lang.org> | 2024-05-12 04:18:20 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-05-12 04:18:20 +0000 |
| commit | 8cc6f34653505e13159d62ad9de4c7b7a43b9e39 (patch) | |
| tree | 0bfc6ceb1172777485709c92dd0a1077df730775 /compiler/rustc_errors/src/snippet.rs | |
| parent | ee97564e3a9f9ac8c65103abb37c6aa48d95bfa2 (diff) | |
| parent | 78c8dc123495f19b2da8e655cd5b95fff161c8c1 (diff) | |
| download | rust-8cc6f34653505e13159d62ad9de4c7b7a43b9e39.tar.gz rust-8cc6f34653505e13159d62ad9de4c7b7a43b9e39.zip | |
Auto merge of #119427 - dtolnay:maccall, r=compiler-errors
Fix, document, and test parser and pretty-printer edge cases related to braced macro calls
_Review note: this is a deceptively small PR because it comes with 145 lines of docs and 196 lines of tests, and only 25 lines of compiler code changed. However, I recommend reviewing it 1 commit at a time because much of the effect of the code changes is non-local i.e. affecting code that is not visible in the final state of the PR. I have paid attention that reviewing the PR one commit at a time is as easy as I can make it. All of the code you need to know about is touched in those commits, even if some of those changes disappear by the end of the stack._
This is a follow-up to https://github.com/rust-lang/rust/pull/119105. One case that is not relevant to `-Zunpretty=expanded`, but which came up as I'm porting #119105 and #118726 into `syn`'s printer and `prettyplease`'s printer where it **is** relevant, and is also relevant to rustc's `stringify!`, is statement boundaries in the vicinity of braced macro calls.
Rustc's AST pretty-printer produces invalid syntax for statements that begin with a braced macro call:
```rust
macro_rules! stringify_item {
($i:item) => {
stringify!($i)
};
}
macro_rules! repro {
($e:expr) => {
stringify_item!(fn main() { $e + 1; })
};
}
fn main() {
println!("{}", repro!(m! {}));
}
```
**Before this PR:** output is not valid Rust syntax.
```console
fn main() { m! {} + 1; }
```
```console
error: leading `+` is not supported
--> <anon>:1:19
|
1 | fn main() { m! {} + 1; }
| ^ unexpected `+`
|
help: try removing the `+`
|
1 - fn main() { m! {} + 1; }
1 + fn main() { m! {} 1; }
|
```
**After this PR:** valid syntax.
```console
fn main() { (m! {}) + 1; }
```
Diffstat (limited to 'compiler/rustc_errors/src/snippet.rs')
0 files changed, 0 insertions, 0 deletions
