]> git.lizzy.rs Git - rust.git/blobdiff - src/matches.rs
Merge pull request #3011 from topecongiro/rustc-ap-syntax
[rust.git] / src / matches.rs
index 0ee63fb0c5ad5797c4b7f26585b9c92fbb9f050b..9fac170b96c9ef9a653390fa5c1546edee230eea 100644 (file)
@@ -16,7 +16,6 @@
 use syntax::source_map::{BytePos, Span};
 use syntax::{ast, ptr};
 
-use source_map::SpanUtils;
 use comment::{combine_strs_with_missing_comments, rewrite_comment};
 use config::{Config, ControlBraceStyle, IndentStyle};
 use expr::{
@@ -26,6 +25,7 @@
 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,
@@ -275,7 +275,7 @@ fn rewrite_match_arm(
 fn rewrite_match_pattern(
     context: &RewriteContext,
     pats: &[&ast::Pat],
-    guard: &Option<ptr::P<ast::Expr>>,
+    guard: &Option<ast::Guard>,
     shape: Shape,
 ) -> Option<String> {
     // Patterns
@@ -289,7 +289,7 @@ fn rewrite_match_pattern(
         guard,
         shape,
         trimmed_last_line_width(&pats_str),
-        pats_str.contains("\n"),
+        pats_str.contains('\n'),
     )?;
 
     Some(format!("{}{}", pats_str, guard_str))
@@ -484,10 +484,18 @@ fn rewrite_match_body(
     }
 }
 
+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).