diff options
| author | Jason Newcomb <jsnewcomb@pm.me> | 2025-05-20 09:23:56 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-20 09:23:56 +0000 |
| commit | f00c58b374e691e89ba034bfcb9afeebac9fda37 (patch) | |
| tree | 5c971cfd06b93e73c65cfa0b6edc1fb874f846b7 /clippy_lints | |
| parent | 6753e164be65dbb24f6a5b43b65e08772a313d2d (diff) | |
| parent | e0fd8144c04cd385c044fafeb3ae93269c310ab6 (diff) | |
| download | rust-f00c58b374e691e89ba034bfcb9afeebac9fda37.tar.gz rust-f00c58b374e691e89ba034bfcb9afeebac9fda37.zip | |
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
Diffstat (limited to 'clippy_lints')
| -rw-r--r-- | clippy_lints/src/returns.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 122d97fdf81..ab9b0f88f93 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -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())) |
