Fix indents
This commit is contained in:
parent
2781cac839
commit
3eccccb367
@ -144,7 +144,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
|
||||
"try",
|
||||
format!("{}.trailing_zeros() >= {}", sugg, n.count_ones()),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -418,12 +418,14 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
|
||||
NONMINIMAL_BOOL,
|
||||
e.span,
|
||||
"this boolean expression can be simplified",
|
||||
|db| { db.span_suggestions_with_applicability(
|
||||
|db| {
|
||||
db.span_suggestions_with_applicability(
|
||||
e.span,
|
||||
"try",
|
||||
suggestions,
|
||||
Applicability::Unspecified,
|
||||
); },
|
||||
);
|
||||
},
|
||||
);
|
||||
};
|
||||
if improvements.is_empty() {
|
||||
|
@ -134,13 +134,16 @@ fn check_collapsible_no_if_let(cx: &EarlyContext<'_>, expr: &ast::Expr, check: &
|
||||
span_lint_and_then(cx, COLLAPSIBLE_IF, expr.span, "this if statement can be collapsed", |db| {
|
||||
let lhs = Sugg::ast(cx, check, "..");
|
||||
let rhs = Sugg::ast(cx, check_inner, "..");
|
||||
db.span_suggestion_with_applicability(expr.span,
|
||||
"try",
|
||||
format!("if {} {}",
|
||||
lhs.and(&rhs),
|
||||
snippet_block(cx, content.span, "..")),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
db.span_suggestion_with_applicability(
|
||||
expr.span,
|
||||
"try",
|
||||
format!(
|
||||
"if {} {}",
|
||||
lhs.and(&rhs),
|
||||
snippet_block(cx, content.span, ".."),
|
||||
),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ impl StaticConst {
|
||||
"consider removing `'static`",
|
||||
sugg,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -141,11 +141,11 @@ impl<'a, 'tcx, 'b> Visitor<'tcx> for InsertVisitor<'a, 'tcx, 'b> {
|
||||
snippet(self.cx, params[2].span, ".."));
|
||||
|
||||
db.span_suggestion_with_applicability(
|
||||
self.span,
|
||||
"consider using",
|
||||
help,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
self.span,
|
||||
"consider using",
|
||||
help,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
}
|
||||
else {
|
||||
let help = format!("{}.entry({})",
|
||||
@ -153,11 +153,11 @@ impl<'a, 'tcx, 'b> Visitor<'tcx> for InsertVisitor<'a, 'tcx, 'b> {
|
||||
snippet(self.cx, params[1].span, ".."));
|
||||
|
||||
db.span_suggestion_with_applicability(
|
||||
self.span,
|
||||
"consider using",
|
||||
help,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
self.span,
|
||||
"consider using",
|
||||
help,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -115,11 +115,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
|
||||
span_lint_and_then(cx, OP_REF, e.span, "needlessly taken reference of left operand", |db| {
|
||||
let lsnip = snippet(cx, l.span, "...").to_string();
|
||||
db.span_suggestion_with_applicability(
|
||||
left.span,
|
||||
"use the left value directly",
|
||||
lsnip,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
left.span,
|
||||
"use the left value directly",
|
||||
lsnip,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
})
|
||||
} else if !lcpy && rcpy && implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty.into()]) {
|
||||
span_lint_and_then(
|
||||
@ -133,7 +133,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
|
||||
right.span,
|
||||
"use the right value directly",
|
||||
rsnip,
|
||||
Applicability::Unspecified,);
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
},
|
||||
)
|
||||
}
|
||||
@ -146,11 +147,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
|
||||
span_lint_and_then(cx, OP_REF, e.span, "needlessly taken reference of left operand", |db| {
|
||||
let lsnip = snippet(cx, l.span, "...").to_string();
|
||||
db.span_suggestion_with_applicability(
|
||||
left.span,
|
||||
"use the left value directly",
|
||||
lsnip,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
left.span,
|
||||
"use the left value directly",
|
||||
lsnip,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
})
|
||||
}
|
||||
},
|
||||
@ -162,11 +163,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
|
||||
span_lint_and_then(cx, OP_REF, e.span, "taken reference of right operand", |db| {
|
||||
let rsnip = snippet(cx, r.span, "...").to_string();
|
||||
db.span_suggestion_with_applicability(
|
||||
right.span,
|
||||
"use the right value directly",
|
||||
rsnip,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
right.span,
|
||||
"use the right value directly",
|
||||
rsnip,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
})
|
||||
}
|
||||
},
|
||||
|
@ -98,11 +98,11 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr) {
|
||||
span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure found", |db| {
|
||||
if let Some(snippet) = snippet_opt(cx, caller.span) {
|
||||
db.span_suggestion_with_applicability(
|
||||
expr.span,
|
||||
"remove closure as shown",
|
||||
snippet,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
expr.span,
|
||||
"remove closure as shown",
|
||||
snippet,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -62,11 +62,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||
let sugg = format!("{}.to_string()", snippet(cx, format_arg, "<arg>").into_owned());
|
||||
span_lint_and_then(cx, USELESS_FORMAT, span, "useless use of `format!`", |db| {
|
||||
db.span_suggestion_with_applicability(
|
||||
expr.span,
|
||||
"consider using .to_string()",
|
||||
sugg,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
expr.span,
|
||||
"consider using .to_string()",
|
||||
sugg,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -77,11 +77,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||
let sugg = format!("{}.to_string()", snippet(cx, expr.span, "<expr>").into_owned());
|
||||
span_lint_and_then(cx, USELESS_FORMAT, span, "useless use of `format!`", |db| {
|
||||
db.span_suggestion_with_applicability(
|
||||
span,
|
||||
"consider using .to_string()",
|
||||
sugg,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
span,
|
||||
"consider using .to_string()",
|
||||
sugg,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
@ -65,11 +65,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
|
||||
let sugg = snippet(cx, args[0].span, "<expr>").into_owned();
|
||||
span_lint_and_then(cx, IDENTITY_CONVERSION, e.span, "identical conversion", |db| {
|
||||
db.span_suggestion_with_applicability(
|
||||
e.span,
|
||||
"consider removing `.into()`",
|
||||
sugg,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
e.span,
|
||||
"consider removing `.into()`",
|
||||
sugg,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -80,11 +80,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
|
||||
let sugg = snippet(cx, args[0].span, "<expr>").into_owned();
|
||||
span_lint_and_then(cx, IDENTITY_CONVERSION, e.span, "identical conversion", |db| {
|
||||
db.span_suggestion_with_applicability(
|
||||
e.span,
|
||||
"consider removing `.into_iter()`",
|
||||
sugg,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
e.span,
|
||||
"consider removing `.into_iter()`",
|
||||
sugg,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -100,11 +100,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
|
||||
let sugg_msg = format!("consider removing `{}()`", snippet(cx, path.span, "From::from"));
|
||||
span_lint_and_then(cx, IDENTITY_CONVERSION, e.span, "identical conversion", |db| {
|
||||
db.span_suggestion_with_applicability(
|
||||
e.span,
|
||||
&sugg_msg,
|
||||
sugg,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
e.span,
|
||||
&sugg_msg,
|
||||
sugg,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -154,11 +154,11 @@ impl IntPlusOne {
|
||||
fn emit_warning(&self, cx: &EarlyContext<'_>, block: &Expr, recommendation: String) {
|
||||
span_lint_and_then(cx, INT_PLUS_ONE, block.span, "Unnecessary `>= y + 1` or `x - 1 >=`", |db| {
|
||||
db.span_suggestion_with_applicability(
|
||||
block.span,
|
||||
"change `>= y + 1` to `> y` as shown",
|
||||
recommendation,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
block.span,
|
||||
"change `>= y + 1` to `> y` as shown",
|
||||
recommendation,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -122,11 +122,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
|
||||
"`if _ { .. } else { .. }` is an expression",
|
||||
|db| {
|
||||
db.span_suggestion_with_applicability(
|
||||
span,
|
||||
"it is more idiomatic to write",
|
||||
sug,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
span,
|
||||
"it is more idiomatic to write",
|
||||
sug,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
if !mutability.is_empty() {
|
||||
db.note("you might not need `mut` at all");
|
||||
}
|
||||
|
@ -229,20 +229,22 @@ fn lint_map_unit_fn(cx: &LateContext<'_, '_>, stmt: &hir::Stmt, expr: &hir::Expr
|
||||
snippet(cx, var_arg.span, "_"),
|
||||
snippet(cx, reduced_expr_span, "_"));
|
||||
db.span_suggestion_with_applicability(
|
||||
stmt.span,
|
||||
"try this",
|
||||
suggestion,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
stmt.span,
|
||||
"try this",
|
||||
suggestion,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
} else {
|
||||
let suggestion = format!("if let {0}({1}) = {2} {{ ... }}",
|
||||
variant,
|
||||
snippet(cx, binding.pat.span, "_"),
|
||||
snippet(cx, var_arg.span, "_"));
|
||||
db.span_suggestion_with_applicability(stmt.span,
|
||||
"try this",
|
||||
suggestion,
|
||||
Applicability::Unspecified);
|
||||
db.span_suggestion_with_applicability(
|
||||
stmt.span,
|
||||
"try this",
|
||||
suggestion,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -341,11 +341,11 @@ fn check_match_bool(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Ex
|
||||
|
||||
if let Some(sugg) = sugg {
|
||||
db.span_suggestion_with_applicability(
|
||||
expr.span,
|
||||
"consider using an if/else expression",
|
||||
sugg,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
expr.span,
|
||||
"consider using an if/else expression",
|
||||
sugg,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1129,17 +1129,17 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Exp
|
||||
let derefs: String = iter::repeat('*').take(n).collect();
|
||||
let explicit = format!("{}{}::clone({})", refs, ty, snip);
|
||||
db.span_suggestion_with_applicability(
|
||||
expr.span,
|
||||
"try dereferencing it",
|
||||
format!("{}({}{}).clone()", refs, derefs, snip.deref()),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
expr.span,
|
||||
"try dereferencing it",
|
||||
format!("{}({}{}).clone()", refs, derefs, snip.deref()),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
db.span_suggestion_with_applicability(
|
||||
expr.span,
|
||||
"or try being explicit about what type to clone",
|
||||
explicit,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
expr.span,
|
||||
"or try being explicit about what type to clone",
|
||||
explicit,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
},
|
||||
);
|
||||
return; // don't report clone_on_copy
|
||||
@ -1185,7 +1185,7 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Exp
|
||||
text,
|
||||
snip,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -1656,11 +1656,11 @@ fn lint_map_or_none<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr,
|
||||
let hint = format!("{0}.and_then({1})", map_or_self_snippet, map_or_func_snippet);
|
||||
span_lint_and_then(cx, OPTION_MAP_OR_NONE, expr.span, msg, |db| {
|
||||
db.span_suggestion_with_applicability(
|
||||
expr.span,
|
||||
"try using and_then instead",
|
||||
hint,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
expr.span,
|
||||
"try using and_then instead",
|
||||
hint,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -295,14 +295,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||
l.pat.span,
|
||||
"`ref` on an entire `let` pattern is discouraged, take a reference with `&` instead",
|
||||
|db| {
|
||||
db.span_suggestion_with_applicability(s.span,
|
||||
"try",
|
||||
format!("let {name}{tyopt} = {initref};",
|
||||
name=snippet(cx, i.span, "_"),
|
||||
tyopt=tyopt,
|
||||
initref=initref),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
db.span_suggestion_with_applicability(
|
||||
s.span,
|
||||
"try",
|
||||
format!(
|
||||
"let {name}{tyopt} = {initref};",
|
||||
name=snippet(cx, i.span, "_"),
|
||||
tyopt=tyopt,
|
||||
initref=initref,
|
||||
),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -321,13 +324,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||
|db| {
|
||||
let sugg = if binop.node == BinOpKind::Or { !sugg } else { sugg };
|
||||
db.span_suggestion_with_applicability(
|
||||
s.span,
|
||||
"replace it with",
|
||||
format!("if {} {{ {}; }}",
|
||||
sugg,
|
||||
&snippet(cx, b.span, "..")),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
s.span,
|
||||
"replace it with",
|
||||
format!(
|
||||
"if {} {{ {}; }}",
|
||||
sugg,
|
||||
&snippet(cx, b.span, ".."),
|
||||
),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -545,11 +550,11 @@ fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr, other: &Expr) {
|
||||
}
|
||||
}
|
||||
db.span_suggestion_with_applicability(
|
||||
expr.span,
|
||||
"try",
|
||||
snip.to_string(),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
expr.span,
|
||||
"try",
|
||||
snip.to_string(),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -309,11 +309,11 @@ impl EarlyLintPass for MiscEarly {
|
||||
|db| if decl.inputs.is_empty() {
|
||||
let hint = snippet(cx, block.span, "..").into_owned();
|
||||
db.span_suggestion_with_applicability(
|
||||
expr.span,
|
||||
"Try doing something like: ",
|
||||
hint,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
expr.span,
|
||||
"Try doing something like: ",
|
||||
hint,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -77,11 +77,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow {
|
||||
|db| {
|
||||
if let Some(snippet) = snippet_opt(cx, inner.span) {
|
||||
db.span_suggestion_with_applicability(
|
||||
e.span,
|
||||
"change this to",
|
||||
snippet,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
e.span,
|
||||
"change this to",
|
||||
snippet,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
@ -110,11 +110,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow {
|
||||
|db| {
|
||||
if let Some(snippet) = snippet_opt(cx, name.span) {
|
||||
db.span_suggestion_with_applicability(
|
||||
pat.span,
|
||||
"change this to",
|
||||
snippet,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
pat.span,
|
||||
"change this to",
|
||||
snippet,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
}
|
||||
}
|
||||
)
|
||||
|
@ -79,11 +79,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrowedRef {
|
||||
|db| {
|
||||
let hint = snippet(cx, spanned_name.span, "..").into_owned();
|
||||
db.span_suggestion_with_applicability(
|
||||
pat.span,
|
||||
"try removing the `&ref` part and just keep",
|
||||
hint,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
pat.span,
|
||||
"try removing the `&ref` part and just keep",
|
||||
hint,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -229,11 +229,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
|
||||
then {
|
||||
let slice_ty = format!("&[{}]", snippet(cx, elem_ty.span, "_"));
|
||||
db.span_suggestion_with_applicability(
|
||||
input.span,
|
||||
"consider changing the type to",
|
||||
slice_ty,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
input.span,
|
||||
"consider changing the type to",
|
||||
slice_ty,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
|
||||
for (span, suggestion) in clone_spans {
|
||||
db.span_suggestion_with_applicability(
|
||||
@ -258,11 +258,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
|
||||
if let Some(clone_spans) =
|
||||
get_spans(cx, Some(body.id()), idx, &[("clone", ".to_string()"), ("as_str", "")]) {
|
||||
db.span_suggestion_with_applicability(
|
||||
input.span,
|
||||
"consider changing the type to",
|
||||
"&str".to_string(),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
input.span,
|
||||
"consider changing the type to",
|
||||
"&str".to_string(),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
|
||||
for (span, suggestion) in clone_spans {
|
||||
db.span_suggestion_with_applicability(
|
||||
|
@ -131,12 +131,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
|
||||
&format!("you should consider deriving a `Default` implementation for `{}`", self_ty),
|
||||
|db| {
|
||||
db.suggest_item_with_attr(
|
||||
cx,
|
||||
sp,
|
||||
"try this",
|
||||
"#[derive(Default)]",
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
cx,
|
||||
sp,
|
||||
"try this",
|
||||
"#[derive(Default)]",
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
});
|
||||
} else {
|
||||
span_lint_and_then(
|
||||
|
@ -212,11 +212,11 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: NodeId, opt_body_id:
|
||||
"writing `&String` instead of `&str` involves a new object where a slice will do.",
|
||||
|db| {
|
||||
db.span_suggestion_with_applicability(
|
||||
arg.span,
|
||||
"change this to",
|
||||
"&str".into(),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
arg.span,
|
||||
"change this to",
|
||||
"&str".into(),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
for (clonespan, suggestion) in spans {
|
||||
db.span_suggestion_short_with_applicability(
|
||||
clonespan,
|
||||
@ -253,11 +253,11 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: NodeId, opt_body_id:
|
||||
"using a reference to `Cow` is not recommended.",
|
||||
|db| {
|
||||
db.span_suggestion_with_applicability(
|
||||
arg.span,
|
||||
"change this to",
|
||||
"&".to_owned() + &r,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
arg.span,
|
||||
"change this to",
|
||||
"&".to_owned() + &r,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -151,17 +151,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||
let end = Sugg::hir(cx, y, "y");
|
||||
if let Some(is_wrapped) = &snippet_opt(cx, expr.span) {
|
||||
if is_wrapped.starts_with('(') && is_wrapped.ends_with(')') {
|
||||
db.span_suggestion_with_applicability(expr.span,
|
||||
"use",
|
||||
format!("({}..={})", start, end),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
db.span_suggestion_with_applicability(
|
||||
expr.span,
|
||||
"use",
|
||||
format!("({}..={})", start, end),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
} else {
|
||||
db.span_suggestion_with_applicability(expr.span,
|
||||
"use",
|
||||
format!("{}..={}", start, end),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
db.span_suggestion_with_applicability(
|
||||
expr.span,
|
||||
"use",
|
||||
format!("{}..={}", start, end),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -182,11 +184,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||
|db| {
|
||||
let start = start.map_or(String::new(), |x| Sugg::hir(cx, x, "x").to_string());
|
||||
let end = Sugg::hir(cx, y, "y");
|
||||
db.span_suggestion_with_applicability(expr.span,
|
||||
"use",
|
||||
format!("{}..{}", start, end),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
db.span_suggestion_with_applicability(
|
||||
expr.span,
|
||||
"use",
|
||||
format!("{}..{}", start, end),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -110,11 +110,11 @@ impl ReturnPass {
|
||||
span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded return statement", |db| {
|
||||
if let Some(snippet) = snippet_opt(cx, inner_span) {
|
||||
db.span_suggestion_with_applicability(
|
||||
ret_span,
|
||||
"remove `return` as shown",
|
||||
snippet,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
ret_span,
|
||||
"remove `return` as shown",
|
||||
snippet,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -138,11 +138,11 @@ fn check_manual_swap(cx: &LateContext<'_, '_>, block: &Block) {
|
||||
|db| {
|
||||
if !sugg.is_empty() {
|
||||
db.span_suggestion_with_applicability(
|
||||
span,
|
||||
"try",
|
||||
sugg,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
span,
|
||||
"try",
|
||||
sugg,
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
|
||||
if replace {
|
||||
db.note("or maybe you should use `std::mem::replace`?");
|
||||
@ -187,13 +187,15 @@ fn check_suspicious_swap(cx: &LateContext<'_, '_>, block: &Block) {
|
||||
|db| {
|
||||
if !what.is_empty() {
|
||||
db.span_suggestion_with_applicability(
|
||||
span,
|
||||
"try",
|
||||
format!("std::mem::swap({}, {})",
|
||||
lhs,
|
||||
rhs),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
span,
|
||||
"try",
|
||||
format!(
|
||||
"std::mem::swap({}, {})",
|
||||
lhs,
|
||||
rhs,
|
||||
),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
db.note("or maybe you should use `std::mem::replace`?");
|
||||
}
|
||||
});
|
||||
|
@ -247,11 +247,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
||||
};
|
||||
|
||||
db.span_suggestion_with_applicability(
|
||||
e.span,
|
||||
"try",
|
||||
sugg.to_string(),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
e.span,
|
||||
"try",
|
||||
sugg.to_string(),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
},
|
||||
),
|
||||
(&ty::Int(_), &ty::RawPtr(_)) | (&ty::Uint(_), &ty::RawPtr(_)) => {
|
||||
@ -262,11 +262,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
||||
"transmute from an integer to a pointer",
|
||||
|db| if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
|
||||
db.span_suggestion_with_applicability(
|
||||
e.span,
|
||||
"try",
|
||||
arg.as_ty(&to_ty.to_string()).to_string(),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
e.span,
|
||||
"try",
|
||||
arg.as_ty(&to_ty.to_string()).to_string(),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
},
|
||||
)
|
||||
},
|
||||
@ -324,11 +324,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
||||
};
|
||||
|
||||
db.span_suggestion_with_applicability(
|
||||
e.span,
|
||||
"try",
|
||||
sugg::make_unop(deref, arg).to_string(),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
e.span,
|
||||
"try",
|
||||
sugg::make_unop(deref, arg).to_string(),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
},
|
||||
),
|
||||
(&ty::Int(ast::IntTy::I32), &ty::Char) |
|
||||
@ -399,11 +399,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
||||
sugg_paren.addr_deref()
|
||||
};
|
||||
db.span_suggestion_with_applicability(
|
||||
e.span,
|
||||
"try",
|
||||
sugg.to_string(),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
e.span,
|
||||
"try",
|
||||
sugg.to_string(),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
},
|
||||
)
|
||||
}
|
||||
@ -418,11 +418,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
||||
|db| if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
|
||||
let sugg = arg.as_ty(cx.tcx.mk_ptr(to_ty));
|
||||
db.span_suggestion_with_applicability(
|
||||
e.span,
|
||||
"try",
|
||||
sugg.to_string(),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
e.span,
|
||||
"try",
|
||||
sugg.to_string(),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
},
|
||||
),
|
||||
(&ty::Int(ast::IntTy::I8), &ty::Bool) | (&ty::Uint(ast::UintTy::U8), &ty::Bool) => {
|
||||
|
@ -546,10 +546,10 @@ impl<'a, 'b, 'c, T: LintContext<'c>> DiagnosticBuilderExt<'c, T> for rustc_error
|
||||
}
|
||||
|
||||
self.span_suggestion_with_applicability(
|
||||
remove_span,
|
||||
msg,
|
||||
String::new(),
|
||||
applicability,
|
||||
);
|
||||
remove_span,
|
||||
msg,
|
||||
String::new(),
|
||||
applicability,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user