Skip to content

Commit

Permalink
Rollup merge of rust-lang#92414 - dtolnay:constnoexpr, r=oli-obk
Browse files Browse the repository at this point in the history
Fix spacing of pretty printed const item without body

Follow-up to rust-lang#92238 fixing one of the FIXMEs.

```rust
macro_rules! repro {
    ($item:item) => {
        stringify!($item)
    };
}

fn main() {
    println!("{}", repro!(extern "C" { static S: i32; }));
}
```

Before: `extern "C" { static S: i32 ; }`
After: `extern "C" { static S: i32; }`
  • Loading branch information
matthiaskrgr committed Dec 30, 2021
2 parents b9f7197 + b621635 commit e810487
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
4 changes: 3 additions & 1 deletion compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,9 @@ impl<'a> State<'a> {
self.print_ident(ident);
self.word_space(":");
self.print_type(ty);
self.space();
if body.is_some() {
self.space();
}
self.end(); // end the head-ibox
if let Some(body) = body {
self.word_space("=");
Expand Down
20 changes: 10 additions & 10 deletions src/test/pretty/nested-item-vis-defaultness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,42 @@ fn main() {}

#[cfg(FALSE)]
extern "C" {
static X: u8 ;
static X: u8;
type X;
fn foo();
pub static X: u8 ;
pub static X: u8;
pub type X;
pub fn foo();
}

#[cfg(FALSE)]
trait T {
const X: u8 ;
const X: u8;
type X;
fn foo();
default const X: u8 ;
default const X: u8;
default type X;
default fn foo();
pub const X: u8 ;
pub const X: u8;
pub type X;
pub fn foo();
pub default const X: u8 ;
pub default const X: u8;
pub default type X;
pub default fn foo();
}

#[cfg(FALSE)]
impl T for S {
const X: u8 ;
const X: u8;
type X;
fn foo();
default const X: u8 ;
default const X: u8;
default type X;
default fn foo();
pub const X: u8 ;
pub const X: u8;
pub type X;
pub fn foo();
pub default const X: u8 ;
pub default const X: u8;
pub default type X;
pub default fn foo();
}
6 changes: 3 additions & 3 deletions src/test/ui/macros/stringify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,13 @@ fn test_item() {
stringify_item!(
static S: ();
),
"static S: () ;", // FIXME
"static S: ();",
);
assert_eq!(
stringify_item!(
static mut S: ();
),
"static mut S: () ;",
"static mut S: ();",
);

// ItemKind::Const
Expand All @@ -402,7 +402,7 @@ fn test_item() {
stringify_item!(
const S: ();
),
"const S: () ;", // FIXME
"const S: ();",
);

// ItemKind::Fn
Expand Down

0 comments on commit e810487

Please sign in to comment.