Skip to content

Commit 233000d

Browse files
committed
Merge pull request #752 from mcarton/rustup
Rustup to rustc 1.9.0-nightly (eabfc16 2016-03-08)
2 parents d9b5b2a + c95ae89 commit 233000d

File tree

3 files changed

+44
-20
lines changed

3 files changed

+44
-20
lines changed

Diff for: Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.0.48"
3+
version = "0.0.49"
44
authors = [
55
"Manish Goregaokar <[email protected]>",
66
"Andre Bogus <[email protected]>",

Diff for: src/matches.rs

+23-14
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::cmp::Ordering;
88
use syntax::ast::LitKind;
99
use syntax::codemap::Span;
1010
use utils::{COW_PATH, OPTION_PATH, RESULT_PATH};
11-
use utils::{match_type, snippet, span_lint, span_note_and_lint, span_lint_and_then, in_external_macro, expr_block};
11+
use utils::{match_type, snippet, span_note_and_lint, span_lint_and_then, in_external_macro, expr_block};
1212

1313
/// **What it does:** This lint checks for matches with a single arm where an `if let` will usually suffice.
1414
///
@@ -309,18 +309,26 @@ fn check_match_ref_pats(cx: &LateContext, ex: &Expr, arms: &[Arm], source: Match
309309
if has_only_ref_pats(arms) {
310310
if let ExprAddrOf(Mutability::MutImmutable, ref inner) = ex.node {
311311
let template = match_template(cx, expr.span, source, "", inner);
312-
span_lint(cx,
313-
MATCH_REF_PATS,
314-
expr.span,
315-
&format!("you don't need to add `&` to both the expression and the patterns: use `{}`",
316-
template));
312+
span_lint_and_then(cx,
313+
MATCH_REF_PATS,
314+
expr.span,
315+
"you don't need to add `&` to both the expression and the patterns",
316+
|db| {
317+
db.span_suggestion(expr.span,
318+
"try",
319+
template);
320+
});
317321
} else {
318322
let template = match_template(cx, expr.span, source, "*", ex);
319-
span_lint(cx,
320-
MATCH_REF_PATS,
321-
expr.span,
322-
&format!("instead of prefixing all patterns with `&`, you can dereference the expression: `{}`",
323-
template));
323+
span_lint_and_then(cx,
324+
MATCH_REF_PATS,
325+
expr.span,
326+
"you don't need to add `&` to all patterns",
327+
|db| {
328+
db.span_suggestion(expr.span,
329+
"instead of prefixing all patterns with `&`, you can dereference the expression",
330+
template);
331+
});
324332
}
325333
}
326334
}
@@ -435,10 +443,11 @@ fn has_only_ref_pats(arms: &[Arm]) -> bool {
435443
fn match_template(cx: &LateContext, span: Span, source: MatchSource, op: &str, expr: &Expr) -> String {
436444
let expr_snippet = snippet(cx, expr.span, "..");
437445
match source {
438-
MatchSource::Normal => format!("match {}{} {{ ...", op, expr_snippet),
439-
MatchSource::IfLetDesugar { .. } => format!("if let ... = {}{} {{", op, expr_snippet),
440-
MatchSource::WhileLetDesugar => format!("while let ... = {}{} {{", op, expr_snippet),
446+
MatchSource::Normal => format!("match {}{} {{ .. }}", op, expr_snippet),
447+
MatchSource::IfLetDesugar { .. } => format!("if let .. = {}{} {{ .. }}", op, expr_snippet),
448+
MatchSource::WhileLetDesugar => format!("while let .. = {}{} {{ .. }}", op, expr_snippet),
441449
MatchSource::ForLoopDesugar => cx.sess().span_bug(span, "for loop desugared to match with &-patterns!"),
450+
MatchSource::TryDesugar => cx.sess().span_bug(span, "`?` operator desugared to match with &-patterns!")
442451
}
443452
}
444453

Diff for: tests/compile-fail/matches.rs

+20-5
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ fn match_bool() {
137137
fn ref_pats() {
138138
{
139139
let v = &Some(0);
140-
match v { //~ERROR dereference the expression: `match *v { ...`
140+
match v {
141+
//~^ERROR add `&` to all patterns
142+
//~|HELP instead of
143+
//~|SUGGESTION `match *v { .. }`
141144
&Some(v) => println!("{:?}", v),
142145
&None => println!("none"),
143146
}
@@ -147,13 +150,19 @@ fn ref_pats() {
147150
}
148151
}
149152
let tup =& (1, 2);
150-
match tup { //~ERROR dereference the expression: `match *tup { ...`
153+
match tup {
154+
//~^ERROR add `&` to all patterns
155+
//~|HELP instead of
156+
//~|SUGGESTION `match *tup { .. }`
151157
&(v, 1) => println!("{}", v),
152158
_ => println!("none"),
153159
}
154160
// special case: using & both in expr and pats
155161
let w = Some(0);
156-
match &w { //~ERROR use `match w { ...`
162+
match &w {
163+
//~^ERROR add `&` to both
164+
//~|HELP try
165+
//~|SUGGESTION `match w { .. }`
157166
&Some(v) => println!("{:?}", v),
158167
&None => println!("none"),
159168
}
@@ -164,12 +173,18 @@ fn ref_pats() {
164173
}
165174

166175
let a = &Some(0);
167-
if let &None = a { //~ERROR dereference the expression: `if let ... = *a {`
176+
if let &None = a {
177+
//~^ERROR add `&` to all patterns
178+
//~|HELP instead of
179+
//~|SUGGESTION `if let ... = *a { .. }`
168180
println!("none");
169181
}
170182

171183
let b = Some(0);
172-
if let &None = &b { //~ERROR use `if let ... = b {`
184+
if let &None = &b {
185+
//~^ERROR add `&` to both
186+
//~|HELP try
187+
//~|SUGGESTION `if let ... = b { .. }`
173188
println!("none");
174189
}
175190
}

0 commit comments

Comments
 (0)