Skip to content

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

Closed
@dtolnay

Description

@dtolnay
$ 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

Metadata

Metadata

Labels

A-prettyArea: Pretty printing (including `-Z unpretty`)C-bugCategory: This is a bug.F-unsafe_extern_blocks`#![feature(unsafe_extern_blocks)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions