From: mcarton Date: Sun, 3 Jul 2016 17:24:44 +0000 (+0200) Subject: Use `span_suggestion` in entry lints X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=2f259b8cd345988090c401f551001dfc63ccfd2d;p=rust.git Use `span_suggestion` in entry lints --- diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index bc209fd4846..c7afc2d5cd9 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -121,21 +121,21 @@ fn visit_expr(&mut self, expr: &'v Expr) { SpanlessEq::new(self.cx).eq_expr(self.key, ¶ms[1]) ], { span_lint_and_then(self.cx, MAP_ENTRY, self.span, - &format!("usage of `contains_key` followed by `insert` on `{}`", self.ty), |db| { + &format!("usage of `contains_key` followed by `insert` on a `{}`", self.ty), |db| { if self.sole_expr { let help = format!("{}.entry({}).or_insert({})", snippet(self.cx, self.map.span, "map"), snippet(self.cx, params[1].span, ".."), snippet(self.cx, params[2].span, "..")); - db.span_suggestion(self.span, "Consider using", help); + db.span_suggestion(self.span, "consider using", help); } else { - let help = format!("Consider using `{}.entry({})`", + let help = format!("{}.entry({})", snippet(self.cx, self.map.span, "map"), snippet(self.cx, params[1].span, "..")); - db.span_note(self.span, &help); + db.span_suggestion(self.span, "consider using", help); } }); }} diff --git a/tests/compile-fail/entry.rs b/tests/compile-fail/entry.rs index 7dc4054ec5b..ec3b75abb37 100755 --- a/tests/compile-fail/entry.rs +++ b/tests/compile-fail/entry.rs @@ -11,45 +11,51 @@ fn foo() {} fn insert_if_absent0(m: &mut HashMap, k: K, v: V) { if !m.contains_key(&k) { m.insert(k, v); } - //~^ ERROR usage of `contains_key` followed by `insert` on `HashMap` - //~| HELP Consider + //~^ ERROR usage of `contains_key` followed by `insert` on a `HashMap` + //~| HELP consider //~| SUGGESTION m.entry(k).or_insert(v) } fn insert_if_absent1(m: &mut HashMap, k: K, v: V) { if !m.contains_key(&k) { foo(); m.insert(k, v); } - //~^ ERROR usage of `contains_key` followed by `insert` on `HashMap` - //~| NOTE Consider using `m.entry(k)` + //~^ ERROR usage of `contains_key` followed by `insert` on a `HashMap` + //~| HELP consider + //~| SUGGESTION m.entry(k) } fn insert_if_absent2(m: &mut HashMap, k: K, v: V) { if !m.contains_key(&k) { m.insert(k, v) } else { None }; - //~^ ERROR usage of `contains_key` followed by `insert` on `HashMap` - //~| NOTE Consider using `m.entry(k)` + //~^ ERROR usage of `contains_key` followed by `insert` on a `HashMap` + //~| HELP consider + //~| SUGGESTION m.entry(k) } fn insert_if_present2(m: &mut HashMap, k: K, v: V) { if m.contains_key(&k) { None } else { m.insert(k, v) }; - //~^ ERROR usage of `contains_key` followed by `insert` on `HashMap` - //~| NOTE Consider using `m.entry(k)` + //~^ ERROR usage of `contains_key` followed by `insert` on a `HashMap` + //~| HELP consider + //~| SUGGESTION m.entry(k) } fn insert_if_absent3(m: &mut HashMap, k: K, v: V) { if !m.contains_key(&k) { foo(); m.insert(k, v) } else { None }; - //~^ ERROR usage of `contains_key` followed by `insert` on `HashMap` - //~| NOTE Consider using `m.entry(k)` + //~^ ERROR usage of `contains_key` followed by `insert` on a `HashMap` + //~| HELP consider + //~| SUGGESTION m.entry(k) } fn insert_if_present3(m: &mut HashMap, k: K, v: V) { if m.contains_key(&k) { None } else { foo(); m.insert(k, v) }; - //~^ ERROR usage of `contains_key` followed by `insert` on `HashMap` - //~| NOTE Consider using `m.entry(k)` + //~^ ERROR usage of `contains_key` followed by `insert` on a `HashMap` + //~| HELP consider + //~| SUGGESTION m.entry(k) } fn insert_in_btreemap(m: &mut BTreeMap, k: K, v: V) { if !m.contains_key(&k) { foo(); m.insert(k, v) } else { None }; - //~^ ERROR usage of `contains_key` followed by `insert` on `BTreeMap` - //~| NOTE Consider using `m.entry(k)` + //~^ ERROR usage of `contains_key` followed by `insert` on a `BTreeMap` + //~| HELP consider + //~| SUGGESTION m.entry(k) } fn insert_other_if_absent(m: &mut HashMap, k: K, o: K, v: V) {