]> git.lizzy.rs Git - rust.git/commitdiff
Merge pull request #1550 from topecongiro/issue-1547
authorNick Cameron <nrc@ncameron.org>
Sun, 14 May 2017 20:46:14 +0000 (08:46 +1200)
committerGitHub <noreply@github.com>
Sun, 14 May 2017 20:46:14 +0000 (08:46 +1200)
Prevent rewriting closure block to expr inside macro

src/config.rs
src/patterns.rs
tests/source/configs-trailing_comma-never.rs
tests/target/configs-trailing_comma-never.rs

index 441f86f48cbf982790612d45199421cc3561794b..632170e681248a22d27f0c44a4db2efa2e676826 100644 (file)
@@ -261,8 +261,9 @@ pub fn from_toml(toml: &str) -> Result<Config, String> {
                 match parsed.try_into() {
                     Ok(parsed_config) =>
                         Ok(Config::default().fill_from_parsed_config(parsed_config)),
-                    Err(_) => {
-                        err.push_str("Error: Decoding config file failed. ");
+                    Err(e) => {
+                        err.push_str("Error: Decoding config file failed:\n");
+                        err.push_str(format!("{}\n", e).as_str());
                         err.push_str("Please check your config file.\n");
                         Err(err)
                     }
index a50fee040d66dfdf47f09d0023755c0975898636..8edfc1deea08086e9a59956002d1d14fba6d0cca 100644 (file)
@@ -13,8 +13,9 @@
 use config::{IndentStyle, MultilineStyle};
 use rewrite::{Rewrite, RewriteContext};
 use utils::{wrap_str, format_mutability};
-use lists::{DefinitiveListTactic, format_item_list, itemize_list, ListItem, struct_lit_shape,
-            struct_lit_tactic, shape_for_tactic, struct_lit_formatting, write_list};
+use lists::{DefinitiveListTactic, SeparatorTactic, format_item_list, itemize_list, ListItem,
+            struct_lit_shape, struct_lit_tactic, shape_for_tactic, struct_lit_formatting,
+            write_list};
 use expr::{rewrite_unary_prefix, rewrite_pair};
 use types::{rewrite_path, PathContext};
 use super::Spanned;
@@ -134,6 +135,7 @@ fn rewrite_struct_pat(path: &ast::Path,
                       context: &RewriteContext,
                       shape: Shape)
                       -> Option<String> {
+    // 2 =  ` {`
     let path_shape = try_opt!(shape.sub_width(2));
     let path_str = try_opt!(rewrite_path(context, PathContext::Expr, None, path, path_shape));
 
@@ -165,6 +167,10 @@ fn rewrite_struct_pat(path: &ast::Path,
 
     if elipses {
         if fields_str.contains('\n') {
+            // Add a missing trailing comma.
+            if fmt.trailing_separator == SeparatorTactic::Never {
+                fields_str.push_str(",");
+            }
             fields_str.push_str("\n");
             fields_str.push_str(&nested_shape.indent.to_string(context.config));
             fields_str.push_str("..");
index 5d4dbef385afadae0f07e3aa29b080e7766e5855..0577f2e5affa6d4d4dabeb55ef7a44fbb52aff16 100644 (file)
@@ -4,4 +4,10 @@
 fn main() {
     let Lorem { ipsum, dolor, sit, } = amet;
     let Lorem { ipsum, dolor, sit, amet, consectetur, adipiscing } = elit;
+
+    // #1544
+    if let VrMsg::ClientReply {request_num: reply_req_num, value, ..} = msg {
+        let _ = safe_assert_eq!(reply_req_num, request_num, op);
+        return Ok((request_num, op, value));
+    }
 }
index ca2da9136c7648e4aea49ff3006f5ba461c94b25..949069cede8f1bcc8ef5fb6064c4a5240fb3b108 100644 (file)
@@ -11,4 +11,14 @@ fn main() {
         consectetur,
         adipiscing
     } = elit;
+
+    // #1544
+    if let VrMsg::ClientReply {
+               request_num: reply_req_num,
+               value,
+               ..
+           } = msg {
+        let _ = safe_assert_eq!(reply_req_num, request_num, op);
+        return Ok((request_num, op, value));
+    }
 }