Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A shebang is displaced in HIR & expanded outputs #134643

Open
fluiderson opened this issue Dec 22, 2024 · 1 comment
Open

A shebang is displaced in HIR & expanded outputs #134643

fluiderson opened this issue Dec 22, 2024 · 1 comment
Labels
A-pretty Area: Pretty printing (including `-Z unpretty`) C-enhancement Category: An issue proposing an enhancement or a PR with one. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@fluiderson
Copy link

I tried this code:

#!/usr/bin/env rust

fn test() {}

After running rustc -Zunpretty=hir test.rs, I expected to see this happen:

#!/usr/bin/env rust
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;

fn test() { }

Instead, this happened:

#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
#!/usr/bin/env rust

fn test() { }

A shebang should remain at the beginning of an output but instead is placed in-between. The same happens with rustc -Zunpretty=expanded test.rs.

Meta

rustc --version --verbose:

rustc 1.85.0-nightly (5f23ef7d3 2024-12-20)
binary: rustc
commit-hash: 5f23ef7d3f7a8c3e0ca5c4e1978829c0448a3686
commit-date: 2024-12-20
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.6
@fluiderson fluiderson added the C-bug Category: This is a bug. label Dec 22, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 22, 2024
@fmease fmease added A-pretty Area: Pretty printing (including `-Z unpretty`) requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-enhancement Category: An issue proposing an enhancement or a PR with one. and removed C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 22, 2024
@fmease
Copy link
Member

fmease commented Dec 22, 2024

Marking this as an enhancement instead of a bug because technically speaking we don't guarantee anything about the shape of the output produced by -Zunpretty. Of course, a PR fixing this would be very welcome regardless :)

Some breadcrumbs: Both -Zunpretty={expanded,hir} / rustc_{ast,hir}_pretty collect comments (which includes shebangs) via rustc_ast_pretty::pprust::state::Comments:

pub struct Comments<'a> {
sm: &'a SourceMap,
// Stored in reverse order so we can consume them by popping.
reversed_comments: Vec<Comment>,
}

And print them again via maybe_print_comment / print_remaining_comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-pretty Area: Pretty printing (including `-Z unpretty`) C-enhancement Category: An issue proposing an enhancement or a PR with one. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants