]> git.lizzy.rs Git - rust.git/commitdiff
Merge pull request #127 from birkenfeld/better-helptext-if-let
authorManish Goregaokar <manishsmail@gmail.com>
Tue, 11 Aug 2015 19:14:51 +0000 (00:44 +0530)
committerManish Goregaokar <manishsmail@gmail.com>
Tue, 11 Aug 2015 19:14:51 +0000 (00:44 +0530)
better help text for "match -> if let" lint

1  2 
src/misc.rs
src/utils.rs

diff --cc src/misc.rs
index 53bf73de35a7d45ac81c0aa3a276d44a0ca51f9e,24f0d8afeb6526abe0bd7e54dac028e4ebdae254..444062a5919fc9f35eb5459e5de42c9b2be199a3
@@@ -41,15 -41,22 +41,22 @@@ impl LintPass for MiscPass 
                      }
                      // In some cases, an exhaustive match is preferred to catch situations when
                      // an enum is extended. So we only consider cases where a `_` wildcard is used
 -                    if arms[1].pats[0].node == PatWild(PatWildSingle) && 
 +                    if arms[1].pats[0].node == PatWild(PatWildSingle) &&
                              arms[0].pats.len() == 1 {
+                         let body_code = snippet(cx, arms[0].body.span, "..");
+                         let suggestion = if let ExprBlock(_) = arms[0].body.node {
+                             body_code.into_owned()
+                         } else {
+                             format!("{{ {} }}", body_code)
+                         };
                          span_help_and_lint(cx, SINGLE_MATCH, expr.span,
                                "You seem to be trying to use match for \
-                               destructuring a single type. Did you mean to \
+                               destructuring a single pattern. Did you mean to \
                                use `if let`?",
-                               &*format!("Try if let {} = {} {{ ... }}",
-                                       snippet(cx, arms[0].pats[0].span, ".."),
-                                       snippet(cx, ex.span, ".."))
+                               &*format!("Try\nif let {} = {} {}",
+                                         snippet(cx, arms[0].pats[0].span, ".."),
+                                         snippet(cx, ex.span, ".."),
+                                         suggestion)
                          );
                      }
                  }
diff --cc src/utils.rs
Simple merge