|
1 | | -use clippy_utils::diagnostics::{span_lint, span_lint_and_help}; |
| 1 | +use clippy_utils::diagnostics::span_lint_and_then; |
2 | 2 | use rustc_hir::def_id::DefId; |
3 | 3 | use rustc_hir::{Closure, Expr, ExprKind, StmtKind}; |
4 | 4 | use rustc_lint::{LateContext, LateLintPass}; |
@@ -180,32 +180,21 @@ impl<'tcx> LateLintPass<'tcx> for UnitReturnExpectingOrd { |
180 | 180 | let args = std::iter::once(receiver).chain(args.iter()).collect::<Vec<_>>(); |
181 | 181 | let arg_indices = get_args_to_check(cx, expr, args.len(), fn_mut_trait, ord_trait, partial_ord_trait); |
182 | 182 | 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 \ |
191 | 190 | 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 | + ); |
209 | 198 | } |
210 | 199 | } |
211 | 200 | } |
|
0 commit comments