]> git.lizzy.rs Git - rust.git/blobdiff - src/matches.rs
Merge pull request #3510 from topecongiro/issue3509
[rust.git] / src / matches.rs
index 15ff7dbb8fe72b3352cab8cb953192ee9b4b1b63..c09949cf2e86332245709aa3175d78b41d1b5685 100644 (file)
@@ -1,13 +1,3 @@
-// Copyright 2018 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.
-
 //! Format match expression.
 
 use std::iter::repeat;
@@ -35,8 +25,8 @@
 /// A simple wrapper type against `ast::Arm`. Used inside `write_list()`.
 struct ArmWrapper<'a> {
     pub arm: &'a ast::Arm,
-    /// True if the arm is the last one in match expression. Used to decide on whether we should add
-    /// trailing comma to the match arm when `config.trailing_comma() == Never`.
+    /// `true` if the arm is the last one in match expression. Used to decide on whether we should
+    /// add trailing comma to the match arm when `config.trailing_comma() == Never`.
     pub is_last: bool,
     /// Holds a byte position of `|` at the beginning of the arm pattern, if available.
     pub beginning_vert: Option<BytePos>,
@@ -273,7 +263,7 @@ fn rewrite_match_arm(
         false,
     )?;
 
-    let arrow_span = mk_sp(arm.pats.last().unwrap().span.hi(), arm.body.span.lo());
+    let arrow_span = mk_sp(arm.pats.last().unwrap().span.hi(), arm.body.span().lo());
     rewrite_match_body(
         context,
         &arm.body,
@@ -374,7 +364,8 @@ fn rewrite_match_body(
         shape.indent
     };
 
-    let forbid_same_line = has_guard && pats_str.contains('\n') && !is_empty_block;
+    let forbid_same_line =
+        (has_guard && pats_str.contains('\n') && !is_empty_block) || !body.attrs.is_empty();
 
     // Look for comments between `=>` and the start of the body.
     let arrow_comment = {