Skip to content

Fix pretty printing unsafe match arms #19215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 16 additions & 21 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,25 @@
pub use self::AnnNode::*;

use abi;
use ast::{FnUnboxedClosureKind, FnMutUnboxedClosureKind};
use ast::{mod, FnUnboxedClosureKind, FnMutUnboxedClosureKind};
use ast::{FnOnceUnboxedClosureKind};
use ast::{MethodImplItem, RegionTyParamBound, TraitTyParamBound};
use ast::{RequiredMethod, ProvidedMethod, TypeImplItem, TypeTraitItem};
use ast::{UnboxedClosureKind};
use ast;
use ast_util;
use owned_slice::OwnedSlice;
use attr::{AttrMetaMethods, AttributeMethods};
use codemap::{CodeMap, BytePos};
use codemap;
use codemap::{mod, CodeMap, BytePos};
use diagnostic;
use parse::token::{BinOpToken, Token};
use parse::token;
use parse::token::{mod, BinOpToken, Token};
use parse::lexer::comments;
use parse;
use print::pp::{break_offset, word, space, zerobreak, hardbreak};
use print::pp::{mod, break_offset, word, space, zerobreak, hardbreak};
use print::pp::{Breaks, Consistent, Inconsistent, eof};
use print::pp;
use ptr::P;

use std::ascii;
use std::io::IoResult;
use std::io;
use std::mem;
use std::{ascii, mem};
use std::io::{mod, IoResult};

pub enum AnnNode<'a> {
NodeIdent(&'a ast::Ident),
Expand Down Expand Up @@ -2164,21 +2158,22 @@ impl<'a> State<'a> {
try!(self.print_pat(&**p));
}
try!(space(&mut self.s));
match arm.guard {
Some(ref e) => {
try!(self.word_space("if"));
try!(self.print_expr(&**e));
try!(space(&mut self.s));
}
None => ()
if let Some(ref e) = arm.guard {
try!(self.word_space("if"));
try!(self.print_expr(&**e));
try!(space(&mut self.s));
}
try!(self.word_space("=>"));

match arm.body.node {
ast::ExprBlock(ref blk) => {
// the block will close the pattern's ibox
try!(self.print_block_unclosed_indent(&**blk,
indent_unit));
try!(self.print_block_unclosed_indent(&**blk, indent_unit));

// If it is a user-provided unsafe block, print a comma after it
if let ast::UnsafeBlock(ast::UserProvided) = blk.rules {
try!(word(&mut self.s, ","));
}
}
_ => {
try!(self.end()); // close the ibox for the pattern
Expand Down
20 changes: 20 additions & 0 deletions src/test/pretty/issue-19077.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// Testing that unsafe blocks in match arms are followed by a comma
// pp-exact
fn main() {
match true {
true if true => (),
false => unsafe { },
true => { }
false => (),
}
}