cargo dev fmt
This commit is contained in:
parent
870ae36f85
commit
eb7ad1c6cd
@ -124,15 +124,21 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
|
||||
&& !rcpy
|
||||
&& implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right).into()])
|
||||
{
|
||||
span_lint_and_then(cx, OP_REF, e.span, "needlessly taken reference of left operand", |diag| {
|
||||
let lsnip = snippet(cx, l.span, "...").to_string();
|
||||
diag.span_suggestion(
|
||||
left.span,
|
||||
"use the left value directly",
|
||||
lsnip,
|
||||
Applicability::MaybeIncorrect, // FIXME #2597
|
||||
);
|
||||
})
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
OP_REF,
|
||||
e.span,
|
||||
"needlessly taken reference of left operand",
|
||||
|diag| {
|
||||
let lsnip = snippet(cx, l.span, "...").to_string();
|
||||
diag.span_suggestion(
|
||||
left.span,
|
||||
"use the left value directly",
|
||||
lsnip,
|
||||
Applicability::MaybeIncorrect, // FIXME #2597
|
||||
);
|
||||
},
|
||||
)
|
||||
} else if !lcpy
|
||||
&& rcpy
|
||||
&& implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty.into()])
|
||||
@ -161,15 +167,21 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
|
||||
if (requires_ref || lcpy)
|
||||
&& implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right).into()])
|
||||
{
|
||||
span_lint_and_then(cx, OP_REF, e.span, "needlessly taken reference of left operand", |diag| {
|
||||
let lsnip = snippet(cx, l.span, "...").to_string();
|
||||
diag.span_suggestion(
|
||||
left.span,
|
||||
"use the left value directly",
|
||||
lsnip,
|
||||
Applicability::MaybeIncorrect, // FIXME #2597
|
||||
);
|
||||
})
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
OP_REF,
|
||||
e.span,
|
||||
"needlessly taken reference of left operand",
|
||||
|diag| {
|
||||
let lsnip = snippet(cx, l.span, "...").to_string();
|
||||
diag.span_suggestion(
|
||||
left.span,
|
||||
"use the left value directly",
|
||||
lsnip,
|
||||
Applicability::MaybeIncorrect, // FIXME #2597
|
||||
);
|
||||
},
|
||||
)
|
||||
}
|
||||
},
|
||||
// foo == &bar
|
||||
|
@ -53,14 +53,20 @@ fn visit_type(&mut self, ty: &Ty, cx: &EarlyContext<'_>, reason: &str) {
|
||||
if lifetime.ident.name == rustc_span::symbol::kw::StaticLifetime {
|
||||
let snip = snippet(cx, borrow_type.ty.span, "<type>");
|
||||
let sugg = format!("&{}", snip);
|
||||
span_lint_and_then(cx, REDUNDANT_STATIC_LIFETIMES, lifetime.ident.span, reason, |diag| {
|
||||
diag.span_suggestion(
|
||||
ty.span,
|
||||
"consider removing `'static`",
|
||||
sugg,
|
||||
Applicability::MachineApplicable, //snippet
|
||||
);
|
||||
});
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
REDUNDANT_STATIC_LIFETIMES,
|
||||
lifetime.ident.span,
|
||||
reason,
|
||||
|diag| {
|
||||
diag.span_suggestion(
|
||||
ty.span,
|
||||
"consider removing `'static`",
|
||||
sugg,
|
||||
Applicability::MachineApplicable, //snippet
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
|
@ -608,17 +608,23 @@ fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt<'_>) {
|
||||
if higher::is_from_for_desugar(local) {
|
||||
return;
|
||||
}
|
||||
span_lint_and_then(cx, LET_UNIT_VALUE, stmt.span, "this let-binding has unit value", |diag| {
|
||||
if let Some(expr) = &local.init {
|
||||
let snip = snippet_with_macro_callsite(cx, expr.span, "()");
|
||||
diag.span_suggestion(
|
||||
stmt.span,
|
||||
"omit the `let` binding",
|
||||
format!("{};", snip),
|
||||
Applicability::MachineApplicable, // snippet
|
||||
);
|
||||
}
|
||||
});
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
LET_UNIT_VALUE,
|
||||
stmt.span,
|
||||
"this let-binding has unit value",
|
||||
|diag| {
|
||||
if let Some(expr) = &local.init {
|
||||
let snip = snippet_with_macro_callsite(cx, expr.span, "()");
|
||||
diag.span_suggestion(
|
||||
stmt.span,
|
||||
"omit the `let` binding",
|
||||
format!("{};", snip),
|
||||
Applicability::MachineApplicable, // snippet
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user