Use span_suggestion in entry lints
This commit is contained in:
parent
ffa840d4f2
commit
2f259b8cd3
2 changed files with 24 additions and 18 deletions
|
|
@ -121,21 +121,21 @@ impl<'a, 'tcx, 'v, 'b> Visitor<'v> for InsertVisitor<'a, 'tcx, 'b> {
|
|||
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);
|
||||
}
|
||||
});
|
||||
}}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue