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

AST pretty-printer produces invalid syntax for unsafe extern statics #132080

Closed
dtolnay opened this issue Oct 23, 2024 · 0 comments · Fixed by #132088
Closed

AST pretty-printer produces invalid syntax for unsafe extern statics #132080

dtolnay opened this issue Oct 23, 2024 · 0 comments · Fixed by #132088
Assignees
Labels
A-pretty Area: Pretty printing (including `-Z unpretty`) C-bug Category: This is a bug. F-unsafe_extern_blocks `#![feature(unsafe_extern_blocks)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@dtolnay
Copy link
Member

dtolnay commented Oct 23, 2024

$ echo 'unsafe extern { pub unsafe static STATIC: (); }' | rustc -Zunpretty=expanded -
#![feature(prelude_import)]
#![no_std]
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
unsafe extern {
    unsafe pub static STATIC: ();
}

The syntax printed by rustc is not valid Rust syntax.

error: expected one of `extern` or `fn`, found keyword `pub`
 --> <anon>:8:12
  |
7 | unsafe extern {
  |               - while parsing this item list starting here
8 |     unsafe pub static STATIC: ();
  |     -------^^^
  |     |      |
  |     |      expected one of `extern` or `fn`
  |     help: visibility `pub` must come before `unsafe`: `pub unsafe`
9 | }
  | - the item list ends here

Meta

rustc --version --verbose:

rustc 1.84.0-nightly (86d69c705 2024-10-22)
binary: rustc
commit-hash: 86d69c705a552236a622eee3fdea94bf13c5f102
commit-date: 2024-10-22
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1
@dtolnay dtolnay added A-pretty Area: Pretty printing (including `-Z unpretty`) C-bug Category: This is a bug. F-unsafe_extern_blocks `#![feature(unsafe_extern_blocks)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 23, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 23, 2024
@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 23, 2024
@compiler-errors compiler-errors self-assigned this Oct 24, 2024
@bors bors closed this as completed in 7e2bbc3 Oct 24, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 24, 2024
Rollup merge of rust-lang#132088 - compiler-errors:extern-static, r=jieyouxu

Print safety correctly in extern static items

Fixes rust-lang#132080

r? spastorino or anyone really
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-bug Category: This is a bug. F-unsafe_extern_blocks `#![feature(unsafe_extern_blocks)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants