The extra newline in unpretty=hir
Open
Nobody has claimed this yet.
A-pretty
C-bug
requires-nightly
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code when dump the hir by -Z unpretty=hir:
// file: procedural macro
extern crate proc_macro;
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, Expr};
#[proc_macro]
pub fn mdriver(input: TokenStream) -> TokenStream {
let body = parse_macro_input!(input as Expr);
let expanded = quote! {
fn main() {
#body
}
};
TokenStream::from(expanded)
}
// file: macro call
mdriver!({
println!("Hello, world!");
});
mdriver!({
println!("Hello, world!");
});
mdriver!({
println!("Hello, world!");
});
mdriver!({
println!("Hello, world!");
});
mdriver!({
println!("Hello, world!");
});
I expected to see this happen:
fn main() {
{
{
::std::io::_print(format_arguments::new_const(&["Hello, world!\n"]));
};
}
}
fn main() {
{
{
::std::io::_print(format_arguments::new_const(&["Hello, world!\n"]));
};
}
}
....................
Instead, this happened:
fn main() {
{
// unexpected newline here
{
::std::io::_print(format_arguments::new_const(&["Hello, world!\n"]));
};
}
}
fn main() {
{
{
::std::io::_print(format_arguments::new_const(&["Hello, world!\n"]));
};
}
}
...........
Meta
rustc --version --verbose:
rustc 1.80.0-nightly (ef0027897 2024-05-12)
binary: rustc
commit-hash: ef0027897d2e9014766fb47dce9ddbb925d2f540
commit-date: 2024-05-12
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.4
Backtrace
<backtrace>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the supplied Rust procedural-macro example and -Z unpretty=hir, comparing the first expanded invocation with later ones. Trace the compiler entry point responsible for unpretty HIR output and identify why extra blank lines appear between expansions. Done means the output no longer contains the unexpected newline and a regression test covers repeated macro invocations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100