Make lint span smaller for needless return (#14790)

Fixes rust-lang/rust-clippy#14750 by reducing the lint span for
needless_return.

changelog: [`needless_return`]: Lint span no longer wraps to previous
line
This commit is contained in:
Jason Newcomb 2025-05-20 09:23:56 +00:00 committed by GitHub
commit f00c58b374
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 62 additions and 74 deletions

View file

@ -423,7 +423,14 @@ fn check_final_expr<'tcx>(
_ => return,
}
emit_return_lint(cx, ret_span, semi_spans, &replacement, expr.hir_id);
emit_return_lint(
cx,
peeled_drop_expr.span,
ret_span,
semi_spans,
&replacement,
expr.hir_id,
);
},
ExprKind::If(_, then, else_clause_opt) => {
check_block_return(cx, &then.kind, peeled_drop_expr.span, semi_spans.clone());
@ -448,6 +455,7 @@ fn check_final_expr<'tcx>(
fn emit_return_lint(
cx: &LateContext<'_>,
lint_span: Span,
ret_span: Span,
semi_spans: Vec<Span>,
replacement: &RetReplacement<'_>,
@ -457,7 +465,7 @@ fn emit_return_lint(
cx,
NEEDLESS_RETURN,
at,
ret_span,
lint_span,
"unneeded `return` statement",
|diag| {
let suggestions = std::iter::once((ret_span, replacement.to_string()))