Skip to content

Commit d03d3bd

Browse files
committed
Fixes internal lint warning in code base.
1 parent bdd32e7 commit d03d3bd

File tree

9 files changed

+153
-151
lines changed

9 files changed

+153
-151
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-
|diag| {
172-
diag.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", |diag| {
49-
diag.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_then(
49+
cx,
50+
EMPTY_ENUM,
51+
item.span,
52+
"enum with no variants",
53+
"consider using the uninhabited type `!` (never type) or a wrapper around it \
54+
to introduce a type which can't be instantiated",
55+
);
5556
}
5657
}
5758
}

clippy_lints/src/eta_reduction.rs

Lines changed: 11 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,15 @@ 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", |diag| {
135-
diag.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(
136+
cx,
137+
REDUNDANT_CLOSURE_FOR_METHOD_CALLS,
138+
expr.span,
139+
"redundant closure found",
140+
"remove closure as shown",
141+
format!("{}::{}", name, path.ident.name),
142+
Applicability::MachineApplicable,
143+
);
142144
}
143145
);
144146
}

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", |diag| {
62-
diag.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", |diag| {
77-
diag.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", |diag| {
99-
diag.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-
|diag| {
158-
diag.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: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,45 +2471,50 @@ 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, |diag| {
2475-
diag.span_suggestion(
2476-
span,
2474+
span_lint_and_sugg(cx,
2475+
NEEDLESS_COLLECT,
2476+
span,
2477+
NEEDLESS_COLLECT_MSG,
24772478
"replace with",
24782479
".count()".to_string(),
24792480
Applicability::MachineApplicable,
24802481
);
2481-
});
24822482
}
24832483
if method.ident.name == sym!(is_empty) {
24842484
let span = shorten_needless_collect_span(expr);
2485-
span_lint_and_then(cx, NEEDLESS_COLLECT, span, NEEDLESS_COLLECT_MSG, |diag| {
2486-
diag.span_suggestion(
2487-
span,
2488-
"replace with",
2489-
".next().is_none()".to_string(),
2490-
Applicability::MachineApplicable,
2485+
span_lint_and_sugg(cx,
2486+
NEEDLESS_COLLECT,
2487+
span,
2488+
NEEDLESS_COLLECT_MSG,
2489+
"replace with",
2490+
".next().is_none()".to_string(),
2491+
Applicability::MachineApplicable,
24912492
);
2492-
});
24932493
}
24942494
if method.ident.name == sym!(contains) {
24952495
let contains_arg = snippet(cx, args[1].span, "??");
24962496
let span = shorten_needless_collect_span(expr);
2497-
span_lint_and_then(cx, NEEDLESS_COLLECT, span, NEEDLESS_COLLECT_MSG, |diag| {
2498-
let (arg, pred) = if contains_arg.starts_with('&') {
2499-
("x", &contains_arg[1..])
2500-
} else {
2501-
("&x", &*contains_arg)
2502-
};
2503-
diag.span_suggestion(
2504-
span,
2505-
"replace with",
2506-
format!(
2507-
".any(|{}| x == {})",
2508-
arg, pred
2509-
),
2510-
Applicability::MachineApplicable,
2511-
);
2512-
});
2497+
span_lint_and_then(cx,
2498+
NEEDLESS_COLLECT,
2499+
span,
2500+
NEEDLESS_COLLECT_MSG,
2501+
|db| {
2502+
let (arg, pred) = if contains_arg.starts_with('&') {
2503+
("x", &contains_arg[1..])
2504+
} else {
2505+
("&x", &*contains_arg)
2506+
};
2507+
db.span_suggestion(
2508+
span,
2509+
"replace with",
2510+
format!(
2511+
".any(|{}| x == {})",
2512+
arg, pred
2513+
),
2514+
Applicability::MachineApplicable,
2515+
);
2516+
}
2517+
);
25132518
}
25142519
}
25152520
}

clippy_lints/src/ptr.rs

Lines changed: 6 additions & 11 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,19 +234,14 @@ 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-
|diag| {
243-
diag.span_suggestion(
244-
arg.span,
245-
"change this to",
246-
"&".to_owned() + &r,
247-
Applicability::Unspecified,
248-
);
249-
},
242+
"change this to",
243+
"&".to_owned() + &r,
244+
Applicability::Unspecified,
250245
);
251246
}
252247
}

0 commit comments

Comments
 (0)