Skip to content

Commit 4dbd657

Browse files
author
Jakub Bukaj
committed
rollup merge of #19215: aochagavia/pretty
Closes #19077 I would appreciate any guidance on how to write a test for this. I saw some examples in `test/pretty`, but there are different ways to test... With or without `.pp` files, with a `pp-exact` comment, etc.
2 parents 3594c58 + d678684 commit 4dbd657

File tree

2 files changed

+36
-21
lines changed

2 files changed

+36
-21
lines changed

src/libsyntax/print/pprust.rs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,25 @@
1111
pub use self::AnnNode::*;
1212

1313
use abi;
14-
use ast::{FnUnboxedClosureKind, FnMutUnboxedClosureKind};
14+
use ast::{mod, FnUnboxedClosureKind, FnMutUnboxedClosureKind};
1515
use ast::{FnOnceUnboxedClosureKind};
1616
use ast::{MethodImplItem, RegionTyParamBound, TraitTyParamBound};
1717
use ast::{RequiredMethod, ProvidedMethod, TypeImplItem, TypeTraitItem};
1818
use ast::{UnboxedClosureKind};
19-
use ast;
2019
use ast_util;
2120
use owned_slice::OwnedSlice;
2221
use attr::{AttrMetaMethods, AttributeMethods};
23-
use codemap::{CodeMap, BytePos};
24-
use codemap;
22+
use codemap::{mod, CodeMap, BytePos};
2523
use diagnostic;
26-
use parse::token::{BinOpToken, Token};
27-
use parse::token;
24+
use parse::token::{mod, BinOpToken, Token};
2825
use parse::lexer::comments;
2926
use parse;
30-
use print::pp::{break_offset, word, space, zerobreak, hardbreak};
27+
use print::pp::{mod, break_offset, word, space, zerobreak, hardbreak};
3128
use print::pp::{Breaks, Consistent, Inconsistent, eof};
32-
use print::pp;
3329
use ptr::P;
3430

35-
use std::ascii;
36-
use std::io::IoResult;
37-
use std::io;
38-
use std::mem;
31+
use std::{ascii, mem};
32+
use std::io::{mod, IoResult};
3933

4034
pub enum AnnNode<'a> {
4135
NodeIdent(&'a ast::Ident),
@@ -2150,21 +2144,22 @@ impl<'a> State<'a> {
21502144
try!(self.print_pat(&**p));
21512145
}
21522146
try!(space(&mut self.s));
2153-
match arm.guard {
2154-
Some(ref e) => {
2155-
try!(self.word_space("if"));
2156-
try!(self.print_expr(&**e));
2157-
try!(space(&mut self.s));
2158-
}
2159-
None => ()
2147+
if let Some(ref e) = arm.guard {
2148+
try!(self.word_space("if"));
2149+
try!(self.print_expr(&**e));
2150+
try!(space(&mut self.s));
21602151
}
21612152
try!(self.word_space("=>"));
21622153

21632154
match arm.body.node {
21642155
ast::ExprBlock(ref blk) => {
21652156
// the block will close the pattern's ibox
2166-
try!(self.print_block_unclosed_indent(&**blk,
2167-
indent_unit));
2157+
try!(self.print_block_unclosed_indent(&**blk, indent_unit));
2158+
2159+
// If it is a user-provided unsafe block, print a comma after it
2160+
if let ast::UnsafeBlock(ast::UserProvided) = blk.rules {
2161+
try!(word(&mut self.s, ","));
2162+
}
21682163
}
21692164
_ => {
21702165
try!(self.end()); // close the ibox for the pattern

src/test/pretty/issue-19077.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
//
11+
// Testing that unsafe blocks in match arms are followed by a comma
12+
// pp-exact
13+
fn main() {
14+
match true {
15+
true if true => (),
16+
false => unsafe { },
17+
true => { }
18+
false => (),
19+
}
20+
}

0 commit comments

Comments
 (0)