use std::iter::repeat;
use config::lists::*;
-use syntax::codemap::{BytePos, Span};
+use syntax::source_map::{BytePos, Span};
use syntax::{ast, ptr};
-use codemap::SpanUtils;
use comment::{combine_strs_with_missing_comments, rewrite_comment};
use config::{Config, ControlBraceStyle, IndentStyle};
use expr::{
use lists::{itemize_list, write_list, ListFormatting};
use rewrite::{Rewrite, RewriteContext};
use shape::Shape;
+use source_map::SpanUtils;
use spanned::Spanned;
use utils::{
contains_skip, extra_offset, first_line_width, inner_attributes, last_line_extendable, mk_sp,
fn rewrite_match_pattern(
context: &RewriteContext,
pats: &[&ast::Pat],
- guard: &Option<ptr::P<ast::Expr>>,
+ guard: &Option<ast::Guard>,
shape: Shape,
) -> Option<String> {
// Patterns
guard,
shape,
trimmed_last_line_width(&pats_str),
- pats_str.contains("\n"),
+ pats_str.contains('\n'),
)?;
Some(format!("{}{}", pats_str, guard_str))
match expr.node {
ast::ExprKind::Block(ref block, _)
if !is_unsafe_block(block)
- && is_simple_block(block, Some(&expr.attrs), context.codemap) =>
+ && is_simple_block(block, Some(&expr.attrs), context.source_map) =>
{
Some(&*block)
}
let (is_block, is_empty_block) = if let ast::ExprKind::Block(ref block, _) = body.node {
(
true,
- is_empty_block(block, Some(&body.attrs), context.codemap),
+ is_empty_block(block, Some(&body.attrs), context.source_map),
)
} else {
(false, false)
}
}
+impl Rewrite for ast::Guard {
+ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
+ match self {
+ ast::Guard::If(ref expr) => expr.rewrite(context, shape),
+ }
+ }
+}
+
// The `if ...` guard on a match arm.
fn rewrite_guard(
context: &RewriteContext,
- guard: &Option<ptr::P<ast::Expr>>,
+ guard: &Option<ast::Guard>,
shape: Shape,
// The amount of space used up on this line for the pattern in
// the arm (excludes offset).