Skip to content

Commit 9f15ccb

Browse files
committed
Fix pretty printing unsafe match arms
1 parent acfdb14 commit 9f15ccb

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-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),
@@ -2164,21 +2158,22 @@ impl<'a> State<'a> {
21642158
try!(self.print_pat(&**p));
21652159
}
21662160
try!(space(&mut self.s));
2167-
match arm.guard {
2168-
Some(ref e) => {
2169-
try!(self.word_space("if"));
2170-
try!(self.print_expr(&**e));
2171-
try!(space(&mut self.s));
2172-
}
2173-
None => ()
2161+
if let Some(ref e) = arm.guard {
2162+
try!(self.word_space("if"));
2163+
try!(self.print_expr(&**e));
2164+
try!(space(&mut self.s));
21742165
}
21752166
try!(self.word_space("=>"));
21762167

21772168
match arm.body.node {
21782169
ast::ExprBlock(ref blk) => {
21792170
// the block will close the pattern's ibox
2180-
try!(self.print_block_unclosed_indent(&**blk,
2181-
indent_unit));
2171+
try!(self.print_block_unclosed_indent(&**blk, indent_unit));
2172+
2173+
// If it is a user-provided unsafe block, print a comma after it
2174+
if let ast::UnsafeBlock(ast::UserProvided) = blk.rules {
2175+
try!(word(&mut self.s, ","));
2176+
}
21822177
}
21832178
_ => {
21842179
try!(self.end()); // close the ibox for the pattern

0 commit comments

Comments
 (0)