Skip to content

Commit e810487

Browse files
authored
Rollup merge of rust-lang#92414 - dtolnay:constnoexpr, r=oli-obk
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; }`
2 parents b9f7197 + b621635 commit e810487

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

Diff for: compiler/rustc_ast_pretty/src/pprust/state.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,9 @@ impl<'a> State<'a> {
11161116
self.print_ident(ident);
11171117
self.word_space(":");
11181118
self.print_type(ty);
1119-
self.space();
1119+
if body.is_some() {
1120+
self.space();
1121+
}
11201122
self.end(); // end the head-ibox
11211123
if let Some(body) = body {
11221124
self.word_space("=");

Diff for: src/test/pretty/nested-item-vis-defaultness.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,42 @@ fn main() {}
66

77
#[cfg(FALSE)]
88
extern "C" {
9-
static X: u8 ;
9+
static X: u8;
1010
type X;
1111
fn foo();
12-
pub static X: u8 ;
12+
pub static X: u8;
1313
pub type X;
1414
pub fn foo();
1515
}
1616

1717
#[cfg(FALSE)]
1818
trait T {
19-
const X: u8 ;
19+
const X: u8;
2020
type X;
2121
fn foo();
22-
default const X: u8 ;
22+
default const X: u8;
2323
default type X;
2424
default fn foo();
25-
pub const X: u8 ;
25+
pub const X: u8;
2626
pub type X;
2727
pub fn foo();
28-
pub default const X: u8 ;
28+
pub default const X: u8;
2929
pub default type X;
3030
pub default fn foo();
3131
}
3232

3333
#[cfg(FALSE)]
3434
impl T for S {
35-
const X: u8 ;
35+
const X: u8;
3636
type X;
3737
fn foo();
38-
default const X: u8 ;
38+
default const X: u8;
3939
default type X;
4040
default fn foo();
41-
pub const X: u8 ;
41+
pub const X: u8;
4242
pub type X;
4343
pub fn foo();
44-
pub default const X: u8 ;
44+
pub default const X: u8;
4545
pub default type X;
4646
pub default fn foo();
4747
}

Diff for: src/test/ui/macros/stringify.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,13 @@ fn test_item() {
382382
stringify_item!(
383383
static S: ();
384384
),
385-
"static S: () ;", // FIXME
385+
"static S: ();",
386386
);
387387
assert_eq!(
388388
stringify_item!(
389389
static mut S: ();
390390
),
391-
"static mut S: () ;",
391+
"static mut S: ();",
392392
);
393393

394394
// ItemKind::Const
@@ -402,7 +402,7 @@ fn test_item() {
402402
stringify_item!(
403403
const S: ();
404404
),
405-
"const S: () ;", // FIXME
405+
"const S: ();",
406406
);
407407

408408
// ItemKind::Fn

0 commit comments

Comments
 (0)