Skip to content

Commit 3ea8e5e

Browse files
committed
Auto merge of #5482 - phansch:diag, r=matthiaskrgr
Cleanup: Rename 'db' variables to 'diag' Did the same in rustc a while ago: rust-lang/rust#65428 changelog: none
2 parents 82be9dc + eb7ad1c commit 3ea8e5e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+355
-328
lines changed

clippy_lints/src/assign_ops.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
131131
ASSIGN_OP_PATTERN,
132132
expr.span,
133133
"manual implementation of an assign operation",
134-
|db| {
134+
|diag| {
135135
if let (Some(snip_a), Some(snip_r)) =
136136
(snippet_opt(cx, assignee.span), snippet_opt(cx, rhs.span))
137137
{
138-
db.span_suggestion(
138+
diag.span_suggestion(
139139
expr.span,
140140
"replace it with",
141141
format!("{} {}= {}", snip_a, op.node.as_str(), snip_r),
@@ -199,12 +199,12 @@ fn lint_misrefactored_assign_op(
199199
MISREFACTORED_ASSIGN_OP,
200200
expr.span,
201201
"variable appears on both sides of an assignment operation",
202-
|db| {
202+
|diag| {
203203
if let (Some(snip_a), Some(snip_r)) = (snippet_opt(cx, assignee.span), snippet_opt(cx, rhs_other.span)) {
204204
let a = &sugg::Sugg::hir(cx, assignee, "..");
205205
let r = &sugg::Sugg::hir(cx, rhs, "..");
206206
let long = format!("{} = {}", snip_a, sugg::make_binop(higher::binop(op.node), a, r));
207-
db.span_suggestion(
207+
diag.span_suggestion(
208208
expr.span,
209209
&format!(
210210
"Did you mean `{} = {} {} {}` or `{}`? Consider replacing it with",
@@ -217,7 +217,7 @@ fn lint_misrefactored_assign_op(
217217
format!("{} {}= {}", snip_a, op.node.as_str(), snip_r),
218218
Applicability::MaybeIncorrect,
219219
);
220-
db.span_suggestion(
220+
diag.span_suggestion(
221221
expr.span,
222222
"or",
223223
long,

clippy_lints/src/attrs.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
273273
USELESS_ATTRIBUTE,
274274
line_span,
275275
"useless lint attribute",
276-
|db| {
276+
|diag| {
277277
sugg = sugg.replacen("#[", "#![", 1);
278-
db.span_suggestion(
278+
diag.span_suggestion(
279279
line_span,
280280
"if you just forgot a `!`, use",
281281
sugg,
@@ -329,7 +329,7 @@ fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) {
329329
UNKNOWN_CLIPPY_LINTS,
330330
lint.span(),
331331
&format!("unknown clippy lint: clippy::{}", name),
332-
|db| {
332+
|diag| {
333333
let name_lower = name.as_str().to_lowercase();
334334
let symbols = lint_store.get_lints().iter().map(
335335
|l| Symbol::intern(&l.name_lower())
@@ -341,14 +341,14 @@ fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) {
341341
);
342342
if name.as_str().chars().any(char::is_uppercase)
343343
&& lint_store.find_lints(&format!("clippy::{}", name_lower)).is_ok() {
344-
db.span_suggestion(
344+
diag.span_suggestion(
345345
lint.span(),
346346
"lowercase the lint name",
347347
format!("clippy::{}", name_lower),
348348
Applicability::MachineApplicable,
349349
);
350350
} else if let Some(sugg) = sugg {
351-
db.span_suggestion(
351+
diag.span_suggestion(
352352
lint.span(),
353353
"did you mean",
354354
sugg.to_string(),

clippy_lints/src/bit_mask.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
137137
VERBOSE_BIT_MASK,
138138
e.span,
139139
"bit mask could be simplified with a call to `trailing_zeros`",
140-
|db| {
140+
|diag| {
141141
let sugg = Sugg::hir(cx, left1, "...").maybe_par();
142-
db.span_suggestion(
142+
diag.span_suggestion(
143143
e.span,
144144
"try",
145145
format!("{}.trailing_zeros() >= {}", sugg, n.count_ones()),

clippy_lints/src/booleans.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -376,13 +376,13 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
376376
LOGIC_BUG,
377377
e.span,
378378
"this boolean expression contains a logic bug",
379-
|db| {
380-
db.span_help(
379+
|diag| {
380+
diag.span_help(
381381
h2q.terminals[i].span,
382382
"this expression can be optimized out by applying boolean operations to the \
383383
outer expression",
384384
);
385-
db.span_suggestion(
385+
diag.span_suggestion(
386386
e.span,
387387
"it would look like the following",
388388
suggest(self.cx, suggestion, &h2q.terminals),
@@ -411,8 +411,8 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
411411
NONMINIMAL_BOOL,
412412
e.span,
413413
"this boolean expression can be simplified",
414-
|db| {
415-
db.span_suggestions(
414+
|diag| {
415+
diag.span_suggestions(
416416
e.span,
417417
"try",
418418
suggestions.into_iter(),

clippy_lints/src/collapsible_if.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ fn check_collapsible_no_if_let(cx: &EarlyContext<'_>, expr: &ast::Expr, check: &
137137
if expr.span.ctxt() != inner.span.ctxt() {
138138
return;
139139
}
140-
span_lint_and_then(cx, COLLAPSIBLE_IF, expr.span, "this `if` statement can be collapsed", |db| {
140+
span_lint_and_then(cx, COLLAPSIBLE_IF, expr.span, "this `if` statement can be collapsed", |diag| {
141141
let lhs = Sugg::ast(cx, check, "..");
142142
let rhs = Sugg::ast(cx, check_inner, "..");
143-
db.span_suggestion(
143+
diag.span_suggestion(
144144
expr.span,
145145
"try",
146146
format!(

clippy_lints/src/copies.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr<'_>) {
279279
MATCH_SAME_ARMS,
280280
j.body.span,
281281
"this `match` has identical arm bodies",
282-
|db| {
283-
db.span_note(i.body.span, "same as this");
282+
|diag| {
283+
diag.span_note(i.body.span, "same as this");
284284

285285
// Note: this does not use `span_suggestion` on purpose:
286286
// there is no clean way
@@ -296,15 +296,15 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr<'_>) {
296296
// if the last arm is _, then i could be integrated into _
297297
// note that i.pat cannot be _, because that would mean that we're
298298
// hiding all the subsequent arms, and rust won't compile
299-
db.span_note(
299+
diag.span_note(
300300
i.body.span,
301301
&format!(
302302
"`{}` has the same arm body as the `_` wildcard, consider removing it",
303303
lhs
304304
),
305305
);
306306
} else {
307-
db.span_help(i.pat.span, &format!("consider refactoring into `{} | {}`", lhs, rhs));
307+
diag.span_help(i.pat.span, &format!("consider refactoring into `{} | {}`", lhs, rhs));
308308
}
309309
},
310310
);

clippy_lints/src/derive.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ fn check_hash_peq<'a, 'tcx>(
119119
span_lint_and_then(
120120
cx, DERIVE_HASH_XOR_EQ, span,
121121
mess,
122-
|db| {
122+
|diag| {
123123
if let Some(node_id) = cx.tcx.hir().as_local_hir_id(impl_id) {
124-
db.span_note(
124+
diag.span_note(
125125
cx.tcx.hir().span(node_id),
126126
"`PartialEq` implemented here"
127127
);
@@ -168,8 +168,8 @@ fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item<'_>, trait
168168
EXPL_IMPL_CLONE_ON_COPY,
169169
item.span,
170170
"you are implementing `Clone` explicitly on a `Copy` type",
171-
|db| {
172-
db.span_note(item.span, "consider deriving `Clone` or removing `Copy`");
171+
|diag| {
172+
diag.span_note(item.span, "consider deriving `Clone` or removing `Copy`");
173173
},
174174
);
175175
}

clippy_lints/src/empty_enum.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum {
4545
let ty = cx.tcx.type_of(did);
4646
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
4747
if adt.variants.is_empty() {
48-
span_lint_and_then(cx, EMPTY_ENUM, item.span, "enum with no variants", |db| {
49-
db.span_help(
48+
span_lint_and_then(cx, EMPTY_ENUM, item.span, "enum with no variants", |diag| {
49+
diag.span_help(
5050
item.span,
5151
"consider using the uninhabited type `!` (never type) or a wrapper \
5252
around it to introduce a type which can't be instantiated",

clippy_lints/src/entry.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,15 @@ impl<'a, 'tcx, 'b> Visitor<'tcx> for InsertVisitor<'a, 'tcx, 'b> {
148148
if snippet_opt(self.cx, self.map.span) == snippet_opt(self.cx, params[0].span);
149149
then {
150150
span_lint_and_then(self.cx, MAP_ENTRY, self.span,
151-
&format!("usage of `contains_key` followed by `insert` on a `{}`", self.ty), |db| {
151+
&format!("usage of `contains_key` followed by `insert` on a `{}`", self.ty), |diag| {
152152
if self.sole_expr {
153153
let mut app = Applicability::MachineApplicable;
154154
let help = format!("{}.entry({}).or_insert({});",
155155
snippet_with_applicability(self.cx, self.map.span, "map", &mut app),
156156
snippet_with_applicability(self.cx, params[1].span, "..", &mut app),
157157
snippet_with_applicability(self.cx, params[2].span, "..", &mut app));
158158

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

171-
db.span_label(
171+
diag.span_label(
172172
self.span,
173173
&help,
174174
);

clippy_lints/src/eq_op.rs

+36-24
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
110110
OP_REF,
111111
e.span,
112112
"needlessly taken reference of both operands",
113-
|db| {
113+
|diag| {
114114
let lsnip = snippet(cx, l.span, "...").to_string();
115115
let rsnip = snippet(cx, r.span, "...").to_string();
116116
multispan_sugg(
117-
db,
117+
diag,
118118
"use the values directly".to_string(),
119119
vec![(left.span, lsnip), (right.span, rsnip)],
120120
);
@@ -124,15 +124,21 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
124124
&& !rcpy
125125
&& implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right).into()])
126126
{
127-
span_lint_and_then(cx, OP_REF, e.span, "needlessly taken reference of left operand", |db| {
128-
let lsnip = snippet(cx, l.span, "...").to_string();
129-
db.span_suggestion(
130-
left.span,
131-
"use the left value directly",
132-
lsnip,
133-
Applicability::MaybeIncorrect, // FIXME #2597
134-
);
135-
})
127+
span_lint_and_then(
128+
cx,
129+
OP_REF,
130+
e.span,
131+
"needlessly taken reference of left operand",
132+
|diag| {
133+
let lsnip = snippet(cx, l.span, "...").to_string();
134+
diag.span_suggestion(
135+
left.span,
136+
"use the left value directly",
137+
lsnip,
138+
Applicability::MaybeIncorrect, // FIXME #2597
139+
);
140+
},
141+
)
136142
} else if !lcpy
137143
&& rcpy
138144
&& implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty.into()])
@@ -142,9 +148,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
142148
OP_REF,
143149
e.span,
144150
"needlessly taken reference of right operand",
145-
|db| {
151+
|diag| {
146152
let rsnip = snippet(cx, r.span, "...").to_string();
147-
db.span_suggestion(
153+
diag.span_suggestion(
148154
right.span,
149155
"use the right value directly",
150156
rsnip,
@@ -161,15 +167,21 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
161167
if (requires_ref || lcpy)
162168
&& implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right).into()])
163169
{
164-
span_lint_and_then(cx, OP_REF, e.span, "needlessly taken reference of left operand", |db| {
165-
let lsnip = snippet(cx, l.span, "...").to_string();
166-
db.span_suggestion(
167-
left.span,
168-
"use the left value directly",
169-
lsnip,
170-
Applicability::MaybeIncorrect, // FIXME #2597
171-
);
172-
})
170+
span_lint_and_then(
171+
cx,
172+
OP_REF,
173+
e.span,
174+
"needlessly taken reference of left operand",
175+
|diag| {
176+
let lsnip = snippet(cx, l.span, "...").to_string();
177+
diag.span_suggestion(
178+
left.span,
179+
"use the left value directly",
180+
lsnip,
181+
Applicability::MaybeIncorrect, // FIXME #2597
182+
);
183+
},
184+
)
173185
}
174186
},
175187
// foo == &bar
@@ -179,9 +191,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
179191
if (requires_ref || rcpy)
180192
&& implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty.into()])
181193
{
182-
span_lint_and_then(cx, OP_REF, e.span, "taken reference of right operand", |db| {
194+
span_lint_and_then(cx, OP_REF, e.span, "taken reference of right operand", |diag| {
183195
let rsnip = snippet(cx, r.span, "...").to_string();
184-
db.span_suggestion(
196+
diag.span_suggestion(
185197
right.span,
186198
"use the right value directly",
187199
rsnip,

clippy_lints/src/eta_reduction.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
101101
if compare_inputs(&mut iter_input_pats(decl, body), &mut args.iter());
102102

103103
then {
104-
span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure found", |db| {
104+
span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure found", |diag| {
105105
if let Some(snippet) = snippet_opt(cx, caller.span) {
106-
db.span_suggestion(
106+
diag.span_suggestion(
107107
expr.span,
108108
"remove closure as shown",
109109
snippet,
@@ -131,8 +131,8 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
131131
if let Some(name) = get_ufcs_type_name(cx, method_def_id, &args[0]);
132132

133133
then {
134-
span_lint_and_then(cx, REDUNDANT_CLOSURE_FOR_METHOD_CALLS, expr.span, "redundant closure found", |db| {
135-
db.span_suggestion(
134+
span_lint_and_then(cx, REDUNDANT_CLOSURE_FOR_METHOD_CALLS, expr.span, "redundant closure found", |diag| {
135+
diag.span_suggestion(
136136
expr.span,
137137
"remove closure as shown",
138138
format!("{}::{}", name, path.ident.name),

clippy_lints/src/fallible_impl_from.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_it
117117
FALLIBLE_IMPL_FROM,
118118
impl_span,
119119
"consider implementing `TryFrom` instead",
120-
move |db| {
121-
db.help(
120+
move |diag| {
121+
diag.help(
122122
"`From` is intended for infallible conversions only. \
123123
Use `TryFrom` if there's a possibility for the conversion to fail.");
124-
db.span_note(fpu.result, "potential failure(s)");
124+
diag.span_note(fpu.result, "potential failure(s)");
125125
});
126126
}
127127
}

0 commit comments

Comments
 (0)