Skip to content

Commit eb7f9d8

Browse files
committed
Fix internal lint warnings in code base.
1 parent d3b808b commit eb7f9d8

File tree

11 files changed

+96
-154
lines changed

11 files changed

+96
-154
lines changed

clippy_lints/src/derive.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::utils::paths;
2-
use crate::utils::{is_automatically_derived, is_copy, match_path, span_lint_and_then};
2+
use crate::utils::{is_automatically_derived, is_copy, match_path, span_lint_and_note, span_lint_and_then};
33
use if_chain::if_chain;
44
use rustc_hir::{Item, ItemKind, TraitRef};
55
use rustc_lint::{LateContext, LateLintPass};
@@ -163,14 +163,13 @@ fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item<'_>, trait
163163
_ => (),
164164
}
165165

166-
span_lint_and_then(
166+
span_lint_and_note(
167167
cx,
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`");
173-
},
171+
item.span,
172+
"consider deriving `Clone` or removing `Copy`",
174173
);
175174
}
176175
}

clippy_lints/src/empty_enum.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! lint when there is an enum with no variants
22
3-
use crate::utils::span_lint_and_then;
3+
use crate::utils::span_lint_and_help;
44
use rustc_hir::{Item, ItemKind};
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -45,13 +45,14 @@ 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(
50-
item.span,
51-
"consider using the uninhabited type `!` (never type) or a wrapper \
52-
around it to introduce a type which can't be instantiated",
53-
);
54-
});
48+
span_lint_and_help(
49+
cx,
50+
EMPTY_ENUM,
51+
item.span,
52+
"enum with no variants",
53+
"consider using the uninhabited type `!` (never type) or a wrapper \
54+
around it to introduce a type which can't be instantiated",
55+
);
5556
}
5657
}
5758
}

clippy_lints/src/eta_reduction.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use rustc_middle::ty::{self, Ty};
77
use rustc_session::{declare_lint_pass, declare_tool_lint};
88

99
use crate::utils::{
10-
implements_trait, is_adjusted, iter_input_pats, snippet_opt, span_lint_and_then, type_is_unsafe_function,
10+
implements_trait, is_adjusted, iter_input_pats, snippet_opt, span_lint_and_sugg, span_lint_and_then,
11+
type_is_unsafe_function,
1112
};
1213

1314
declare_clippy_lint! {
@@ -131,14 +132,10 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
131132
if let Some(name) = get_ufcs_type_name(cx, method_def_id, &args[0]);
132133

133134
then {
134-
span_lint_and_then(cx, REDUNDANT_CLOSURE_FOR_METHOD_CALLS, expr.span, "redundant closure found", |db| {
135-
db.span_suggestion(
136-
expr.span,
137-
"remove closure as shown",
138-
format!("{}::{}", name, path.ident.name),
139-
Applicability::MachineApplicable,
140-
);
141-
});
135+
span_lint_and_sugg(cx, REDUNDANT_CLOSURE_FOR_METHOD_CALLS, expr.span, "redundant closure found",
136+
"remove closure as shown",
137+
format!("{}::{}", name, path.ident.name),
138+
Applicability::MachineApplicable,);
142139
}
143140
);
144141
}

clippy_lints/src/identity_conversion.rs

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::utils::{
2-
match_def_path, match_trait_method, paths, same_tys, snippet, snippet_with_macro_callsite, span_lint_and_then,
2+
match_def_path, match_trait_method, paths, same_tys, snippet, snippet_with_macro_callsite, span_lint_and_sugg,
33
};
44
use rustc_errors::Applicability;
55
use rustc_hir::{Expr, ExprKind, HirId, MatchSource};
@@ -58,29 +58,31 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
5858
if same_tys(cx, a, b) {
5959
let sugg = snippet_with_macro_callsite(cx, args[0].span, "<expr>").to_string();
6060

61-
span_lint_and_then(cx, IDENTITY_CONVERSION, e.span, "identical conversion", |db| {
62-
db.span_suggestion(
63-
e.span,
64-
"consider removing `.into()`",
65-
sugg,
66-
Applicability::MachineApplicable, // snippet
67-
);
68-
});
61+
span_lint_and_sugg(
62+
cx,
63+
IDENTITY_CONVERSION,
64+
e.span,
65+
"identical conversion",
66+
"consider removing `.into()`",
67+
sugg,
68+
Applicability::MachineApplicable, // snippet
69+
);
6970
}
7071
}
7172
if match_trait_method(cx, e, &paths::INTO_ITERATOR) && &*name.ident.as_str() == "into_iter" {
7273
let a = cx.tables.expr_ty(e);
7374
let b = cx.tables.expr_ty(&args[0]);
7475
if same_tys(cx, a, b) {
7576
let sugg = snippet(cx, args[0].span, "<expr>").into_owned();
76-
span_lint_and_then(cx, IDENTITY_CONVERSION, e.span, "identical conversion", |db| {
77-
db.span_suggestion(
78-
e.span,
79-
"consider removing `.into_iter()`",
80-
sugg,
81-
Applicability::MachineApplicable, // snippet
82-
);
83-
});
77+
span_lint_and_sugg(
78+
cx,
79+
IDENTITY_CONVERSION,
80+
e.span,
81+
"identical conversion",
82+
"consider removing `.into_iter()`",
83+
sugg,
84+
Applicability::MachineApplicable, // snippet
85+
);
8486
}
8587
}
8688
},
@@ -95,14 +97,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
9597
let sugg = snippet(cx, args[0].span.source_callsite(), "<expr>").into_owned();
9698
let sugg_msg =
9799
format!("consider removing `{}()`", snippet(cx, path.span, "From::from"));
98-
span_lint_and_then(cx, IDENTITY_CONVERSION, e.span, "identical conversion", |db| {
99-
db.span_suggestion(
100-
e.span,
101-
&sugg_msg,
102-
sugg,
103-
Applicability::MachineApplicable, // snippet
104-
);
105-
});
100+
span_lint_and_sugg(
101+
cx,
102+
IDENTITY_CONVERSION,
103+
e.span,
104+
"identical conversion",
105+
&sugg_msg,
106+
sugg,
107+
Applicability::MachineApplicable, // snippet
108+
);
106109
}
107110
}
108111
}

clippy_lints/src/int_plus_one.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_errors::Applicability;
55
use rustc_lint::{EarlyContext, EarlyLintPass};
66
use rustc_session::{declare_lint_pass, declare_tool_lint};
77

8-
use crate::utils::{snippet_opt, span_lint_and_then};
8+
use crate::utils::{snippet_opt, span_lint_and_sugg};
99

1010
declare_clippy_lint! {
1111
/// **What it does:** Checks for usage of `x >= y + 1` or `x - 1 >= y` (and `<=`) in a block
@@ -149,19 +149,14 @@ impl IntPlusOne {
149149
}
150150

151151
fn emit_warning(cx: &EarlyContext<'_>, block: &Expr, recommendation: String) {
152-
span_lint_and_then(
152+
span_lint_and_sugg(
153153
cx,
154154
INT_PLUS_ONE,
155155
block.span,
156156
"Unnecessary `>= y + 1` or `x - 1 >=`",
157-
|db| {
158-
db.span_suggestion(
159-
block.span,
160-
"change it to",
161-
recommendation,
162-
Applicability::MachineApplicable, // snippet
163-
);
164-
},
157+
"change it to",
158+
recommendation,
159+
Applicability::MachineApplicable, // snippet
165160
);
166161
}
167162
}

clippy_lints/src/loops.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,25 +2471,19 @@ fn check_needless_collect<'a, 'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'a, '
24712471
match_type(cx, ty, &paths::HASHMAP) {
24722472
if method.ident.name == sym!(len) {
24732473
let span = shorten_needless_collect_span(expr);
2474-
span_lint_and_then(cx, NEEDLESS_COLLECT, span, NEEDLESS_COLLECT_MSG, |db| {
2475-
db.span_suggestion(
2476-
span,
2474+
span_lint_and_sugg(cx, NEEDLESS_COLLECT, span, NEEDLESS_COLLECT_MSG,
24772475
"replace with",
24782476
".count()".to_string(),
24792477
Applicability::MachineApplicable,
24802478
);
2481-
});
24822479
}
24832480
if method.ident.name == sym!(is_empty) {
24842481
let span = shorten_needless_collect_span(expr);
2485-
span_lint_and_then(cx, NEEDLESS_COLLECT, span, NEEDLESS_COLLECT_MSG, |db| {
2486-
db.span_suggestion(
2487-
span,
2482+
span_lint_and_sugg(cx, NEEDLESS_COLLECT, span, NEEDLESS_COLLECT_MSG,
24882483
"replace with",
24892484
".next().is_none()".to_string(),
24902485
Applicability::MachineApplicable,
24912486
);
2492-
});
24932487
}
24942488
if method.ident.name == sym!(contains) {
24952489
let contains_arg = snippet(cx, args[1].span, "??");

clippy_lints/src/ptr.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
use crate::utils::ptr::get_spans;
44
use crate::utils::{
5-
is_type_diagnostic_item, match_qpath, match_type, paths, snippet_opt, span_lint, span_lint_and_then,
6-
walk_ptrs_hir_ty,
5+
is_type_diagnostic_item, match_qpath, match_type, paths, snippet_opt, span_lint, span_lint_and_sugg,
6+
span_lint_and_then, walk_ptrs_hir_ty,
77
};
88
use if_chain::if_chain;
99
use rustc_errors::Applicability;
@@ -234,20 +234,15 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl<'_>, fn_id: HirId, opt_body_
234234
then {
235235
let replacement = snippet_opt(cx, inner.span);
236236
if let Some(r) = replacement {
237-
span_lint_and_then(
237+
span_lint_and_sugg(
238238
cx,
239239
PTR_ARG,
240240
arg.span,
241241
"using a reference to `Cow` is not recommended.",
242-
|db| {
243-
db.span_suggestion(
244-
arg.span,
245242
"change this to",
246243
"&".to_owned() + &r,
247244
Applicability::Unspecified,
248245
);
249-
},
250-
);
251246
}
252247
}
253248
}

clippy_lints/src/returns.rs

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_session::{declare_lint_pass, declare_tool_lint};
88
use rustc_span::source_map::Span;
99
use rustc_span::BytePos;
1010

11-
use crate::utils::{in_macro, match_path_ast, snippet_opt, span_lint_and_then};
11+
use crate::utils::{in_macro, match_path_ast, snippet_opt, span_lint_and_sugg, span_lint_and_then};
1212

1313
declare_clippy_lint! {
1414
/// **What it does:** Checks for return statements at the end of a block.
@@ -162,24 +162,26 @@ impl Return {
162162
},
163163
None => match replacement {
164164
RetReplacement::Empty => {
165-
span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded `return` statement", |db| {
166-
db.span_suggestion(
167-
ret_span,
168-
"remove `return`",
169-
String::new(),
170-
Applicability::MachineApplicable,
171-
);
172-
});
165+
span_lint_and_sugg(
166+
cx,
167+
NEEDLESS_RETURN,
168+
ret_span,
169+
"unneeded `return` statement",
170+
"remove `return`",
171+
String::new(),
172+
Applicability::MachineApplicable,
173+
);
173174
},
174175
RetReplacement::Block => {
175-
span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded `return` statement", |db| {
176-
db.span_suggestion(
177-
ret_span,
178-
"replace `return` with an empty block",
179-
"{}".to_string(),
180-
Applicability::MachineApplicable,
181-
);
182-
});
176+
span_lint_and_sugg(
177+
cx,
178+
NEEDLESS_RETURN,
179+
ret_span,
180+
"unneeded `return` statement",
181+
"replace `return` with an empty block",
182+
"{}".to_string(),
183+
Applicability::MachineApplicable,
184+
);
183185
},
184186
},
185187
}
@@ -259,14 +261,11 @@ impl EarlyLintPass for Return {
259261
} else {
260262
(ty.span, Applicability::MaybeIncorrect)
261263
};
262-
span_lint_and_then(cx, UNUSED_UNIT, rspan, "unneeded unit return type", |db| {
263-
db.span_suggestion(
264-
rspan,
264+
span_lint_and_sugg(cx, UNUSED_UNIT, rspan, "unneeded unit return type",
265265
"remove the `-> ()`",
266266
String::new(),
267267
appl,
268268
);
269-
});
270269
}
271270
}
272271
}
@@ -279,14 +278,12 @@ impl EarlyLintPass for Return {
279278
if is_unit_expr(expr) && !stmt.span.from_expansion();
280279
then {
281280
let sp = expr.span;
282-
span_lint_and_then(cx, UNUSED_UNIT, sp, "unneeded unit expression", |db| {
283-
db.span_suggestion(
284-
sp,
281+
span_lint_and_sugg(cx, UNUSED_UNIT, sp, "unneeded unit expression",
285282
"remove the final `()`",
286283
String::new(),
287284
Applicability::MachineApplicable,
288285
);
289-
});
286+
290287
}
291288
}
292289
}
@@ -295,14 +292,15 @@ impl EarlyLintPass for Return {
295292
match e.kind {
296293
ast::ExprKind::Ret(Some(ref expr)) | ast::ExprKind::Break(_, Some(ref expr)) => {
297294
if is_unit_expr(expr) && !expr.span.from_expansion() {
298-
span_lint_and_then(cx, UNUSED_UNIT, expr.span, "unneeded `()`", |db| {
299-
db.span_suggestion(
300-
expr.span,
301-
"remove the `()`",
302-
String::new(),
303-
Applicability::MachineApplicable,
304-
);
305-
});
295+
span_lint_and_sugg(
296+
cx,
297+
UNUSED_UNIT,
298+
expr.span,
299+
"unneeded `()`",
300+
"remove the `()`",
301+
String::new(),
302+
Applicability::MachineApplicable,
303+
);
306304
}
307305
},
308306
_ => (),

clippy_lints/src/transmute.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::utils::{
2-
is_normalizable, last_path_segment, match_def_path, paths, snippet, span_lint, span_lint_and_then, sugg,
2+
is_normalizable, last_path_segment, match_def_path, paths, snippet, span_lint, span_lint_and_sugg,
3+
span_lint_and_then, sugg,
34
};
45
use if_chain::if_chain;
56
use rustc_ast::ast;
@@ -441,14 +442,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
441442
""
442443
};
443444

444-
span_lint_and_then(
445+
span_lint_and_sugg(
445446
cx,
446447
TRANSMUTE_BYTES_TO_STR,
447448
e.span,
448449
&format!("transmute from a `{}` to a `{}`", from_ty, to_ty),
449-
|db| {
450-
db.span_suggestion(
451-
e.span,
452450
"consider using",
453451
format!(
454452
"std::str::from_utf8{}({}).unwrap()",
@@ -457,8 +455,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
457455
),
458456
Applicability::Unspecified,
459457
);
460-
}
461-
)
462458
} else {
463459
if cx.tcx.erase_regions(&from_ty) != cx.tcx.erase_regions(&to_ty) {
464460
span_lint_and_then(

0 commit comments

Comments
 (0)