Skip to content

Commit 3dcef78

Browse files
authored
refactor(unit_return_expecting_ord): use one big span_lint_and_then (#17234)
Small leftover from a PR that didn't work out changelog: none
2 parents 6f66667 + 67878aa commit 3dcef78

1 file changed

Lines changed: 15 additions & 26 deletions

File tree

clippy_lints/src/unit_return_expecting_ord.rs

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_utils::diagnostics::{span_lint, span_lint_and_help};
1+
use clippy_utils::diagnostics::span_lint_and_then;
22
use rustc_hir::def_id::DefId;
33
use rustc_hir::{Closure, Expr, ExprKind, StmtKind};
44
use rustc_lint::{LateContext, LateLintPass};
@@ -180,32 +180,21 @@ impl<'tcx> LateLintPass<'tcx> for UnitReturnExpectingOrd {
180180
let args = std::iter::once(receiver).chain(args.iter()).collect::<Vec<_>>();
181181
let arg_indices = get_args_to_check(cx, expr, args.len(), fn_mut_trait, ord_trait, partial_ord_trait);
182182
for (i, trait_name) in arg_indices {
183-
match check_arg(cx, args[i]) {
184-
Some((span, None)) => {
185-
span_lint(
186-
cx,
187-
UNIT_RETURN_EXPECTING_ORD,
188-
span,
189-
format!(
190-
"this closure returns \
183+
if let Some((span, last_semi)) = check_arg(cx, args[i]) {
184+
span_lint_and_then(
185+
cx,
186+
UNIT_RETURN_EXPECTING_ORD,
187+
span,
188+
format!(
189+
"this closure returns \
191190
the unit type which also implements {trait_name}"
192-
),
193-
);
194-
},
195-
Some((span, Some(last_semi))) => {
196-
span_lint_and_help(
197-
cx,
198-
UNIT_RETURN_EXPECTING_ORD,
199-
span,
200-
format!(
201-
"this closure returns \
202-
the unit type which also implements {trait_name}"
203-
),
204-
Some(last_semi),
205-
"probably caused by this trailing semicolon",
206-
);
207-
},
208-
None => {},
191+
),
192+
|diag| {
193+
if let Some(last_semi) = last_semi {
194+
diag.span_help(last_semi, "probably caused by this trailing semicolon");
195+
}
196+
},
197+
);
209198
}
210199
}
211200
}

0 commit comments

Comments
 (0)