]> git.lizzy.rs Git - rust.git/commitdiff
Use `span_suggestion` in entry lints
authormcarton <cartonmartin+git@gmail.com>
Sun, 3 Jul 2016 17:24:44 +0000 (19:24 +0200)
committermcarton <cartonmartin+git@gmail.com>
Sun, 3 Jul 2016 21:27:44 +0000 (23:27 +0200)
clippy_lints/src/entry.rs
tests/compile-fail/entry.rs

index bc209fd4846e8b0e98725e60315fba65d7e9bfa2..c7afc2d5cd9eff6afbdc9b8ced8c6f5ebbc1b24c 100644 (file)
@@ -121,21 +121,21 @@ fn visit_expr(&mut self, expr: &'v Expr) {
             SpanlessEq::new(self.cx).eq_expr(self.key, &params[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 `{}`", 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);
                 }
             });
         }}
index 7dc4054ec5bf94404ad9276a990183268576bbd2..ec3b75abb371c3a7db3605ffe2dc0f624337b25e 100755 (executable)
@@ -11,45 +11,51 @@ fn foo() {}
 
 fn insert_if_absent0<K: Eq + Hash, V>(m: &mut HashMap<K, V>, 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 `HashMap`
+    //~| HELP consider
     //~| SUGGESTION m.entry(k).or_insert(v)
 }
 
 fn insert_if_absent1<K: Eq + Hash, V>(m: &mut HashMap<K, V>, 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<K: Eq + Hash, V>(m: &mut HashMap<K, V>, 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<K: Eq + Hash, V>(m: &mut HashMap<K, V>, 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<K: Eq + Hash, V>(m: &mut HashMap<K, V>, 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<K: Eq + Hash, V>(m: &mut HashMap<K, V>, 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<K: Ord, V>(m: &mut BTreeMap<K, V>, 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<K: Eq + Hash, V>(m: &mut HashMap<K, V>, k: K, o: K, v: V) {