1
Fork 0

Rollup merge of #91437 - dtolnay:emptybrace, r=nagisa

Pretty print empty blocks as {}

**Example:**

```rust
macro_rules! p {
    ($e:expr) => {
        println!("{}", stringify!($e));
    };
    ($i:item) => {
        println!("{}", stringify!($i));
    };
}

fn main() {
    p!(if true {});
    p!(struct S {});
}
```

**Before:**

```console
if true { }
struct S {
}
```

**After:**

```console
if true {}
struct S {}
```

This affects [`dbg!`](https://doc.rust-lang.org/std/macro.dbg.html), as well as ecosystem uses of stringify such as in [`anyhow::ensure!`](https://docs.rs/anyhow/1/anyhow/macro.ensure.html). Printing a `{ }` in today's heavily rustfmt'd world comes out looking jarring/sloppy.
This commit is contained in:
Matthias Krüger 2021-12-05 15:04:20 +01:00 committed by GitHub
commit a8f8f746fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
63 changed files with 182 additions and 164 deletions

View file

@ -263,14 +263,17 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
self.strsep(",", false, b, elts, op) self.strsep(",", false, b, elts, op)
} }
fn maybe_print_comment(&mut self, pos: BytePos) { fn maybe_print_comment(&mut self, pos: BytePos) -> bool {
let mut has_comment = false;
while let Some(ref cmnt) = self.next_comment() { while let Some(ref cmnt) = self.next_comment() {
if cmnt.pos < pos { if cmnt.pos < pos {
has_comment = true;
self.print_comment(cmnt); self.print_comment(cmnt);
} else { } else {
break; break;
} }
} }
has_comment
} }
fn print_comment(&mut self, cmnt: &Comment) { fn print_comment(&mut self, cmnt: &Comment) {
@ -570,7 +573,10 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
self.print_tts(tts, convert_dollar_crate); self.print_tts(tts, convert_dollar_crate);
self.end(); self.end();
match delim { match delim {
DelimToken::Brace => self.bclose(span), DelimToken::Brace => {
let empty = tts.is_empty();
self.bclose(span, empty);
}
_ => { _ => {
let token_str = self.token_kind_to_string(&token::CloseDelim(delim)); let token_str = self.token_kind_to_string(&token::CloseDelim(delim));
self.word(token_str) self.word(token_str)
@ -642,17 +648,20 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
self.end(); // Close the head-box. self.end(); // Close the head-box.
} }
fn bclose_maybe_open(&mut self, span: rustc_span::Span, close_box: bool) { fn bclose_maybe_open(&mut self, span: rustc_span::Span, empty: bool, close_box: bool) {
self.maybe_print_comment(span.hi()); let has_comment = self.maybe_print_comment(span.hi());
if !empty || has_comment {
self.break_offset_if_not_bol(1, -(INDENT_UNIT as isize)); self.break_offset_if_not_bol(1, -(INDENT_UNIT as isize));
}
self.word("}"); self.word("}");
if close_box { if close_box {
self.end(); // Close the outer-box. self.end(); // Close the outer-box.
} }
} }
fn bclose(&mut self, span: rustc_span::Span) { fn bclose(&mut self, span: rustc_span::Span, empty: bool) {
self.bclose_maybe_open(span, true) let close_box = true;
self.bclose_maybe_open(span, empty, close_box)
} }
fn break_offset_if_not_bol(&mut self, n: usize, off: isize) { fn break_offset_if_not_bol(&mut self, n: usize, off: isize) {
@ -1196,7 +1205,8 @@ impl<'a> State<'a> {
for item in items { for item in items {
self.print_item(item); self.print_item(item);
} }
self.bclose(item.span); let empty = item.attrs.is_empty() && items.is_empty();
self.bclose(item.span, empty);
} }
ModKind::Unloaded => { ModKind::Unloaded => {
self.s.word(";"); self.s.word(";");
@ -1216,7 +1226,8 @@ impl<'a> State<'a> {
} }
self.bopen(); self.bopen();
self.print_foreign_mod(nmod, &item.attrs); self.print_foreign_mod(nmod, &item.attrs);
self.bclose(item.span); let empty = item.attrs.is_empty() && nmod.items.is_empty();
self.bclose(item.span, empty);
} }
ast::ItemKind::GlobalAsm(ref asm) => { ast::ItemKind::GlobalAsm(ref asm) => {
self.head(visibility_qualified(&item.vis, "global_asm!")); self.head(visibility_qualified(&item.vis, "global_asm!"));
@ -1291,7 +1302,8 @@ impl<'a> State<'a> {
for impl_item in items { for impl_item in items {
self.print_assoc_item(impl_item); self.print_assoc_item(impl_item);
} }
self.bclose(item.span); let empty = item.attrs.is_empty() && items.is_empty();
self.bclose(item.span, empty);
} }
ast::ItemKind::Trait(box ast::Trait { ast::ItemKind::Trait(box ast::Trait {
is_auto, is_auto,
@ -1326,7 +1338,8 @@ impl<'a> State<'a> {
for trait_item in items { for trait_item in items {
self.print_assoc_item(trait_item); self.print_assoc_item(trait_item);
} }
self.bclose(item.span); let empty = item.attrs.is_empty() && items.is_empty();
self.bclose(item.span, empty);
} }
ast::ItemKind::TraitAlias(ref generics, ref bounds) => { ast::ItemKind::TraitAlias(ref generics, ref bounds) => {
self.head(""); self.head("");
@ -1410,7 +1423,8 @@ impl<'a> State<'a> {
self.end(); self.end();
self.maybe_print_trailing_comment(v.span, None); self.maybe_print_trailing_comment(v.span, None);
} }
self.bclose(span) let empty = variants.is_empty();
self.bclose(span, empty)
} }
crate fn print_visibility(&mut self, vis: &ast::Visibility) { crate fn print_visibility(&mut self, vis: &ast::Visibility) {
@ -1441,6 +1455,9 @@ impl<'a> State<'a> {
crate fn print_record_struct_body(&mut self, fields: &[ast::FieldDef], span: rustc_span::Span) { crate fn print_record_struct_body(&mut self, fields: &[ast::FieldDef], span: rustc_span::Span) {
self.nbsp(); self.nbsp();
self.bopen(); self.bopen();
let empty = fields.is_empty();
if !empty {
self.hardbreak_if_not_bol(); self.hardbreak_if_not_bol();
for field in fields { for field in fields {
@ -1453,8 +1470,9 @@ impl<'a> State<'a> {
self.print_type(&field.ty); self.print_type(&field.ty);
self.s.word(","); self.s.word(",");
} }
}
self.bclose(span) self.bclose(span, empty);
} }
crate fn print_struct( crate fn print_struct(
@ -1633,7 +1651,8 @@ impl<'a> State<'a> {
} }
} }
self.bclose_maybe_open(blk.span, close_box); let empty = attrs.is_empty() && blk.stmts.is_empty();
self.bclose_maybe_open(blk.span, empty, close_box);
self.ann.post(self, AnnNode::Block(blk)) self.ann.post(self, AnnNode::Block(blk))
} }
@ -2010,7 +2029,8 @@ impl<'a> State<'a> {
for arm in arms { for arm in arms {
self.print_arm(arm); self.print_arm(arm);
} }
self.bclose(expr.span); let empty = attrs.is_empty() && arms.is_empty();
self.bclose(expr.span, empty);
} }
ast::ExprKind::Closure( ast::ExprKind::Closure(
capture_clause, capture_clause,

View file

@ -2174,7 +2174,7 @@ impl<'a> State<'a> {
match decl.output { match decl.output {
hir::FnRetTy::Return(ref ty) => { hir::FnRetTy::Return(ref ty) => {
self.print_type(&ty); self.print_type(&ty);
self.maybe_print_comment(ty.span.lo()) self.maybe_print_comment(ty.span.lo());
} }
hir::FnRetTy::DefaultReturn(..) => unreachable!(), hir::FnRetTy::DefaultReturn(..) => unreachable!(),
} }
@ -2368,7 +2368,7 @@ impl<'a> State<'a> {
self.end(); self.end();
if let hir::FnRetTy::Return(ref output) = decl.output { if let hir::FnRetTy::Return(ref output) = decl.output {
self.maybe_print_comment(output.span.lo()) self.maybe_print_comment(output.span.lo());
} }
} }

View file

@ -1,6 +1,6 @@
// pp-exact // pp-exact
fn main() { } fn main() {}
#[cfg(FALSE)] #[cfg(FALSE)]
fn syntax() { fn syntax() {
@ -117,7 +117,7 @@ fn syntax() {
let _ = #[attr] foo!(#! [attr]); let _ = #[attr] foo!(#! [attr]);
let _ = #[attr] foo![]; let _ = #[attr] foo![];
let _ = #[attr] foo![#! [attr]]; let _ = #[attr] foo![#! [attr]];
let _ = #[attr] foo! { }; let _ = #[attr] foo! {};
let _ = #[attr] foo! { #! [attr] }; let _ = #[attr] foo! { #! [attr] };
let _ = #[attr] Foo{bar: baz,}; let _ = #[attr] Foo{bar: baz,};
let _ = #[attr] Foo{..foo}; let _ = #[attr] Foo{..foo};
@ -135,7 +135,7 @@ fn syntax() {
foo!(); foo!();
#[attr] #[attr]
foo! { } foo! {}
#[attr] #[attr]
foo![]; foo![];
@ -170,6 +170,6 @@ fn syntax() {
{ {
#[attr] #[attr]
foo! { } foo! {}
} }
} }

View file

@ -29,4 +29,4 @@ enum Enum {
Qwerty, Qwerty,
} }
fn main() { } fn main() {}

View file

@ -2,8 +2,8 @@
// pp-exact // pp-exact
auto trait MyTrait { } auto trait MyTrait {}
unsafe auto trait UnsafeMyTrait { } unsafe auto trait UnsafeMyTrait {}
pub fn main() { } pub fn main() {}

View file

@ -1,8 +1,7 @@
// compile-flags: --crate-type=lib // compile-flags: --crate-type=lib
// pp-exact // pp-exact
fn f() { fn f() {} /*
} /*
The next line should not be indented. The next line should not be indented.
That one. It shouldn't have been indented. That one. It shouldn't have been indented.

View file

@ -3,14 +3,14 @@
// pp-exact // pp-exact
fn call_it(f: Box<FnMut(String) -> String>) { } fn call_it(f: Box<FnMut(String) -> String>) {}
fn call_this<F>(f: F) where F: Fn(&str) + Send { } fn call_this<F>(f: F) where F: Fn(&str) + Send {}
fn call_that<F>(f: F) where F: for<'a> Fn(&'a isize, &'a isize) -> isize { } fn call_that<F>(f: F) where F: for<'a> Fn(&'a isize, &'a isize) -> isize {}
fn call_extern(f: fn() -> isize) { } fn call_extern(f: fn() -> isize) {}
fn call_abid_extern(f: extern "C" fn() -> isize) { } fn call_abid_extern(f: extern "C" fn() -> isize) {}
pub fn main() { } pub fn main() {}

View file

@ -7,4 +7,4 @@
fn id<F>(f: F) -> isize where F: Fn() -> isize { f() } fn id<F>(f: F) -> isize where F: Fn() -> isize { f() }
fn wsucc(_n: isize) -> isize { id(|| { 1 }) - 0 } fn wsucc(_n: isize) -> isize { id(|| { 1 }) - 0 }
fn main() { } fn main() {}

View file

@ -2,7 +2,7 @@
// Check that the visibility is printed on an enum variant. // Check that the visibility is printed on an enum variant.
fn main() { } fn main() {}
#[cfg(FALSE)] #[cfg(FALSE)]
enum Foo { pub V, } enum Foo { pub V, }

View file

@ -1,3 +1,3 @@
// pp-exact // pp-exact
fn main() { } fn main() {}

View file

@ -1,3 +1,3 @@
// pp-exact:example2.pp // pp-exact:example2.pp
fn main() { } fn main() {}

View file

@ -1,3 +1,3 @@
// pp-exact:example2.pp // pp-exact:example2.pp
fn main() { } fn main() {}

View file

@ -10,4 +10,4 @@ extern crate std;
// pp-exact:expanded-and-path-remap-80832.pp // pp-exact:expanded-and-path-remap-80832.pp
// compile-flags: --remap-path-prefix {{src-base}}=the/src // compile-flags: --remap-path-prefix {{src-base}}=the/src
fn main() { } fn main() {}

View file

@ -1,7 +1,7 @@
// pp-exact // pp-exact
// Check that `fn f() -> () { }` does not print as `fn f() { }`. // Check that `fn f() -> () {}` does not print as `fn f() {}`.
fn f() -> () { } fn f() -> () {}
fn main() { } fn main() {}

View file

@ -1,5 +1,5 @@
// pp-exact // pp-exact
fn from_foreign_fn(_x: fn()) { } fn from_foreign_fn(_x: fn()) {}
fn from_stack_closure<F>(_x: F) where F: Fn() { } fn from_stack_closure<F>(_x: F) where F: Fn() {}
fn main() { } fn main() {}

View file

@ -12,4 +12,4 @@ pub unsafe extern "C" fn bar(_: i32, mut ap: ...) -> usize {
ap.arg::<usize>() ap.arg::<usize>()
} }
fn main() { } fn main() {}

View file

@ -4,34 +4,34 @@
fn simple_attr() { fn simple_attr() {
#[attr] #[attr]
if true { } if true {}
#[allow_warnings] #[allow_warnings]
if true { } if true {}
} }
#[cfg(FALSE)] #[cfg(FALSE)]
fn if_else_chain() { fn if_else_chain() {
#[first_attr] #[first_attr]
if true { } else if false { } else { } if true {} else if false {} else {}
} }
#[cfg(FALSE)] #[cfg(FALSE)]
fn if_let() { fn if_let() {
#[attr] #[attr]
if let Some(_) = Some(true) { } if let Some(_) = Some(true) {}
} }
#[cfg(FALSE)] #[cfg(FALSE)]
fn let_attr_if() { fn let_attr_if() {
let _ = #[attr] if let _ = 0 { }; let _ = #[attr] if let _ = 0 {};
let _ = #[attr] if true { }; let _ = #[attr] if true {};
let _ = #[attr] if let _ = 0 { } else { }; let _ = #[attr] if let _ = 0 {} else {};
let _ = #[attr] if true { } else { }; let _ = #[attr] if true {} else {};
} }
fn main() { } fn main() {}

View file

@ -6,4 +6,4 @@
#[path = "issue-12590-b.rs"] #[path = "issue-12590-b.rs"]
mod issue_12590_b; mod issue_12590_b;
fn main() { } fn main() {}

View file

@ -13,7 +13,7 @@ extern crate std;
#[path = "issue-12590-b.rs"] #[path = "issue-12590-b.rs"]
mod issue_12590_b { mod issue_12590_b {
fn b() { } fn b() {}
fn main() { } fn main() {}
} }
fn main() { } fn main() {}

View file

@ -7,4 +7,4 @@
#[path = "issue-12590-b.rs"] #[path = "issue-12590-b.rs"]
mod issue_12590_b; mod issue_12590_b;
fn main() { } fn main() {}

View file

@ -4,8 +4,8 @@
fn main() { fn main() {
match true { match true {
true if true => (), true if true => (),
false if false => unsafe { }, false if false => unsafe {},
true => { } true => {}
false => (), false => (),
} }
} }

View file

@ -5,4 +5,4 @@
// pretty-compare-only // pretty-compare-only
// pp-exact // pp-exact
fn main() { b! { } c } fn main() { b! {} c }

View file

@ -1,6 +1,6 @@
// pp-exact // pp-exact
fn main() { } fn main() {}
struct C { struct C {
field: u8, field: u8,

View file

@ -1,5 +1,5 @@
// pp-exact // pp-exact
fn f1<'a, 'b, 'c>(_x: &'a u32, _y: &'b u32, _z: &'c u32) where 'c: 'a + 'b { } fn f1<'a, 'b, 'c>(_x: &'a u32, _y: &'b u32, _z: &'c u32) where 'c: 'a + 'b {}
fn main() { } fn main() {}

View file

@ -4,4 +4,4 @@
pub(crate) macro mac { ($arg : expr) => { $arg + $arg } } pub(crate) macro mac { ($arg : expr) => { $arg + $arg } }
fn main() { } fn main() {}

View file

@ -1,19 +1,19 @@
// pp-exact // pp-exact
macro_rules! brace { () => { } ; } macro_rules! brace { () => {} ; }
macro_rules! bracket[() => { } ;]; macro_rules! bracket[() => {} ;];
macro_rules! paren(() => { } ;); macro_rules! paren(() => {} ;);
macro_rules! matcher_brackets { macro_rules! matcher_brackets {
(paren) => { } ; (bracket) => { } ; (brace) => { } ; (paren) => {} ; (bracket) => {} ; (brace) => {} ;
} }
macro_rules! all_fragments { macro_rules! all_fragments {
($b : block, $e : expr, $i : ident, $it : item, $l : lifetime, $lit : ($b : block, $e : expr, $i : ident, $it : item, $l : lifetime, $lit :
literal, $m : meta, $p : pat, $pth : path, $s : stmt, $tt : tt, $ty : ty, literal, $m : meta, $p : pat, $pth : path, $s : stmt, $tt : tt, $ty : ty,
$vis : vis) => { } ; $vis : vis) => {} ;
} }
fn main() { } fn main() {}

View file

@ -2,7 +2,7 @@
// pp-exact // pp-exact
fn main() { } fn main() {}
#[cfg(FALSE)] #[cfg(FALSE)]
extern "C" { extern "C" {

View file

@ -2,9 +2,9 @@
trait Tr { trait Tr {
fn dummy(&self) { } fn dummy(&self) {}
} }
impl Tr for isize { } impl Tr for isize {}
fn foo<'a>(x: Box<Tr + Sync + 'a>) -> Box<Tr + Sync + 'a> { x } fn foo<'a>(x: Box<Tr + Sync + 'a>) -> Box<Tr + Sync + 'a> { x }

View file

@ -8,9 +8,9 @@ mod m {
} }
trait Tu { trait Tu {
fn dummy() { } fn dummy() {}
} }
fn foo<T: m::Tr>() { <T as m::Tr>::Ts::dummy(); } fn foo<T: m::Tr>() { <T as m::Tr>::Ts::dummy(); }
fn main() { } fn main() {}

View file

@ -4,7 +4,7 @@
#![feature(rustc_attrs)] #![feature(rustc_attrs)]
#![feature(stmt_expr_attributes)] #![feature(stmt_expr_attributes)]
fn main() { } fn main() {}
fn _0() { fn _0() {
@ -35,7 +35,7 @@ fn _2() {
fn _3() { fn _3() {
#[rustc_dummy] #[rustc_dummy]
match () { _ => { } } match () { _ => {} }
} }
fn _4() { fn _4() {
@ -117,13 +117,13 @@ fn _9() {
stmt_mac!(); stmt_mac!();
#[rustc_dummy] #[rustc_dummy]
stmt_mac! { }; stmt_mac! {};
#[rustc_dummy] #[rustc_dummy]
stmt_mac![]; stmt_mac![];
#[rustc_dummy] #[rustc_dummy]
stmt_mac! { } stmt_mac! {}
let _ = (); let _ = ();
} }
@ -133,7 +133,7 @@ macro_rules! expr_mac { () => { () } }
fn _10() { fn _10() {
let _ = #[rustc_dummy] expr_mac!(); let _ = #[rustc_dummy] expr_mac!();
let _ = #[rustc_dummy] expr_mac![]; let _ = #[rustc_dummy] expr_mac![];
let _ = #[rustc_dummy] expr_mac! { }; let _ = #[rustc_dummy] expr_mac! {};
} }
fn _11() { fn _11() {
@ -235,7 +235,7 @@ fn _11() {
|| #[rustc_dummy] return; || #[rustc_dummy] return;
let _ = #[rustc_dummy] expr_mac!(); let _ = #[rustc_dummy] expr_mac!();
let _ = #[rustc_dummy] expr_mac![]; let _ = #[rustc_dummy] expr_mac![];
let _ = #[rustc_dummy] expr_mac! { }; let _ = #[rustc_dummy] expr_mac! {};
let _ = #[rustc_dummy] Foo{data: (),}; let _ = #[rustc_dummy] Foo{data: (),};
let _ = #[rustc_dummy] Foo{..s}; let _ = #[rustc_dummy] Foo{..s};
let _ = #[rustc_dummy] Foo{data: (), ..s}; let _ = #[rustc_dummy] Foo{data: (), ..s};
@ -258,6 +258,6 @@ fn _12() {
} }
} }
fn foo() { } fn foo() {}
fn foo3(_: i32, _: (), _: ()) { } fn foo3(_: i32, _: (), _: ()) {}
fn qux(_: i32) { } fn qux(_: i32) {}

View file

@ -5,4 +5,4 @@ enum foo {
baz, baz,
} }
fn main() { } fn main() {}

View file

@ -4,4 +4,4 @@ trait Foo {
#![allow(bar)] #![allow(bar)]
} }
fn main() { } fn main() {}

View file

@ -4,6 +4,6 @@
struct Test; struct Test;
impl !Send for Test { } impl !Send for Test {}
pub fn main() { } pub fn main() {}

View file

@ -5,11 +5,11 @@ unsafe trait UnsafeTrait {
} }
unsafe impl UnsafeTrait for isize { unsafe impl UnsafeTrait for isize {
fn foo(&self) { } fn foo(&self) {}
} }
pub unsafe trait PubUnsafeTrait { pub unsafe trait PubUnsafeTrait {
fn foo(&self); fn foo(&self);
} }
fn main() { } fn main() {}

View file

@ -2,4 +2,4 @@
fn f<'a, 'b, T>(t: T) -> isize where T: 'a, 'a: 'b, T: Eq { 0 } fn f<'a, 'b, T>(t: T) -> isize where T: 'a, 'a: 'b, T: Eq { 0 }
fn main() { } fn main() {}

View file

@ -1,3 +1,3 @@
async fn f(mut x : u8) { } async fn f(mut x : u8) {}
async fn g((mut x, y, mut z) : (u8, u8, u8)) { } async fn g((mut x, y, mut z) : (u8, u8, u8)) {}
async fn g(mut x : u8, (a, mut b, c) : (u8, u8, u8), y : u8) { } async fn g(mut x : u8, (a, mut b, c) : (u8, u8, u8), y : u8) {}

View file

@ -8,7 +8,7 @@ LL | #![u=||{static d=||1;}]
| ^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^
error: unexpected token: `{ error: unexpected token: `{
impl std::ops::Neg for i8 { } impl std::ops::Neg for i8 {}
}` }`
--> $DIR/issue-90873.rs:7:6 --> $DIR/issue-90873.rs:7:6
| |

View file

@ -11,9 +11,9 @@ use ::std::prelude::rust_2015::*;
#[macro_use] #[macro_use]
extern crate std; extern crate std;
trait Foo<const KIND : bool = true> { } trait Foo<const KIND : bool = true> {}
fn foo<const SIZE : usize = 5>() { } fn foo<const SIZE : usize = 5>() {}
struct Range<const FROM : usize = 0, const LEN : usize = 0, const TO : usize = struct Range<const FROM : usize = 0, const LEN : usize = 0, const TO : usize =
FROM>; FROM>;

View file

@ -15,7 +15,7 @@ fn bar /* 0#0 */() {
y /* 0#1 */ + x /* 0#0 */ y /* 0#1 */ + x /* 0#0 */
} }
fn y /* 0#0 */() { } fn y /* 0#0 */() {}
/* /*
Expansions: Expansions:

View file

@ -11,4 +11,4 @@ extern crate std;
macro_rules! foo { () => { break 'x ; } } macro_rules! foo { () => { break 'x ; } }
pub fn main() { loop { } } pub fn main() { loop {} }

View file

@ -16,7 +16,7 @@ macro complex_nonterminal($nt_item: item) {
struct S; struct S;
} }
n!(a $nt_item b); //~ ERROR no rules expected the token `enum E { }` n!(a $nt_item b); //~ ERROR no rules expected the token `enum E {}`
} }
simple_nonterminal!(a, 'a, (x, y, z)); // OK simple_nonterminal!(a, 'a, (x, y, z)); // OK

View file

@ -1,4 +1,4 @@
error: no rules expected the token `enum E { }` error: no rules expected the token `enum E {}`
--> $DIR/nonterminal-matching.rs:19:10 --> $DIR/nonterminal-matching.rs:19:10
| |
LL | macro n(a $nt_item b) { LL | macro n(a $nt_item b) {

View file

@ -14,7 +14,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/allowed-attr-stmt-expr.rs:49:20: 49:21 (#0), span: $DIR/allowed-attr-stmt-expr.rs:49:20: 49:21 (#0),
}, },
] ]
PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] struct Foo { } PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] struct Foo {}
PRINT-ATTR INPUT (DEBUG): TokenStream [ PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct { Punct {
ch: '#', ch: '#',
@ -140,7 +140,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/allowed-attr-stmt-expr.rs:61:28: 61:29 (#0), span: $DIR/allowed-attr-stmt-expr.rs:61:28: 61:29 (#0),
}, },
] ]
PRINT-ATTR INPUT (DISPLAY): second_make_stmt! (#[allow(dead_code)] struct Bar { }) ; PRINT-ATTR INPUT (DISPLAY): second_make_stmt! (#[allow(dead_code)] struct Bar {}) ;
PRINT-ATTR INPUT (DEBUG): TokenStream [ PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident { Ident {
ident: "second_make_stmt", ident: "second_make_stmt",
@ -201,7 +201,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/allowed-attr-stmt-expr.rs:64:57: 64:58 (#0), span: $DIR/allowed-attr-stmt-expr.rs:64:57: 64:58 (#0),
}, },
] ]
PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] #[allow(dead_code)] struct Bar { } PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] #[allow(dead_code)] struct Bar {}
PRINT-ATTR INPUT (DEBUG): TokenStream [ PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct { Punct {
ch: '#', ch: '#',
@ -257,7 +257,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/allowed-attr-stmt-expr.rs:64:54: 64:56 (#0), span: $DIR/allowed-attr-stmt-expr.rs:64:54: 64:56 (#0),
}, },
] ]
PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] struct Other { } PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] struct Other {}
PRINT-ATTR INPUT (DEBUG): TokenStream [ PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct { Punct {
ch: '#', ch: '#',

View file

@ -1,4 +1,4 @@
PRINT-ATTR INPUT (DISPLAY): fn foo < T : MyTrait < MyStruct < { true } >> > () { } PRINT-ATTR INPUT (DISPLAY): fn foo < T : MyTrait < MyStruct < { true } >> > () {}
PRINT-ATTR INPUT (DEBUG): TokenStream [ PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident { Ident {
ident: "fn", ident: "fn",

View file

@ -1,4 +1,4 @@
PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] struct Foo { } PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] struct Foo {}
PRINT-ATTR INPUT (DEBUG): TokenStream [ PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct { Punct {
ch: '#', ch: '#',
@ -124,7 +124,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/attr-stmt-expr.rs:53:28: 53:29 (#0), span: $DIR/attr-stmt-expr.rs:53:28: 53:29 (#0),
}, },
] ]
PRINT-ATTR INPUT (DISPLAY): second_make_stmt! (#[allow(dead_code)] struct Bar { }) ; PRINT-ATTR INPUT (DISPLAY): second_make_stmt! (#[allow(dead_code)] struct Bar {}) ;
PRINT-ATTR INPUT (DEBUG): TokenStream [ PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident { Ident {
ident: "second_make_stmt", ident: "second_make_stmt",
@ -185,7 +185,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/attr-stmt-expr.rs:56:57: 56:58 (#0), span: $DIR/attr-stmt-expr.rs:56:57: 56:58 (#0),
}, },
] ]
PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] #[allow(dead_code)] struct Bar { } PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] #[allow(dead_code)] struct Bar {}
PRINT-ATTR INPUT (DEBUG): TokenStream [ PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct { Punct {
ch: '#', ch: '#',
@ -241,7 +241,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/attr-stmt-expr.rs:56:54: 56:56 (#0), span: $DIR/attr-stmt-expr.rs:56:54: 56:56 (#0),
}, },
] ]
PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] struct Other { } PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] struct Other {}
PRINT-ATTR INPUT (DEBUG): TokenStream [ PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct { Punct {
ch: '#', ch: '#',

View file

@ -83,7 +83,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/attribute-after-derive.rs:16:24: 19:2 (#0), span: $DIR/attribute-after-derive.rs:16:24: 19:2 (#0),
}, },
] ]
PRINT-DERIVE INPUT (DISPLAY): struct AttributeDerive { } PRINT-DERIVE INPUT (DISPLAY): struct AttributeDerive {}
PRINT-DERIVE INPUT (DEBUG): TokenStream [ PRINT-DERIVE INPUT (DEBUG): TokenStream [
Ident { Ident {
ident: "struct", ident: "struct",
@ -99,7 +99,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
span: $DIR/attribute-after-derive.rs:16:24: 19:2 (#0), span: $DIR/attribute-after-derive.rs:16:24: 19:2 (#0),
}, },
] ]
PRINT-DERIVE INPUT (DISPLAY): #[print_attr] struct DeriveAttribute { } PRINT-DERIVE INPUT (DISPLAY): #[print_attr] struct DeriveAttribute {}
PRINT-DERIVE INPUT (DEBUG): TokenStream [ PRINT-DERIVE INPUT (DEBUG): TokenStream [
Punct { Punct {
ch: '#', ch: '#',

View file

@ -15,7 +15,7 @@ pub fn attr_with_args(args: TokenStream, input: TokenStream) -> TokenStream {
let input = input.to_string(); let input = input.to_string();
assert_eq!(input, "fn foo() { }"); assert_eq!(input, "fn foo() {}");
r#" r#"
fn foo() -> &'static str { "Hello, world!" } fn foo() -> &'static str { "Hello, world!" }

View file

@ -10,6 +10,6 @@ use proc_macro::TokenStream;
#[proc_macro_attribute] #[proc_macro_attribute]
pub fn foo(attr: TokenStream, item: TokenStream) -> TokenStream { pub fn foo(attr: TokenStream, item: TokenStream) -> TokenStream {
drop(attr); drop(attr);
assert_eq!(item.to_string(), "fn foo() { }"); assert_eq!(item.to_string(), "fn foo() {}");
"fn foo(&self);".parse().unwrap() "fn foo(&self);".parse().unwrap()
} }

View file

@ -3,7 +3,7 @@ PRINT-ATTR INPUT (DISPLAY): impl Foo <
{ {
#! [rustc_dummy(cursed_inner)] #! [allow(unused)] struct Inner #! [rustc_dummy(cursed_inner)] #! [allow(unused)] struct Inner
{ field : [u8 ; { #! [rustc_dummy(another_cursed_inner)] 1 }] } 0 { field : [u8 ; { #! [rustc_dummy(another_cursed_inner)] 1 }] } 0
}] > { #! [rustc_dummy(evaluated_attr)] fn bar() { } } }] > { #! [rustc_dummy(evaluated_attr)] fn bar() {} }
PRINT-ATTR INPUT (DEBUG): TokenStream [ PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident { Ident {
ident: "impl", ident: "impl",

View file

@ -1,5 +1,5 @@
Derive First: #[derive(Second)] #[derive(Third, Fourth)] #[derive(Fifth)] pub struct Foo { } Derive First: #[derive(Second)] #[derive(Third, Fourth)] #[derive(Fifth)] pub struct Foo {}
Derive Second: #[derive(Third, Fourth)] #[derive(Fifth)] pub struct Foo { } Derive Second: #[derive(Third, Fourth)] #[derive(Fifth)] pub struct Foo {}
Derive Third: #[derive(Fifth)] pub struct Foo { } Derive Third: #[derive(Fifth)] pub struct Foo {}
Derive Fourth: #[derive(Fifth)] pub struct Foo { } Derive Fourth: #[derive(Fifth)] pub struct Foo {}
Derive Fifth: pub struct Foo { } Derive Fifth: pub struct Foo {}

View file

@ -202,7 +202,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
span: #8 bytes(430..483), span: #8 bytes(430..483),
}, },
] ]
PRINT-DERIVE INPUT (DISPLAY): enum E { V = { let _ = { { } } ; 0 }, } PRINT-DERIVE INPUT (DISPLAY): enum E { V = { let _ = { {} } ; 0 }, }
PRINT-DERIVE INPUT (DEBUG): TokenStream [ PRINT-DERIVE INPUT (DEBUG): TokenStream [
Ident { Ident {
ident: "enum", ident: "enum",

View file

@ -269,7 +269,7 @@ PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
span: $DIR/inner-attrs.rs:20:30: 20:36 (#0), span: $DIR/inner-attrs.rs:20:30: 20:36 (#0),
}, },
] ]
PRINT-ATTR INPUT (DISPLAY): fn foo() { } PRINT-ATTR INPUT (DISPLAY): fn foo() {}
PRINT-ATTR INPUT (DEBUG): TokenStream [ PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident { Ident {
ident: "fn", ident: "fn",
@ -552,7 +552,7 @@ PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
span: $DIR/inner-attrs.rs:27:30: 27:40 (#0), span: $DIR/inner-attrs.rs:27:30: 27:40 (#0),
}, },
] ]
PRINT-ATTR INPUT (DISPLAY): mod inline_mod { } PRINT-ATTR INPUT (DISPLAY): mod inline_mod {}
PRINT-ATTR INPUT (DEBUG): TokenStream [ PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident { Ident {
ident: "mod", ident: "mod",
@ -933,7 +933,7 @@ PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
span: $DIR/inner-attrs.rs:82:42: 82:47 (#0), span: $DIR/inner-attrs.rs:82:42: 82:47 (#0),
}, },
] ]
PRINT-ATTR INPUT (DISPLAY): fn weird_extern() { } PRINT-ATTR INPUT (DISPLAY): fn weird_extern() {}
PRINT-ATTR INPUT (DEBUG): TokenStream [ PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident { Ident {
ident: "fn", ident: "fn",

View file

@ -53,7 +53,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: #4 bytes(432..433), span: #4 bytes(432..433),
}, },
] ]
PRINT-DERIVE INPUT (DISPLAY): struct A { } PRINT-DERIVE INPUT (DISPLAY): struct A {}
PRINT-DERIVE INPUT (DEBUG): TokenStream [ PRINT-DERIVE INPUT (DEBUG): TokenStream [
Ident { Ident {
ident: "struct", ident: "struct",

View file

@ -1,4 +1,4 @@
PRINT-ATTR INPUT (DISPLAY): fn main() { & | _ : u8 | { } ; mul_2! (1 + 1) ; } PRINT-ATTR INPUT (DISPLAY): fn main() { & | _ : u8 | {} ; mul_2! (1 + 1) ; }
PRINT-ATTR INPUT (DEBUG): TokenStream [ PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident { Ident {
ident: "fn", ident: "fn",

View file

@ -8,8 +8,8 @@ struct Foo < #[cfg(FALSE)] A, B >
#[cfg(FALSE)] struct Bar ; #[cfg(not(FALSE))] struct Inner ; #[cfg(FALSE)] struct Bar ; #[cfg(not(FALSE))] struct Inner ;
#[cfg(FALSE)] let a = 25 ; match true #[cfg(FALSE)] let a = 25 ; match true
{ {
#[cfg(FALSE)] true => { }, #[cfg(FALSE)] true => {},
#[cfg_attr(not(FALSE), allow(warnings))] false => { }, _ => { } #[cfg_attr(not(FALSE), allow(warnings))] false => {}, _ => {}
} ; #[print_helper(should_be_removed)] fn removed_fn() } ; #[print_helper(should_be_removed)] fn removed_fn()
{ #! [cfg(FALSE)] } #[print_helper(c)] #[cfg(not(FALSE))] fn { #! [cfg(FALSE)] } #[print_helper(c)] #[cfg(not(FALSE))] fn
kept_fn() { #! [cfg(not(FALSE))] let my_val = true ; } enum TupleEnum kept_fn() { #! [cfg(not(FALSE))] let my_val = true ; } enum TupleEnum
@ -1278,7 +1278,7 @@ PRINT-DERIVE INPUT (DISPLAY): #[print_helper(a)] #[allow(dead_code)] #[print_hel
[u8 ; [u8 ;
{ {
#[cfg(not(FALSE))] struct Inner ; match true #[cfg(not(FALSE))] struct Inner ; match true
{ #[allow(warnings)] false => { }, _ => { } } ; #[print_helper(c)] { #[allow(warnings)] false => {}, _ => {} } ; #[print_helper(c)]
#[cfg(not(FALSE))] fn kept_fn() #[cfg(not(FALSE))] fn kept_fn()
{ #! [cfg(not(FALSE))] let my_val = true ; } enum TupleEnum { #! [cfg(not(FALSE))] let my_val = true ; } enum TupleEnum
{ Foo(#[cfg(not(FALSE))] i32, u8) } struct { Foo(#[cfg(not(FALSE))] i32, u8) } struct

View file

@ -1,4 +1,4 @@
PRINT-ATTR INPUT (DISPLAY): #[doc = r" A doc comment"] struct Foo { } PRINT-ATTR INPUT (DISPLAY): #[doc = r" A doc comment"] struct Foo {}
PRINT-ATTR INPUT (DEBUG): TokenStream [ PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct { Punct {
ch: '#', ch: '#',
@ -40,7 +40,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/issue-81007-item-attrs.rs:22:16: 22:18 (#0), span: $DIR/issue-81007-item-attrs.rs:22:16: 22:18 (#0),
}, },
] ]
PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] #[doc = r" Another comment comment"] struct Bar { } PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] #[doc = r" Another comment comment"] struct Bar {}
PRINT-ATTR INPUT (DEBUG): TokenStream [ PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct { Punct {
ch: '#', ch: '#',

View file

@ -11,7 +11,7 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
span: $DIR/auxiliary/nested-macro-rules.rs:9:30: 9:35 (#6), span: $DIR/auxiliary/nested-macro-rules.rs:9:30: 9:35 (#6),
}, },
] ]
PRINT-ATTR INPUT (DISPLAY): struct FirstAttrStruct { } PRINT-ATTR INPUT (DISPLAY): struct FirstAttrStruct {}
PRINT-ATTR INPUT (DEBUG): TokenStream [ PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident { Ident {
ident: "struct", ident: "struct",
@ -46,7 +46,7 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
span: $DIR/auxiliary/nested-macro-rules.rs:9:30: 9:35 (#15), span: $DIR/auxiliary/nested-macro-rules.rs:9:30: 9:35 (#15),
}, },
] ]
PRINT-ATTR INPUT (DISPLAY): struct SecondAttrStruct { } PRINT-ATTR INPUT (DISPLAY): struct SecondAttrStruct {}
PRINT-ATTR INPUT (DEBUG): TokenStream [ PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident { Ident {
ident: "struct", ident: "struct",

View file

@ -64,7 +64,7 @@ macro inner /* 0#4 */ { () => { print_bang! { struct S; } } }
struct S /* 0#5 */; struct S /* 0#5 */;
// OK, not a duplicate definition of `S` // OK, not a duplicate definition of `S`
fn main /* 0#0 */() { } fn main /* 0#0 */() {}
/* /*
Expansions: Expansions:

View file

@ -1,4 +1,4 @@
PRINT-ATTR INPUT (DISPLAY): fn foo < T > () where T : Copy + { } PRINT-ATTR INPUT (DISPLAY): fn foo < T > () where T : Copy + {}
PRINT-ATTR INPUT (DEBUG): TokenStream [ PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident { Ident {
ident: "fn", ident: "fn",

View file

@ -445,7 +445,7 @@ PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
span: $DIR/weird-braces.rs:20:30: 20:42 (#0), span: $DIR/weird-braces.rs:20:30: 20:42 (#0),
}, },
] ]
PRINT-ATTR INPUT (DISPLAY): impl Bar < { 1 > 0 } > for Foo < { true } > { } PRINT-ATTR INPUT (DISPLAY): impl Bar < { 1 > 0 } > for Foo < { true } > {}
PRINT-ATTR INPUT (DEBUG): TokenStream [ PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident { Ident {
ident: "impl", ident: "impl",

View file

@ -13,7 +13,6 @@ extern crate std;
// [pretty]compile-flags: -Zunpretty=everybody_loops // [pretty]compile-flags: -Zunpretty=everybody_loops
// [pretty]check-pass // [pretty]check-pass
#[repr("C")] #[repr("C")]
struct A { struct A {}
}
fn main() { loop { } } fn main() { loop {} }

View file

@ -7,4 +7,4 @@ extern crate std;
// build-pass (FIXME(62277): could be check-pass?) // build-pass (FIXME(62277): could be check-pass?)
// compile-flags: -Z unpretty=expanded // compile-flags: -Z unpretty=expanded
fn main() { if let 0 = 1 { } } fn main() { if let 0 = 1 {} }

View file

@ -18,14 +18,14 @@ macro_rules! checker {
} }
checker!(attr_extern, r#"extern "C" { fn ffi(#[a1] arg1 : i32, #[a2] ...) ; }"#); checker!(attr_extern, r#"extern "C" { fn ffi(#[a1] arg1 : i32, #[a2] ...) ; }"#);
checker!(attr_extern_cvar, r#"unsafe extern "C" fn cvar(arg1 : i32, #[a1] mut args : ...) { }"#); checker!(attr_extern_cvar, r#"unsafe extern "C" fn cvar(arg1 : i32, #[a1] mut args : ...) {}"#);
checker!(attr_alias, "type Alias = fn(#[a1] u8, #[a2] ...) ;"); checker!(attr_alias, "type Alias = fn(#[a1] u8, #[a2] ...) ;");
checker!(attr_free, "fn free(#[a1] arg1 : u8) { let lam = | #[a2] W(x), #[a3] y | () ; }"); checker!(attr_free, "fn free(#[a1] arg1 : u8) { let lam = | #[a2] W(x), #[a3] y | () ; }");
checker!(attr_inherent_1, "fn inherent1(#[a1] self, #[a2] arg1 : u8) { }"); checker!(attr_inherent_1, "fn inherent1(#[a1] self, #[a2] arg1 : u8) {}");
checker!(attr_inherent_2, "fn inherent2(#[a1] & self, #[a2] arg1 : u8) { }"); checker!(attr_inherent_2, "fn inherent2(#[a1] & self, #[a2] arg1 : u8) {}");
checker!(attr_inherent_3, "fn inherent3 < 'a > (#[a1] & 'a mut self, #[a2] arg1 : u8) { }"); checker!(attr_inherent_3, "fn inherent3 < 'a > (#[a1] & 'a mut self, #[a2] arg1 : u8) {}");
checker!(attr_inherent_4, "fn inherent4 < 'a > (#[a1] self : Box < Self >, #[a2] arg1 : u8) { }"); checker!(attr_inherent_4, "fn inherent4 < 'a > (#[a1] self : Box < Self >, #[a2] arg1 : u8) {}");
checker!(attr_inherent_issue_64682, "fn inherent5(#[a1] #[a2] arg1 : u8, #[a3] arg2 : u8) { }"); checker!(attr_inherent_issue_64682, "fn inherent5(#[a1] #[a2] arg1 : u8, #[a3] arg2 : u8) {}");
checker!(attr_trait_1, "fn trait1(#[a1] self, #[a2] arg1 : u8) ;"); checker!(attr_trait_1, "fn trait1(#[a1] self, #[a2] arg1 : u8) ;");
checker!(attr_trait_2, "fn trait2(#[a1] & self, #[a2] arg1 : u8) ;"); checker!(attr_trait_2, "fn trait2(#[a1] & self, #[a2] arg1 : u8) ;");
checker!(attr_trait_3, "fn trait3 < 'a > (#[a1] & 'a mut self, #[a2] arg1 : u8) ;"); checker!(attr_trait_3, "fn trait3 < 'a > (#[a1] & 'a mut self, #[a2] arg1 : u8) ;");
@ -35,9 +35,9 @@ checker!(attr_trait_issue_64682, "fn trait5(#[a1] #[a2] arg1 : u8, #[a3] arg2 :
checker!(rename_params, r#"impl Foo checker!(rename_params, r#"impl Foo
{ {
fn hello(#[angery(true)] a : i32, #[a2] b : i32, #[what = "how"] c : u32) fn hello(#[angery(true)] a : i32, #[a2] b : i32, #[what = "how"] c : u32)
{ } fn {} fn
hello2(#[a1] #[a2] a : i32, #[what = "how"] b : i32, #[angery(true)] c : hello2(#[a1] #[a2] a : i32, #[what = "how"] b : i32, #[angery(true)] c :
u32) { } fn u32) {} fn
hello_self(#[a1] #[a2] & self, #[a1] #[a2] a : i32, #[what = "how"] b : hello_self(#[a1] #[a2] & self, #[a1] #[a2] a : i32, #[what = "how"] b :
i32, #[angery(true)] c : u32) { } i32, #[angery(true)] c : u32) {}
}"#); }"#);