Skip to content

Commit 2f259b8

Browse files
committed
Use span_suggestion in entry lints
1 parent ffa840d commit 2f259b8

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

clippy_lints/src/entry.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,21 +121,21 @@ impl<'a, 'tcx, 'v, 'b> Visitor<'v> for InsertVisitor<'a, 'tcx, 'b> {
121121
SpanlessEq::new(self.cx).eq_expr(self.key, &params[1])
122122
], {
123123
span_lint_and_then(self.cx, MAP_ENTRY, self.span,
124-
&format!("usage of `contains_key` followed by `insert` on `{}`", self.ty), |db| {
124+
&format!("usage of `contains_key` followed by `insert` on a `{}`", self.ty), |db| {
125125
if self.sole_expr {
126126
let help = format!("{}.entry({}).or_insert({})",
127127
snippet(self.cx, self.map.span, "map"),
128128
snippet(self.cx, params[1].span, ".."),
129129
snippet(self.cx, params[2].span, ".."));
130130

131-
db.span_suggestion(self.span, "Consider using", help);
131+
db.span_suggestion(self.span, "consider using", help);
132132
}
133133
else {
134-
let help = format!("Consider using `{}.entry({})`",
134+
let help = format!("{}.entry({})",
135135
snippet(self.cx, self.map.span, "map"),
136136
snippet(self.cx, params[1].span, ".."));
137137

138-
db.span_note(self.span, &help);
138+
db.span_suggestion(self.span, "consider using", help);
139139
}
140140
});
141141
}}

tests/compile-fail/entry.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,51 @@ fn foo() {}
1111

1212
fn insert_if_absent0<K: Eq + Hash, V>(m: &mut HashMap<K, V>, k: K, v: V) {
1313
if !m.contains_key(&k) { m.insert(k, v); }
14-
//~^ ERROR usage of `contains_key` followed by `insert` on `HashMap`
15-
//~| HELP Consider
14+
//~^ ERROR usage of `contains_key` followed by `insert` on a `HashMap`
15+
//~| HELP consider
1616
//~| SUGGESTION m.entry(k).or_insert(v)
1717
}
1818

1919
fn insert_if_absent1<K: Eq + Hash, V>(m: &mut HashMap<K, V>, k: K, v: V) {
2020
if !m.contains_key(&k) { foo(); m.insert(k, v); }
21-
//~^ ERROR usage of `contains_key` followed by `insert` on `HashMap`
22-
//~| NOTE Consider using `m.entry(k)`
21+
//~^ ERROR usage of `contains_key` followed by `insert` on a `HashMap`
22+
//~| HELP consider
23+
//~| SUGGESTION m.entry(k)
2324
}
2425

2526
fn insert_if_absent2<K: Eq + Hash, V>(m: &mut HashMap<K, V>, k: K, v: V) {
2627
if !m.contains_key(&k) { m.insert(k, v) } else { None };
27-
//~^ ERROR usage of `contains_key` followed by `insert` on `HashMap`
28-
//~| NOTE Consider using `m.entry(k)`
28+
//~^ ERROR usage of `contains_key` followed by `insert` on a `HashMap`
29+
//~| HELP consider
30+
//~| SUGGESTION m.entry(k)
2931
}
3032

3133
fn insert_if_present2<K: Eq + Hash, V>(m: &mut HashMap<K, V>, k: K, v: V) {
3234
if m.contains_key(&k) { None } else { m.insert(k, v) };
33-
//~^ ERROR usage of `contains_key` followed by `insert` on `HashMap`
34-
//~| NOTE Consider using `m.entry(k)`
35+
//~^ ERROR usage of `contains_key` followed by `insert` on a `HashMap`
36+
//~| HELP consider
37+
//~| SUGGESTION m.entry(k)
3538
}
3639

3740
fn insert_if_absent3<K: Eq + Hash, V>(m: &mut HashMap<K, V>, k: K, v: V) {
3841
if !m.contains_key(&k) { foo(); m.insert(k, v) } else { None };
39-
//~^ ERROR usage of `contains_key` followed by `insert` on `HashMap`
40-
//~| NOTE Consider using `m.entry(k)`
42+
//~^ ERROR usage of `contains_key` followed by `insert` on a `HashMap`
43+
//~| HELP consider
44+
//~| SUGGESTION m.entry(k)
4145
}
4246

4347
fn insert_if_present3<K: Eq + Hash, V>(m: &mut HashMap<K, V>, k: K, v: V) {
4448
if m.contains_key(&k) { None } else { foo(); m.insert(k, v) };
45-
//~^ ERROR usage of `contains_key` followed by `insert` on `HashMap`
46-
//~| NOTE Consider using `m.entry(k)`
49+
//~^ ERROR usage of `contains_key` followed by `insert` on a `HashMap`
50+
//~| HELP consider
51+
//~| SUGGESTION m.entry(k)
4752
}
4853

4954
fn insert_in_btreemap<K: Ord, V>(m: &mut BTreeMap<K, V>, k: K, v: V) {
5055
if !m.contains_key(&k) { foo(); m.insert(k, v) } else { None };
51-
//~^ ERROR usage of `contains_key` followed by `insert` on `BTreeMap`
52-
//~| NOTE Consider using `m.entry(k)`
56+
//~^ ERROR usage of `contains_key` followed by `insert` on a `BTreeMap`
57+
//~| HELP consider
58+
//~| SUGGESTION m.entry(k)
5359
}
5460

5561
fn insert_other_if_absent<K: Eq + Hash, V>(m: &mut HashMap<K, V>, k: K, o: K, v: V) {

0 commit comments

Comments
 (0)