Skip to content

Commit

Permalink
Cleanup: Rename 'db' variable to 'diag'
Browse files Browse the repository at this point in the history
  • Loading branch information
phansch committed Apr 17, 2020
1 parent 8ae143f commit 870ae36
Show file tree
Hide file tree
Showing 54 changed files with 302 additions and 299 deletions.
10 changes: 5 additions & 5 deletions clippy_lints/src/assign_ops.rs
Expand Up @@ -131,11 +131,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
ASSIGN_OP_PATTERN,
expr.span,
"manual implementation of an assign operation",
|db| {
|diag| {
if let (Some(snip_a), Some(snip_r)) =
(snippet_opt(cx, assignee.span), snippet_opt(cx, rhs.span))
{
db.span_suggestion(
diag.span_suggestion(
expr.span,
"replace it with",
format!("{} {}= {}", snip_a, op.node.as_str(), snip_r),
Expand Down Expand Up @@ -199,12 +199,12 @@ fn lint_misrefactored_assign_op(
MISREFACTORED_ASSIGN_OP,
expr.span,
"variable appears on both sides of an assignment operation",
|db| {
|diag| {
if let (Some(snip_a), Some(snip_r)) = (snippet_opt(cx, assignee.span), snippet_opt(cx, rhs_other.span)) {
let a = &sugg::Sugg::hir(cx, assignee, "..");
let r = &sugg::Sugg::hir(cx, rhs, "..");
let long = format!("{} = {}", snip_a, sugg::make_binop(higher::binop(op.node), a, r));
db.span_suggestion(
diag.span_suggestion(
expr.span,
&format!(
"Did you mean `{} = {} {} {}` or `{}`? Consider replacing it with",
Expand All @@ -217,7 +217,7 @@ fn lint_misrefactored_assign_op(
format!("{} {}= {}", snip_a, op.node.as_str(), snip_r),
Applicability::MaybeIncorrect,
);
db.span_suggestion(
diag.span_suggestion(
expr.span,
"or",
long,
Expand Down
10 changes: 5 additions & 5 deletions clippy_lints/src/attrs.rs
Expand Up @@ -273,9 +273,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
USELESS_ATTRIBUTE,
line_span,
"useless lint attribute",
|db| {
|diag| {
sugg = sugg.replacen("#[", "#![", 1);
db.span_suggestion(
diag.span_suggestion(
line_span,
"if you just forgot a `!`, use",
sugg,
Expand Down Expand Up @@ -329,7 +329,7 @@ fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) {
UNKNOWN_CLIPPY_LINTS,
lint.span(),
&format!("unknown clippy lint: clippy::{}", name),
|db| {
|diag| {
let name_lower = name.as_str().to_lowercase();
let symbols = lint_store.get_lints().iter().map(
|l| Symbol::intern(&l.name_lower())
Expand All @@ -341,14 +341,14 @@ fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) {
);
if name.as_str().chars().any(char::is_uppercase)
&& lint_store.find_lints(&format!("clippy::{}", name_lower)).is_ok() {
db.span_suggestion(
diag.span_suggestion(
lint.span(),
"lowercase the lint name",
format!("clippy::{}", name_lower),
Applicability::MachineApplicable,
);
} else if let Some(sugg) = sugg {
db.span_suggestion(
diag.span_suggestion(
lint.span(),
"did you mean",
sugg.to_string(),
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/bit_mask.rs
Expand Up @@ -137,9 +137,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
VERBOSE_BIT_MASK,
e.span,
"bit mask could be simplified with a call to `trailing_zeros`",
|db| {
|diag| {
let sugg = Sugg::hir(cx, left1, "...").maybe_par();
db.span_suggestion(
diag.span_suggestion(
e.span,
"try",
format!("{}.trailing_zeros() >= {}", sugg, n.count_ones()),
Expand Down
10 changes: 5 additions & 5 deletions clippy_lints/src/booleans.rs
Expand Up @@ -376,13 +376,13 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
LOGIC_BUG,
e.span,
"this boolean expression contains a logic bug",
|db| {
db.span_help(
|diag| {
diag.span_help(
h2q.terminals[i].span,
"this expression can be optimized out by applying boolean operations to the \
outer expression",
);
db.span_suggestion(
diag.span_suggestion(
e.span,
"it would look like the following",
suggest(self.cx, suggestion, &h2q.terminals),
Expand Down Expand Up @@ -411,8 +411,8 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
NONMINIMAL_BOOL,
e.span,
"this boolean expression can be simplified",
|db| {
db.span_suggestions(
|diag| {
diag.span_suggestions(
e.span,
"try",
suggestions.into_iter(),
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/collapsible_if.rs
Expand Up @@ -137,10 +137,10 @@ fn check_collapsible_no_if_let(cx: &EarlyContext<'_>, expr: &ast::Expr, check: &
if expr.span.ctxt() != inner.span.ctxt() {
return;
}
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", |diag| {
let lhs = Sugg::ast(cx, check, "..");
let rhs = Sugg::ast(cx, check_inner, "..");
db.span_suggestion(
diag.span_suggestion(
expr.span,
"try",
format!(
Expand Down
8 changes: 4 additions & 4 deletions clippy_lints/src/copies.rs
Expand Up @@ -279,8 +279,8 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr<'_>) {
MATCH_SAME_ARMS,
j.body.span,
"this `match` has identical arm bodies",
|db| {
db.span_note(i.body.span, "same as this");
|diag| {
diag.span_note(i.body.span, "same as this");

// Note: this does not use `span_suggestion` on purpose:
// there is no clean way
Expand All @@ -296,15 +296,15 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr<'_>) {
// if the last arm is _, then i could be integrated into _
// note that i.pat cannot be _, because that would mean that we're
// hiding all the subsequent arms, and rust won't compile
db.span_note(
diag.span_note(
i.body.span,
&format!(
"`{}` has the same arm body as the `_` wildcard, consider removing it",
lhs
),
);
} else {
db.span_help(i.pat.span, &format!("consider refactoring into `{} | {}`", lhs, rhs));
diag.span_help(i.pat.span, &format!("consider refactoring into `{} | {}`", lhs, rhs));
}
},
);
Expand Down
8 changes: 4 additions & 4 deletions clippy_lints/src/derive.rs
Expand Up @@ -119,9 +119,9 @@ fn check_hash_peq<'a, 'tcx>(
span_lint_and_then(
cx, DERIVE_HASH_XOR_EQ, span,
mess,
|db| {
|diag| {
if let Some(node_id) = cx.tcx.hir().as_local_hir_id(impl_id) {
db.span_note(
diag.span_note(
cx.tcx.hir().span(node_id),
"`PartialEq` implemented here"
);
Expand Down Expand Up @@ -168,8 +168,8 @@ fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item<'_>, trait
EXPL_IMPL_CLONE_ON_COPY,
item.span,
"you are implementing `Clone` explicitly on a `Copy` type",
|db| {
db.span_note(item.span, "consider deriving `Clone` or removing `Copy`");
|diag| {
diag.span_note(item.span, "consider deriving `Clone` or removing `Copy`");
},
);
}
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/empty_enum.rs
Expand Up @@ -45,8 +45,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum {
let ty = cx.tcx.type_of(did);
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
if adt.variants.is_empty() {
span_lint_and_then(cx, EMPTY_ENUM, item.span, "enum with no variants", |db| {
db.span_help(
span_lint_and_then(cx, EMPTY_ENUM, item.span, "enum with no variants", |diag| {
diag.span_help(
item.span,
"consider using the uninhabited type `!` (never type) or a wrapper \
around it to introduce a type which can't be instantiated",
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/entry.rs
Expand Up @@ -148,15 +148,15 @@ impl<'a, 'tcx, 'b> Visitor<'tcx> for InsertVisitor<'a, 'tcx, 'b> {
if snippet_opt(self.cx, self.map.span) == snippet_opt(self.cx, params[0].span);
then {
span_lint_and_then(self.cx, MAP_ENTRY, self.span,
&format!("usage of `contains_key` followed by `insert` on a `{}`", self.ty), |db| {
&format!("usage of `contains_key` followed by `insert` on a `{}`", self.ty), |diag| {
if self.sole_expr {
let mut app = Applicability::MachineApplicable;
let help = format!("{}.entry({}).or_insert({});",
snippet_with_applicability(self.cx, self.map.span, "map", &mut app),
snippet_with_applicability(self.cx, params[1].span, "..", &mut app),
snippet_with_applicability(self.cx, params[2].span, "..", &mut app));

db.span_suggestion(
diag.span_suggestion(
self.span,
"consider using",
help,
Expand All @@ -168,7 +168,7 @@ impl<'a, 'tcx, 'b> Visitor<'tcx> for InsertVisitor<'a, 'tcx, 'b> {
snippet(self.cx, self.map.span, "map"),
snippet(self.cx, params[1].span, ".."));

db.span_label(
diag.span_label(
self.span,
&help,
);
Expand Down
20 changes: 10 additions & 10 deletions clippy_lints/src/eq_op.rs
Expand Up @@ -110,11 +110,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
OP_REF,
e.span,
"needlessly taken reference of both operands",
|db| {
|diag| {
let lsnip = snippet(cx, l.span, "...").to_string();
let rsnip = snippet(cx, r.span, "...").to_string();
multispan_sugg(
db,
diag,
"use the values directly".to_string(),
vec![(left.span, lsnip), (right.span, rsnip)],
);
Expand All @@ -124,9 +124,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
&& !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", |db| {
span_lint_and_then(cx, OP_REF, e.span, "needlessly taken reference of left operand", |diag| {
let lsnip = snippet(cx, l.span, "...").to_string();
db.span_suggestion(
diag.span_suggestion(
left.span,
"use the left value directly",
lsnip,
Expand All @@ -142,9 +142,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
OP_REF,
e.span,
"needlessly taken reference of right operand",
|db| {
|diag| {
let rsnip = snippet(cx, r.span, "...").to_string();
db.span_suggestion(
diag.span_suggestion(
right.span,
"use the right value directly",
rsnip,
Expand All @@ -161,9 +161,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
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", |db| {
span_lint_and_then(cx, OP_REF, e.span, "needlessly taken reference of left operand", |diag| {
let lsnip = snippet(cx, l.span, "...").to_string();
db.span_suggestion(
diag.span_suggestion(
left.span,
"use the left value directly",
lsnip,
Expand All @@ -179,9 +179,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
if (requires_ref || rcpy)
&& implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty.into()])
{
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", |diag| {
let rsnip = snippet(cx, r.span, "...").to_string();
db.span_suggestion(
diag.span_suggestion(
right.span,
"use the right value directly",
rsnip,
Expand Down
8 changes: 4 additions & 4 deletions clippy_lints/src/eta_reduction.rs
Expand Up @@ -101,9 +101,9 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
if compare_inputs(&mut iter_input_pats(decl, body), &mut args.iter());

then {
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", |diag| {
if let Some(snippet) = snippet_opt(cx, caller.span) {
db.span_suggestion(
diag.span_suggestion(
expr.span,
"remove closure as shown",
snippet,
Expand Down Expand Up @@ -131,8 +131,8 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
if let Some(name) = get_ufcs_type_name(cx, method_def_id, &args[0]);

then {
span_lint_and_then(cx, REDUNDANT_CLOSURE_FOR_METHOD_CALLS, expr.span, "redundant closure found", |db| {
db.span_suggestion(
span_lint_and_then(cx, REDUNDANT_CLOSURE_FOR_METHOD_CALLS, expr.span, "redundant closure found", |diag| {
diag.span_suggestion(
expr.span,
"remove closure as shown",
format!("{}::{}", name, path.ident.name),
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/fallible_impl_from.rs
Expand Up @@ -117,11 +117,11 @@ fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_it
FALLIBLE_IMPL_FROM,
impl_span,
"consider implementing `TryFrom` instead",
move |db| {
db.help(
move |diag| {
diag.help(
"`From` is intended for infallible conversions only. \
Use `TryFrom` if there's a possibility for the conversion to fail.");
db.span_note(fpu.result, "potential failure(s)");
diag.span_note(fpu.result, "potential failure(s)");
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/format.rs
Expand Up @@ -61,8 +61,8 @@ fn span_useless_format<T: LintContext>(cx: &T, span: Span, help: &str, mut sugg:
sugg.push(';');
}

span_lint_and_then(cx, USELESS_FORMAT, span, "useless use of `format!`", |db| {
db.span_suggestion(
span_lint_and_then(cx, USELESS_FORMAT, span, "useless use of `format!`", |diag| {
diag.span_suggestion(
to_replace,
help,
sugg,
Expand Down
8 changes: 4 additions & 4 deletions clippy_lints/src/functions.rs
Expand Up @@ -416,8 +416,8 @@ fn check_needless_must_use(
MUST_USE_UNIT,
fn_header_span,
"this unit-returning function has a `#[must_use]` attribute",
|db| {
db.span_suggestion(
|diag| {
diag.span_suggestion(
attr.span,
"remove the attribute",
"".into(),
Expand Down Expand Up @@ -454,9 +454,9 @@ fn check_must_use_candidate<'a, 'tcx>(
{
return;
}
span_lint_and_then(cx, MUST_USE_CANDIDATE, fn_span, msg, |db| {
span_lint_and_then(cx, MUST_USE_CANDIDATE, fn_span, msg, |diag| {
if let Some(snippet) = snippet_opt(cx, fn_span) {
db.span_suggestion(
diag.span_suggestion(
fn_span,
"add the attribute",
format!("#[must_use] {}", snippet),
Expand Down

0 comments on commit 870ae36

Please sign in to comment.