for file in `fd \.rs$` ; do sed -i s/span_suggestion_with_applicability/span_suggestion/g $file ; done for file in `fd \.rs$` ; do sed -i s/span_suggestion_short_with_applicability/span_suggestion_short/g $file ; done for file in `fd \.rs$` ; do sed -i s/span_suggestions_with_applicability/span_suggestions/g $file ; done
This commit is contained in:
parent
e9e0a7e3bd
commit
3a96d6b603
@ -83,7 +83,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
|
|||||||
let r = &sugg::Sugg::hir(cx, rhs, "..");
|
let r = &sugg::Sugg::hir(cx, rhs, "..");
|
||||||
let long =
|
let long =
|
||||||
format!("{} = {}", snip_a, sugg::make_binop(higher::binop(op.node), a, r));
|
format!("{} = {}", snip_a, sugg::make_binop(higher::binop(op.node), a, r));
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!(
|
&format!(
|
||||||
"Did you mean {} = {} {} {} or {}? Consider replacing it with",
|
"Did you mean {} = {} {} {} or {}? Consider replacing it with",
|
||||||
@ -96,7 +96,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
|
|||||||
format!("{} {}= {}", snip_a, op.node.as_str(), snip_r),
|
format!("{} {}= {}", snip_a, op.node.as_str(), snip_r),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
"or",
|
"or",
|
||||||
long,
|
long,
|
||||||
@ -183,7 +183,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
|
|||||||
if let (Some(snip_a), Some(snip_r)) =
|
if let (Some(snip_a), Some(snip_r)) =
|
||||||
(snippet_opt(cx, assignee.span), snippet_opt(cx, rhs.span))
|
(snippet_opt(cx, assignee.span), snippet_opt(cx, rhs.span))
|
||||||
{
|
{
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
"replace it with",
|
"replace it with",
|
||||||
format!("{} {}= {}", snip_a, op.node.as_str(), snip_r),
|
format!("{} {}= {}", snip_a, op.node.as_str(), snip_r),
|
||||||
|
@ -273,7 +273,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
|
|||||||
"useless lint attribute",
|
"useless lint attribute",
|
||||||
|db| {
|
|db| {
|
||||||
sugg = sugg.replacen("#[", "#![", 1);
|
sugg = sugg.replacen("#[", "#![", 1);
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
line_span,
|
line_span,
|
||||||
"if you just forgot a `!`, use",
|
"if you just forgot a `!`, use",
|
||||||
sugg,
|
sugg,
|
||||||
@ -336,7 +336,7 @@ fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) {
|
|||||||
// https://github.com/rust-lang/rust/pull/56992
|
// https://github.com/rust-lang/rust/pull/56992
|
||||||
CheckLintNameResult::NoLint(None) => (),
|
CheckLintNameResult::NoLint(None) => (),
|
||||||
_ => {
|
_ => {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
lint.span,
|
lint.span,
|
||||||
"lowercase the lint name",
|
"lowercase the lint name",
|
||||||
name_lower,
|
name_lower,
|
||||||
|
@ -142,7 +142,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
|
|||||||
"bit mask could be simplified with a call to `trailing_zeros`",
|
"bit mask could be simplified with a call to `trailing_zeros`",
|
||||||
|db| {
|
|db| {
|
||||||
let sugg = Sugg::hir(cx, left1, "...").maybe_par();
|
let sugg = Sugg::hir(cx, left1, "...").maybe_par();
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
e.span,
|
e.span,
|
||||||
"try",
|
"try",
|
||||||
format!("{}.trailing_zeros() >= {}", sugg, n.count_ones()),
|
format!("{}.trailing_zeros() >= {}", sugg, n.count_ones()),
|
||||||
|
@ -393,7 +393,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
|
|||||||
"this expression can be optimized out by applying boolean operations to the \
|
"this expression can be optimized out by applying boolean operations to the \
|
||||||
outer expression",
|
outer expression",
|
||||||
);
|
);
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
e.span,
|
e.span,
|
||||||
"it would look like the following",
|
"it would look like the following",
|
||||||
suggest(self.cx, suggestion, &h2q.terminals).0,
|
suggest(self.cx, suggestion, &h2q.terminals).0,
|
||||||
@ -423,7 +423,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
|
|||||||
e.span,
|
e.span,
|
||||||
"this boolean expression can be simplified",
|
"this boolean expression can be simplified",
|
||||||
|db| {
|
|db| {
|
||||||
db.span_suggestions_with_applicability(
|
db.span_suggestions(
|
||||||
e.span,
|
e.span,
|
||||||
"try",
|
"try",
|
||||||
suggestions.into_iter(),
|
suggestions.into_iter(),
|
||||||
|
@ -154,7 +154,7 @@ 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| {
|
span_lint_and_then(cx, COLLAPSIBLE_IF, expr.span, "this if statement can be collapsed", |db| {
|
||||||
let lhs = Sugg::ast(cx, check, "..");
|
let lhs = Sugg::ast(cx, check, "..");
|
||||||
let rhs = Sugg::ast(cx, check_inner, "..");
|
let rhs = Sugg::ast(cx, check_inner, "..");
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
"try",
|
"try",
|
||||||
format!(
|
format!(
|
||||||
|
@ -66,7 +66,7 @@ impl StaticConst {
|
|||||||
lifetime.ident.span,
|
lifetime.ident.span,
|
||||||
"Constants have by default a `'static` lifetime",
|
"Constants have by default a `'static` lifetime",
|
||||||
|db| {
|
|db| {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
ty.span,
|
ty.span,
|
||||||
"consider removing `'static`",
|
"consider removing `'static`",
|
||||||
sugg,
|
sugg,
|
||||||
|
@ -207,7 +207,7 @@ fn lint_match_arms(cx: &LateContext<'_, '_>, expr: &Expr) {
|
|||||||
|db| {
|
|db| {
|
||||||
db.span_note(i.body.span, "same as this");
|
db.span_note(i.body.span, "same as this");
|
||||||
|
|
||||||
// Note: this does not use `span_suggestion_with_applicability` on purpose:
|
// Note: this does not use `span_suggestion` on purpose:
|
||||||
// there is no clean way
|
// there is no clean way
|
||||||
// to remove the other arm. Building a span and suggest to replace it to ""
|
// to remove the other arm. Building a span and suggest to replace it to ""
|
||||||
// makes an even more confusing error message. Also in order not to make up a
|
// makes an even more confusing error message. Also in order not to make up a
|
||||||
|
@ -149,7 +149,7 @@ impl<'a, 'tcx, 'b> Visitor<'tcx> for InsertVisitor<'a, 'tcx, 'b> {
|
|||||||
snippet(self.cx, params[1].span, ".."),
|
snippet(self.cx, params[1].span, ".."),
|
||||||
snippet(self.cx, params[2].span, ".."));
|
snippet(self.cx, params[2].span, ".."));
|
||||||
|
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
self.span,
|
self.span,
|
||||||
"consider using",
|
"consider using",
|
||||||
help,
|
help,
|
||||||
@ -161,7 +161,7 @@ impl<'a, 'tcx, 'b> Visitor<'tcx> for InsertVisitor<'a, 'tcx, 'b> {
|
|||||||
snippet(self.cx, self.map.span, "map"),
|
snippet(self.cx, self.map.span, "map"),
|
||||||
snippet(self.cx, params[1].span, ".."));
|
snippet(self.cx, params[1].span, ".."));
|
||||||
|
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
self.span,
|
self.span,
|
||||||
"consider using",
|
"consider using",
|
||||||
help,
|
help,
|
||||||
|
@ -126,7 +126,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
|
|||||||
{
|
{
|
||||||
span_lint_and_then(cx, OP_REF, e.span, "needlessly taken reference of left operand", |db| {
|
span_lint_and_then(cx, OP_REF, e.span, "needlessly taken reference of left operand", |db| {
|
||||||
let lsnip = snippet(cx, l.span, "...").to_string();
|
let lsnip = snippet(cx, l.span, "...").to_string();
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
left.span,
|
left.span,
|
||||||
"use the left value directly",
|
"use the left value directly",
|
||||||
lsnip,
|
lsnip,
|
||||||
@ -144,7 +144,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
|
|||||||
"needlessly taken reference of right operand",
|
"needlessly taken reference of right operand",
|
||||||
|db| {
|
|db| {
|
||||||
let rsnip = snippet(cx, r.span, "...").to_string();
|
let rsnip = snippet(cx, r.span, "...").to_string();
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
right.span,
|
right.span,
|
||||||
"use the right value directly",
|
"use the right value directly",
|
||||||
rsnip,
|
rsnip,
|
||||||
@ -163,7 +163,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
|
|||||||
{
|
{
|
||||||
span_lint_and_then(cx, OP_REF, e.span, "needlessly taken reference of left operand", |db| {
|
span_lint_and_then(cx, OP_REF, e.span, "needlessly taken reference of left operand", |db| {
|
||||||
let lsnip = snippet(cx, l.span, "...").to_string();
|
let lsnip = snippet(cx, l.span, "...").to_string();
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
left.span,
|
left.span,
|
||||||
"use the left value directly",
|
"use the left value directly",
|
||||||
lsnip,
|
lsnip,
|
||||||
@ -181,7 +181,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
|
|||||||
{
|
{
|
||||||
span_lint_and_then(cx, OP_REF, e.span, "taken reference of right operand", |db| {
|
span_lint_and_then(cx, OP_REF, e.span, "taken reference of right operand", |db| {
|
||||||
let rsnip = snippet(cx, r.span, "...").to_string();
|
let rsnip = snippet(cx, r.span, "...").to_string();
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
right.span,
|
right.span,
|
||||||
"use the right value directly",
|
"use the right value directly",
|
||||||
rsnip,
|
rsnip,
|
||||||
|
@ -101,7 +101,7 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr) {
|
|||||||
}
|
}
|
||||||
span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure found", |db| {
|
span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure found", |db| {
|
||||||
if let Some(snippet) = snippet_opt(cx, caller.span) {
|
if let Some(snippet) = snippet_opt(cx, caller.span) {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
"remove closure as shown",
|
"remove closure as shown",
|
||||||
snippet,
|
snippet,
|
||||||
|
@ -83,7 +83,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||||||
};
|
};
|
||||||
|
|
||||||
span_lint_and_then(cx, USELESS_FORMAT, span, "useless use of `format!`", |db| {
|
span_lint_and_then(cx, USELESS_FORMAT, span, "useless use of `format!`", |db| {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
message,
|
message,
|
||||||
sugg,
|
sugg,
|
||||||
@ -99,7 +99,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||||||
if tup.is_empty() {
|
if tup.is_empty() {
|
||||||
let sugg = format!("{}.to_string()", snippet(cx, expr.span, "<expr>").into_owned());
|
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| {
|
span_lint_and_then(cx, USELESS_FORMAT, span, "useless use of `format!`", |db| {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"consider using .to_string()",
|
"consider using .to_string()",
|
||||||
sugg,
|
sugg,
|
||||||
|
@ -71,7 +71,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
|
|||||||
let sugg = snippet_with_macro_callsite(cx, args[0].span, "<expr>").to_string();
|
let sugg = snippet_with_macro_callsite(cx, args[0].span, "<expr>").to_string();
|
||||||
|
|
||||||
span_lint_and_then(cx, IDENTITY_CONVERSION, e.span, "identical conversion", |db| {
|
span_lint_and_then(cx, IDENTITY_CONVERSION, e.span, "identical conversion", |db| {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
e.span,
|
e.span,
|
||||||
"consider removing `.into()`",
|
"consider removing `.into()`",
|
||||||
sugg,
|
sugg,
|
||||||
@ -86,7 +86,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
|
|||||||
if same_tys(cx, a, b) {
|
if same_tys(cx, a, b) {
|
||||||
let sugg = snippet(cx, args[0].span, "<expr>").into_owned();
|
let sugg = snippet(cx, args[0].span, "<expr>").into_owned();
|
||||||
span_lint_and_then(cx, IDENTITY_CONVERSION, e.span, "identical conversion", |db| {
|
span_lint_and_then(cx, IDENTITY_CONVERSION, e.span, "identical conversion", |db| {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
e.span,
|
e.span,
|
||||||
"consider removing `.into_iter()`",
|
"consider removing `.into_iter()`",
|
||||||
sugg,
|
sugg,
|
||||||
@ -108,7 +108,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
|
|||||||
let sugg_msg =
|
let sugg_msg =
|
||||||
format!("consider removing `{}()`", snippet(cx, path.span, "From::from"));
|
format!("consider removing `{}()`", snippet(cx, path.span, "From::from"));
|
||||||
span_lint_and_then(cx, IDENTITY_CONVERSION, e.span, "identical conversion", |db| {
|
span_lint_and_then(cx, IDENTITY_CONVERSION, e.span, "identical conversion", |db| {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
e.span,
|
e.span,
|
||||||
&sugg_msg,
|
&sugg_msg,
|
||||||
sugg,
|
sugg,
|
||||||
|
@ -39,7 +39,7 @@ impl Pass {
|
|||||||
fn lint(cx: &LateContext<'_, '_>, outer_span: syntax_pos::Span, inner_span: syntax_pos::Span, msg: &str) {
|
fn lint(cx: &LateContext<'_, '_>, outer_span: syntax_pos::Span, inner_span: syntax_pos::Span, msg: &str) {
|
||||||
span_lint_and_then(cx, IMPLICIT_RETURN, outer_span, "missing return statement", |db| {
|
span_lint_and_then(cx, IMPLICIT_RETURN, outer_span, "missing return statement", |db| {
|
||||||
if let Some(snippet) = snippet_opt(cx, inner_span) {
|
if let Some(snippet) = snippet_opt(cx, inner_span) {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
outer_span,
|
outer_span,
|
||||||
msg,
|
msg,
|
||||||
format!("return {}", snippet),
|
format!("return {}", snippet),
|
||||||
|
@ -162,7 +162,7 @@ impl IntPlusOne {
|
|||||||
block.span,
|
block.span,
|
||||||
"Unnecessary `>= y + 1` or `x - 1 >=`",
|
"Unnecessary `>= y + 1` or `x - 1 >=`",
|
||||||
|db| {
|
|db| {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
block.span,
|
block.span,
|
||||||
"change `>= y + 1` to `> y` as shown",
|
"change `>= y + 1` to `> y` as shown",
|
||||||
recommendation,
|
recommendation,
|
||||||
|
@ -100,7 +100,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeEnumVariant {
|
|||||||
VariantData::Unit(_) => unreachable!(),
|
VariantData::Unit(_) => unreachable!(),
|
||||||
};
|
};
|
||||||
if let Some(snip) = snippet_opt(cx, span) {
|
if let Some(snip) = snippet_opt(cx, span) {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"consider boxing the large fields to reduce the total size of the \
|
"consider boxing the large fields to reduce the total size of the \
|
||||||
enum",
|
enum",
|
||||||
|
@ -124,7 +124,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
|
|||||||
span,
|
span,
|
||||||
"`if _ { .. } else { .. }` is an expression",
|
"`if _ { .. } else { .. }` is an expression",
|
||||||
|db| {
|
|db| {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"it is more idiomatic to write",
|
"it is more idiomatic to write",
|
||||||
sug,
|
sug,
|
||||||
|
@ -1304,7 +1304,7 @@ fn check_for_loop_reverse_range<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arg: &'tcx
|
|||||||
expr.span,
|
expr.span,
|
||||||
"this range is empty so this for loop will never run",
|
"this range is empty so this for loop will never run",
|
||||||
|db| {
|
|db| {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
arg.span,
|
arg.span,
|
||||||
"consider using the following if you are attempting to iterate over this \
|
"consider using the following if you are attempting to iterate over this \
|
||||||
range in reverse",
|
range in reverse",
|
||||||
@ -2408,7 +2408,7 @@ fn check_needless_collect<'a, 'tcx>(expr: &'tcx Expr, cx: &LateContext<'a, 'tcx>
|
|||||||
if method.ident.name == "len" {
|
if method.ident.name == "len" {
|
||||||
let span = shorten_needless_collect_span(expr);
|
let span = shorten_needless_collect_span(expr);
|
||||||
span_lint_and_then(cx, NEEDLESS_COLLECT, span, NEEDLESS_COLLECT_MSG, |db| {
|
span_lint_and_then(cx, NEEDLESS_COLLECT, span, NEEDLESS_COLLECT_MSG, |db| {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"replace with",
|
"replace with",
|
||||||
".count()".to_string(),
|
".count()".to_string(),
|
||||||
@ -2419,7 +2419,7 @@ fn check_needless_collect<'a, 'tcx>(expr: &'tcx Expr, cx: &LateContext<'a, 'tcx>
|
|||||||
if method.ident.name == "is_empty" {
|
if method.ident.name == "is_empty" {
|
||||||
let span = shorten_needless_collect_span(expr);
|
let span = shorten_needless_collect_span(expr);
|
||||||
span_lint_and_then(cx, NEEDLESS_COLLECT, span, NEEDLESS_COLLECT_MSG, |db| {
|
span_lint_and_then(cx, NEEDLESS_COLLECT, span, NEEDLESS_COLLECT_MSG, |db| {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"replace with",
|
"replace with",
|
||||||
".next().is_none()".to_string(),
|
".next().is_none()".to_string(),
|
||||||
@ -2431,7 +2431,7 @@ fn check_needless_collect<'a, 'tcx>(expr: &'tcx Expr, cx: &LateContext<'a, 'tcx>
|
|||||||
let contains_arg = snippet(cx, args[1].span, "??");
|
let contains_arg = snippet(cx, args[1].span, "??");
|
||||||
let span = shorten_needless_collect_span(expr);
|
let span = shorten_needless_collect_span(expr);
|
||||||
span_lint_and_then(cx, NEEDLESS_COLLECT, span, NEEDLESS_COLLECT_MSG, |db| {
|
span_lint_and_then(cx, NEEDLESS_COLLECT, span, NEEDLESS_COLLECT_MSG, |db| {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"replace with",
|
"replace with",
|
||||||
format!(
|
format!(
|
||||||
|
@ -216,7 +216,7 @@ fn lint_map_unit_fn(cx: &LateContext<'_, '_>, stmt: &hir::Stmt, expr: &hir::Expr
|
|||||||
);
|
);
|
||||||
|
|
||||||
span_lint_and_then(cx, lint, expr.span, &msg, |db| {
|
span_lint_and_then(cx, lint, expr.span, &msg, |db| {
|
||||||
db.span_suggestion_with_applicability(stmt.span, "try this", suggestion, Applicability::Unspecified);
|
db.span_suggestion(stmt.span, "try this", suggestion, Applicability::Unspecified);
|
||||||
});
|
});
|
||||||
} else if let Some((binding, closure_expr)) = unit_closure(cx, fn_arg) {
|
} else if let Some((binding, closure_expr)) = unit_closure(cx, fn_arg) {
|
||||||
let msg = suggestion_msg("closure", map_type);
|
let msg = suggestion_msg("closure", map_type);
|
||||||
@ -230,7 +230,7 @@ fn lint_map_unit_fn(cx: &LateContext<'_, '_>, stmt: &hir::Stmt, expr: &hir::Expr
|
|||||||
snippet(cx, var_arg.span, "_"),
|
snippet(cx, var_arg.span, "_"),
|
||||||
snippet(cx, reduced_expr_span, "_")
|
snippet(cx, reduced_expr_span, "_")
|
||||||
);
|
);
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
stmt.span,
|
stmt.span,
|
||||||
"try this",
|
"try this",
|
||||||
suggestion,
|
suggestion,
|
||||||
@ -243,7 +243,7 @@ fn lint_map_unit_fn(cx: &LateContext<'_, '_>, stmt: &hir::Stmt, expr: &hir::Expr
|
|||||||
snippet(cx, binding.pat.span, "_"),
|
snippet(cx, binding.pat.span, "_"),
|
||||||
snippet(cx, var_arg.span, "_")
|
snippet(cx, var_arg.span, "_")
|
||||||
);
|
);
|
||||||
db.span_suggestion_with_applicability(stmt.span, "try this", suggestion, Applicability::Unspecified);
|
db.span_suggestion(stmt.span, "try this", suggestion, Applicability::Unspecified);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -375,7 +375,7 @@ fn check_match_bool(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Ex
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Some(sugg) = sugg {
|
if let Some(sugg) = sugg {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
"consider using an if/else expression",
|
"consider using an if/else expression",
|
||||||
sugg,
|
sugg,
|
||||||
|
@ -74,7 +74,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemDiscriminant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let derefs: String = iter::repeat('*').take(derefs_needed).collect();
|
let derefs: String = iter::repeat('*').take(derefs_needed).collect();
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
param.span,
|
param.span,
|
||||||
"try dereferencing",
|
"try dereferencing",
|
||||||
format!("{}{}", derefs, snippet(cx, cur_expr.span, "<param>")),
|
format!("{}{}", derefs, snippet(cx, cur_expr.span, "<param>")),
|
||||||
|
@ -1313,13 +1313,13 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Exp
|
|||||||
let refs: String = iter::repeat('&').take(n + 1).collect();
|
let refs: String = iter::repeat('&').take(n + 1).collect();
|
||||||
let derefs: String = iter::repeat('*').take(n).collect();
|
let derefs: String = iter::repeat('*').take(n).collect();
|
||||||
let explicit = format!("{}{}::clone({})", refs, ty, snip);
|
let explicit = format!("{}{}::clone({})", refs, ty, snip);
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
"try dereferencing it",
|
"try dereferencing it",
|
||||||
format!("{}({}{}).clone()", refs, derefs, snip.deref()),
|
format!("{}({}{}).clone()", refs, derefs, snip.deref()),
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
"or try being explicit about what type to clone",
|
"or try being explicit about what type to clone",
|
||||||
explicit,
|
explicit,
|
||||||
@ -1379,7 +1379,7 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Exp
|
|||||||
}
|
}
|
||||||
span_lint_and_then(cx, CLONE_ON_COPY, expr.span, "using `clone` on a `Copy` type", |db| {
|
span_lint_and_then(cx, CLONE_ON_COPY, expr.span, "using `clone` on a `Copy` type", |db| {
|
||||||
if let Some((text, snip)) = snip {
|
if let Some((text, snip)) = snip {
|
||||||
db.span_suggestion_with_applicability(expr.span, text, snip, Applicability::Unspecified);
|
db.span_suggestion(expr.span, text, snip, Applicability::Unspecified);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1810,7 +1810,7 @@ fn lint_map_flatten<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr,
|
|||||||
let func_snippet = snippet(cx, map_args[1].span, "..");
|
let func_snippet = snippet(cx, map_args[1].span, "..");
|
||||||
let hint = format!("{0}.flat_map({1})", self_snippet, func_snippet);
|
let hint = format!("{0}.flat_map({1})", self_snippet, func_snippet);
|
||||||
span_lint_and_then(cx, MAP_FLATTEN, expr.span, msg, |db| {
|
span_lint_and_then(cx, MAP_FLATTEN, expr.span, msg, |db| {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
"try using flat_map instead",
|
"try using flat_map instead",
|
||||||
hint,
|
hint,
|
||||||
@ -1897,7 +1897,7 @@ fn lint_map_or_none<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr,
|
|||||||
let map_or_func_snippet = snippet(cx, map_or_args[2].span, "..");
|
let map_or_func_snippet = snippet(cx, map_or_args[2].span, "..");
|
||||||
let hint = format!("{0}.and_then({1})", map_or_self_snippet, map_or_func_snippet);
|
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| {
|
span_lint_and_then(cx, OPTION_MAP_OR_NONE, expr.span, msg, |db| {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
"try using and_then instead",
|
"try using and_then instead",
|
||||||
hint,
|
hint,
|
||||||
|
@ -302,7 +302,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||||||
l.pat.span,
|
l.pat.span,
|
||||||
"`ref` on an entire `let` pattern is discouraged, take a reference with `&` instead",
|
"`ref` on an entire `let` pattern is discouraged, take a reference with `&` instead",
|
||||||
|db| {
|
|db| {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
s.span,
|
s.span,
|
||||||
"try",
|
"try",
|
||||||
format!(
|
format!(
|
||||||
@ -330,7 +330,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||||||
"boolean short circuit operator in statement may be clearer using an explicit test",
|
"boolean short circuit operator in statement may be clearer using an explicit test",
|
||||||
|db| {
|
|db| {
|
||||||
let sugg = if binop.node == BinOpKind::Or { !sugg } else { sugg };
|
let sugg = if binop.node == BinOpKind::Or { !sugg } else { sugg };
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
s.span,
|
s.span,
|
||||||
"replace it with",
|
"replace it with",
|
||||||
format!(
|
format!(
|
||||||
@ -387,7 +387,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||||||
let lhs = Sugg::hir(cx, left, "..");
|
let lhs = Sugg::hir(cx, left, "..");
|
||||||
let rhs = Sugg::hir(cx, right, "..");
|
let rhs = Sugg::hir(cx, right, "..");
|
||||||
|
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
"consider comparing them within some error",
|
"consider comparing them within some error",
|
||||||
format!("({}).abs() < error", lhs - rhs),
|
format!("({}).abs() < error", lhs - rhs),
|
||||||
@ -568,7 +568,7 @@ fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr, other: &Expr) {
|
|||||||
snip.to_string()
|
snip.to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
lint_span,
|
lint_span,
|
||||||
"try",
|
"try",
|
||||||
try_hint,
|
try_hint,
|
||||||
|
@ -343,7 +343,7 @@ impl EarlyLintPass for MiscEarly {
|
|||||||
|db| {
|
|db| {
|
||||||
if decl.inputs.is_empty() {
|
if decl.inputs.is_empty() {
|
||||||
let hint = snippet(cx, block.span, "..").into_owned();
|
let hint = snippet(cx, block.span, "..").into_owned();
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
"Try doing something like: ",
|
"Try doing something like: ",
|
||||||
hint,
|
hint,
|
||||||
@ -438,13 +438,13 @@ impl MiscEarly {
|
|||||||
lit.span,
|
lit.span,
|
||||||
"this is a decimal constant",
|
"this is a decimal constant",
|
||||||
|db| {
|
|db| {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
lit.span,
|
lit.span,
|
||||||
"if you mean to use a decimal constant, remove the `0` to remove confusion",
|
"if you mean to use a decimal constant, remove the `0` to remove confusion",
|
||||||
src.trim_start_matches(|c| c == '_' || c == '0').to_string(),
|
src.trim_start_matches(|c| c == '_' || c == '0').to_string(),
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
lit.span,
|
lit.span,
|
||||||
"if you mean to use an octal constant, use `0o`",
|
"if you mean to use an octal constant, use `0o`",
|
||||||
format!("0o{}", src.trim_start_matches(|c| c == '_' || c == '0')),
|
format!("0o{}", src.trim_start_matches(|c| c == '_' || c == '0')),
|
||||||
|
@ -70,7 +70,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow {
|
|||||||
by the compiler",
|
by the compiler",
|
||||||
|db| {
|
|db| {
|
||||||
if let Some(snippet) = snippet_opt(cx, inner.span) {
|
if let Some(snippet) = snippet_opt(cx, inner.span) {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
e.span,
|
e.span,
|
||||||
"change this to",
|
"change this to",
|
||||||
snippet,
|
snippet,
|
||||||
@ -103,7 +103,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow {
|
|||||||
"this pattern creates a reference to a reference",
|
"this pattern creates a reference to a reference",
|
||||||
|db| {
|
|db| {
|
||||||
if let Some(snippet) = snippet_opt(cx, name.span) {
|
if let Some(snippet) = snippet_opt(cx, name.span) {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
pat.span,
|
pat.span,
|
||||||
"change this to",
|
"change this to",
|
||||||
snippet,
|
snippet,
|
||||||
|
@ -82,7 +82,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrowedRef {
|
|||||||
"this pattern takes a reference on something that is being de-referenced",
|
"this pattern takes a reference on something that is being de-referenced",
|
||||||
|db| {
|
|db| {
|
||||||
let hint = snippet(cx, spanned_name.span, "..").into_owned();
|
let hint = snippet(cx, spanned_name.span, "..").into_owned();
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
pat.span,
|
pat.span,
|
||||||
"try removing the `&ref` part and just keep",
|
"try removing the `&ref` part and just keep",
|
||||||
hint,
|
hint,
|
||||||
|
@ -237,7 +237,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
|
|||||||
}).unwrap());
|
}).unwrap());
|
||||||
then {
|
then {
|
||||||
let slice_ty = format!("&[{}]", snippet(cx, elem_ty.span, "_"));
|
let slice_ty = format!("&[{}]", snippet(cx, elem_ty.span, "_"));
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
input.span,
|
input.span,
|
||||||
"consider changing the type to",
|
"consider changing the type to",
|
||||||
slice_ty,
|
slice_ty,
|
||||||
@ -245,7 +245,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
|
|||||||
);
|
);
|
||||||
|
|
||||||
for (span, suggestion) in clone_spans {
|
for (span, suggestion) in clone_spans {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
span,
|
span,
|
||||||
&snippet_opt(cx, span)
|
&snippet_opt(cx, span)
|
||||||
.map_or(
|
.map_or(
|
||||||
@ -266,7 +266,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
|
|||||||
if match_type(cx, ty, &paths::STRING) {
|
if match_type(cx, ty, &paths::STRING) {
|
||||||
if let Some(clone_spans) =
|
if let Some(clone_spans) =
|
||||||
get_spans(cx, Some(body.id()), idx, &[("clone", ".to_string()"), ("as_str", "")]) {
|
get_spans(cx, Some(body.id()), idx, &[("clone", ".to_string()"), ("as_str", "")]) {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
input.span,
|
input.span,
|
||||||
"consider changing the type to",
|
"consider changing the type to",
|
||||||
"&str".to_string(),
|
"&str".to_string(),
|
||||||
@ -274,7 +274,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
|
|||||||
);
|
);
|
||||||
|
|
||||||
for (span, suggestion) in clone_spans {
|
for (span, suggestion) in clone_spans {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
span,
|
span,
|
||||||
&snippet_opt(cx, span)
|
&snippet_opt(cx, span)
|
||||||
.map_or(
|
.map_or(
|
||||||
|
@ -122,7 +122,7 @@ fn verify_ty_bound<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: ty::Ty<'tcx>, sourc
|
|||||||
match source {
|
match source {
|
||||||
Source::Item { .. } => {
|
Source::Item { .. } => {
|
||||||
let const_kw_span = span.from_inner_byte_pos(0, 5);
|
let const_kw_span = span.from_inner_byte_pos(0, 5);
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
const_kw_span,
|
const_kw_span,
|
||||||
"make this a static item",
|
"make this a static item",
|
||||||
"static".to_string(),
|
"static".to_string(),
|
||||||
|
@ -182,7 +182,7 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: NodeId, opt_body_id:
|
|||||||
with non-Vec-based slices.",
|
with non-Vec-based slices.",
|
||||||
|db| {
|
|db| {
|
||||||
if let Some(ref snippet) = ty_snippet {
|
if let Some(ref snippet) = ty_snippet {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
arg.span,
|
arg.span,
|
||||||
"change this to",
|
"change this to",
|
||||||
format!("&[{}]", snippet),
|
format!("&[{}]", snippet),
|
||||||
@ -190,7 +190,7 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: NodeId, opt_body_id:
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
for (clonespan, suggestion) in spans {
|
for (clonespan, suggestion) in spans {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
clonespan,
|
clonespan,
|
||||||
&snippet_opt(cx, clonespan).map_or("change the call to".into(), |x| {
|
&snippet_opt(cx, clonespan).map_or("change the call to".into(), |x| {
|
||||||
Cow::Owned(format!("change `{}` to", x))
|
Cow::Owned(format!("change `{}` to", x))
|
||||||
@ -210,14 +210,14 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: NodeId, opt_body_id:
|
|||||||
arg.span,
|
arg.span,
|
||||||
"writing `&String` instead of `&str` involves a new object where a slice will do.",
|
"writing `&String` instead of `&str` involves a new object where a slice will do.",
|
||||||
|db| {
|
|db| {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
arg.span,
|
arg.span,
|
||||||
"change this to",
|
"change this to",
|
||||||
"&str".into(),
|
"&str".into(),
|
||||||
Applicability::Unspecified,
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
for (clonespan, suggestion) in spans {
|
for (clonespan, suggestion) in spans {
|
||||||
db.span_suggestion_short_with_applicability(
|
db.span_suggestion_short(
|
||||||
clonespan,
|
clonespan,
|
||||||
&snippet_opt(cx, clonespan).map_or("change the call to".into(), |x| {
|
&snippet_opt(cx, clonespan).map_or("change the call to".into(), |x| {
|
||||||
Cow::Owned(format!("change `{}` to", x))
|
Cow::Owned(format!("change `{}` to", x))
|
||||||
@ -250,7 +250,7 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: NodeId, opt_body_id:
|
|||||||
arg.span,
|
arg.span,
|
||||||
"using a reference to `Cow` is not recommended.",
|
"using a reference to `Cow` is not recommended.",
|
||||||
|db| {
|
|db| {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
arg.span,
|
arg.span,
|
||||||
"change this to",
|
"change this to",
|
||||||
"&".to_owned() + &r,
|
"&".to_owned() + &r,
|
||||||
|
@ -92,7 +92,7 @@ impl Pass {
|
|||||||
expr.span,
|
expr.span,
|
||||||
"this block may be rewritten with the `?` operator",
|
"this block may be rewritten with the `?` operator",
|
||||||
|db| {
|
|db| {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
"replace_it_with",
|
"replace_it_with",
|
||||||
replacement_str,
|
replacement_str,
|
||||||
|
@ -166,14 +166,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||||||
let end = Sugg::hir(cx, y, "y");
|
let end = Sugg::hir(cx, y, "y");
|
||||||
if let Some(is_wrapped) = &snippet_opt(cx, expr.span) {
|
if let Some(is_wrapped) = &snippet_opt(cx, expr.span) {
|
||||||
if is_wrapped.starts_with('(') && is_wrapped.ends_with(')') {
|
if is_wrapped.starts_with('(') && is_wrapped.ends_with(')') {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
"use",
|
"use",
|
||||||
format!("({}..={})", start, end),
|
format!("({}..={})", start, end),
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
"use",
|
"use",
|
||||||
format!("{}..={}", start, end),
|
format!("{}..={}", start, end),
|
||||||
@ -199,7 +199,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||||||
|db| {
|
|db| {
|
||||||
let start = start.map_or(String::new(), |x| Sugg::hir(cx, x, "x").to_string());
|
let start = start.map_or(String::new(), |x| Sugg::hir(cx, x, "x").to_string());
|
||||||
let end = Sugg::hir(cx, y, "y");
|
let end = Sugg::hir(cx, y, "y");
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
"use",
|
"use",
|
||||||
format!("{}..{}", start, end),
|
format!("{}..{}", start, end),
|
||||||
|
@ -202,7 +202,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantClone {
|
|||||||
);
|
);
|
||||||
|
|
||||||
span_lint_node_and_then(cx, REDUNDANT_CLONE, node, sugg_span, "redundant clone", |db| {
|
span_lint_node_and_then(cx, REDUNDANT_CLONE, node, sugg_span, "redundant clone", |db| {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
sugg_span,
|
sugg_span,
|
||||||
"remove this",
|
"remove this",
|
||||||
String::new(),
|
String::new(),
|
||||||
|
@ -98,7 +98,7 @@ fn find_sugg_for_if_let<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr,
|
|||||||
&format!("redundant pattern matching, consider using `{}`", good_method),
|
&format!("redundant pattern matching, consider using `{}`", good_method),
|
||||||
|db| {
|
|db| {
|
||||||
let span = expr.span.to(op.span);
|
let span = expr.span.to(op.span);
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"try this",
|
"try this",
|
||||||
format!("if {}.{}", snippet(cx, op.span, "_"), good_method),
|
format!("if {}.{}", snippet(cx, op.span, "_"), good_method),
|
||||||
@ -163,7 +163,7 @@ fn find_sugg_for_match<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, o
|
|||||||
&format!("redundant pattern matching, consider using `{}`", good_method),
|
&format!("redundant pattern matching, consider using `{}`", good_method),
|
||||||
|db| {
|
|db| {
|
||||||
let span = expr.span.to(op.span);
|
let span = expr.span.to(op.span);
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"try this",
|
"try this",
|
||||||
format!("{}.{}", snippet(cx, op.span, "_"), good_method),
|
format!("{}.{}", snippet(cx, op.span, "_"), good_method),
|
||||||
|
@ -135,7 +135,7 @@ impl ReturnPass {
|
|||||||
}
|
}
|
||||||
span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded return statement", |db| {
|
span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded return statement", |db| {
|
||||||
if let Some(snippet) = snippet_opt(cx, inner_span) {
|
if let Some(snippet) = snippet_opt(cx, inner_span) {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
ret_span,
|
ret_span,
|
||||||
"remove `return` as shown",
|
"remove `return` as shown",
|
||||||
snippet,
|
snippet,
|
||||||
@ -211,7 +211,7 @@ impl EarlyLintPass for ReturnPass {
|
|||||||
(ty.span, Applicability::MaybeIncorrect)
|
(ty.span, Applicability::MaybeIncorrect)
|
||||||
};
|
};
|
||||||
span_lint_and_then(cx, UNUSED_UNIT, rspan, "unneeded unit return type", |db| {
|
span_lint_and_then(cx, UNUSED_UNIT, rspan, "unneeded unit return type", |db| {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
rspan,
|
rspan,
|
||||||
"remove the `-> ()`",
|
"remove the `-> ()`",
|
||||||
String::new(),
|
String::new(),
|
||||||
@ -231,7 +231,7 @@ impl EarlyLintPass for ReturnPass {
|
|||||||
then {
|
then {
|
||||||
let sp = expr.span;
|
let sp = expr.span;
|
||||||
span_lint_and_then(cx, UNUSED_UNIT, sp, "unneeded unit expression", |db| {
|
span_lint_and_then(cx, UNUSED_UNIT, sp, "unneeded unit expression", |db| {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
sp,
|
sp,
|
||||||
"remove the final `()`",
|
"remove the final `()`",
|
||||||
String::new(),
|
String::new(),
|
||||||
@ -247,7 +247,7 @@ impl EarlyLintPass for ReturnPass {
|
|||||||
ast::ExprKind::Ret(Some(ref expr)) | ast::ExprKind::Break(_, Some(ref expr)) => {
|
ast::ExprKind::Ret(Some(ref expr)) | ast::ExprKind::Break(_, Some(ref expr)) => {
|
||||||
if is_unit_expr(expr) && !in_macro(expr.span) {
|
if is_unit_expr(expr) && !in_macro(expr.span) {
|
||||||
span_lint_and_then(cx, UNUSED_UNIT, expr.span, "unneeded `()`", |db| {
|
span_lint_and_then(cx, UNUSED_UNIT, expr.span, "unneeded `()`", |db| {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
expr.span,
|
expr.span,
|
||||||
"remove the `()`",
|
"remove the `()`",
|
||||||
String::new(),
|
String::new(),
|
||||||
|
@ -179,7 +179,7 @@ impl Pass {
|
|||||||
let len_expr = Sugg::hir(cx, vec_alloc.len_expr, "len");
|
let len_expr = Sugg::hir(cx, vec_alloc.len_expr, "len");
|
||||||
|
|
||||||
span_lint_and_then(cx, lint, slow_fill.span, msg, |db| {
|
span_lint_and_then(cx, lint, slow_fill.span, msg, |db| {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
vec_alloc.allocation_expr.span,
|
vec_alloc.allocation_expr.span,
|
||||||
"consider replace allocation with",
|
"consider replace allocation with",
|
||||||
format!("vec![0; {}]", len_expr),
|
format!("vec![0; {}]", len_expr),
|
||||||
|
@ -142,7 +142,7 @@ fn check_manual_swap(cx: &LateContext<'_, '_>, block: &Block) {
|
|||||||
&format!("this looks like you are swapping{} manually", what),
|
&format!("this looks like you are swapping{} manually", what),
|
||||||
|db| {
|
|db| {
|
||||||
if !sugg.is_empty() {
|
if !sugg.is_empty() {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"try",
|
"try",
|
||||||
sugg,
|
sugg,
|
||||||
@ -191,7 +191,7 @@ fn check_suspicious_swap(cx: &LateContext<'_, '_>, block: &Block) {
|
|||||||
&format!("this looks like you are trying to swap{}", what),
|
&format!("this looks like you are trying to swap{}", what),
|
||||||
|db| {
|
|db| {
|
||||||
if !what.is_empty() {
|
if !what.is_empty() {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"try",
|
"try",
|
||||||
format!(
|
format!(
|
||||||
|
@ -260,7 +260,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
|||||||
arg.as_ty(cx.tcx.mk_ptr(rty_and_mut)).as_ty(to_ty)
|
arg.as_ty(cx.tcx.mk_ptr(rty_and_mut)).as_ty(to_ty)
|
||||||
};
|
};
|
||||||
|
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
e.span,
|
e.span,
|
||||||
"try",
|
"try",
|
||||||
sugg.to_string(),
|
sugg.to_string(),
|
||||||
@ -276,7 +276,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
|||||||
"transmute from an integer to a pointer",
|
"transmute from an integer to a pointer",
|
||||||
|db| {
|
|db| {
|
||||||
if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
|
if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
e.span,
|
e.span,
|
||||||
"try",
|
"try",
|
||||||
arg.as_ty(&to_ty.to_string()).to_string(),
|
arg.as_ty(&to_ty.to_string()).to_string(),
|
||||||
@ -335,7 +335,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
|||||||
arg.as_ty(&format!("{} {}", cast, get_type_snippet(cx, qpath, to_ref_ty)))
|
arg.as_ty(&format!("{} {}", cast, get_type_snippet(cx, qpath, to_ref_ty)))
|
||||||
};
|
};
|
||||||
|
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
e.span,
|
e.span,
|
||||||
"try",
|
"try",
|
||||||
sugg::make_unop(deref, arg).to_string(),
|
sugg::make_unop(deref, arg).to_string(),
|
||||||
@ -356,7 +356,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
|||||||
} else {
|
} else {
|
||||||
arg
|
arg
|
||||||
};
|
};
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
e.span,
|
e.span,
|
||||||
"consider using",
|
"consider using",
|
||||||
format!("std::char::from_u32({}).unwrap()", arg.to_string()),
|
format!("std::char::from_u32({}).unwrap()", arg.to_string()),
|
||||||
@ -383,7 +383,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
|||||||
e.span,
|
e.span,
|
||||||
&format!("transmute from a `{}` to a `{}`", from_ty, to_ty),
|
&format!("transmute from a `{}` to a `{}`", from_ty, to_ty),
|
||||||
|db| {
|
|db| {
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
e.span,
|
e.span,
|
||||||
"consider using",
|
"consider using",
|
||||||
format!(
|
format!(
|
||||||
@ -416,7 +416,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
|||||||
} else {
|
} else {
|
||||||
sugg_paren.addr_deref()
|
sugg_paren.addr_deref()
|
||||||
};
|
};
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
e.span,
|
e.span,
|
||||||
"try",
|
"try",
|
||||||
sugg.to_string(),
|
sugg.to_string(),
|
||||||
@ -436,7 +436,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
|||||||
|db| {
|
|db| {
|
||||||
if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
|
if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
|
||||||
let sugg = arg.as_ty(cx.tcx.mk_ptr(to_ty));
|
let sugg = arg.as_ty(cx.tcx.mk_ptr(to_ty));
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
e.span,
|
e.span,
|
||||||
"try",
|
"try",
|
||||||
sugg.to_string(),
|
sugg.to_string(),
|
||||||
@ -454,7 +454,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
|||||||
|db| {
|
|db| {
|
||||||
let arg = sugg::Sugg::hir(cx, &args[0], "..");
|
let arg = sugg::Sugg::hir(cx, &args[0], "..");
|
||||||
let zero = sugg::Sugg::NonParen(Cow::from("0"));
|
let zero = sugg::Sugg::NonParen(Cow::from("0"));
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
e.span,
|
e.span,
|
||||||
"consider using",
|
"consider using",
|
||||||
sugg::make_binop(ast::BinOpKind::Ne, &arg, &zero).to_string(),
|
sugg::make_binop(ast::BinOpKind::Ne, &arg, &zero).to_string(),
|
||||||
@ -478,7 +478,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
|||||||
} else {
|
} else {
|
||||||
arg
|
arg
|
||||||
};
|
};
|
||||||
db.span_suggestion_with_applicability(
|
db.span_suggestion(
|
||||||
e.span,
|
e.span,
|
||||||
"consider using",
|
"consider using",
|
||||||
format!("{}::from_bits({})", to_ty, arg.to_string()),
|
format!("{}::from_bits({})", to_ty, arg.to_string()),
|
||||||
|
@ -693,7 +693,7 @@ pub fn span_lint_and_sugg<'a, 'tcx: 'a, T: LintContext<'tcx>>(
|
|||||||
applicability: Applicability,
|
applicability: Applicability,
|
||||||
) {
|
) {
|
||||||
span_lint_and_then(cx, lint, sp, msg, |db| {
|
span_lint_and_then(cx, lint, sp, msg, |db| {
|
||||||
db.span_suggestion_with_applicability(sp, help, sugg, applicability);
|
db.span_suggestion(sp, help, sugg, applicability);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -547,7 +547,7 @@ impl<'a, 'b, 'c, T: LintContext<'c>> DiagnosticBuilderExt<'c, T> for rustc_error
|
|||||||
if let Some(indent) = indentation(cx, item) {
|
if let Some(indent) = indentation(cx, item) {
|
||||||
let span = item.with_hi(item.lo());
|
let span = item.with_hi(item.lo());
|
||||||
|
|
||||||
self.span_suggestion_with_applicability(span, msg, format!("{}\n{}", attr, indent), applicability);
|
self.span_suggestion(span, msg, format!("{}\n{}", attr, indent), applicability);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -568,7 +568,7 @@ impl<'a, 'b, 'c, T: LintContext<'c>> DiagnosticBuilderExt<'c, T> for rustc_error
|
|||||||
})
|
})
|
||||||
.collect::<String>();
|
.collect::<String>();
|
||||||
|
|
||||||
self.span_suggestion_with_applicability(span, msg, format!("{}\n{}", new_item, indent), applicability);
|
self.span_suggestion(span, msg, format!("{}\n{}", new_item, indent), applicability);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -586,7 +586,7 @@ impl<'a, 'b, 'c, T: LintContext<'c>> DiagnosticBuilderExt<'c, T> for rustc_error
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.span_suggestion_with_applicability(remove_span, msg, String::new(), applicability);
|
self.span_suggestion(remove_span, msg, String::new(), applicability);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user