Skip to content

Make lint span smaller for needless return #14790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

barun511
Copy link

@barun511 barun511 commented May 12, 2025

Fixes #14750 by reducing the lint span for needless_return.

changelog: [needless_return]: Lint span no longer wraps to previous line

@rustbot
Copy link
Collaborator

rustbot commented May 12, 2025

r? @dswij

rustbot has assigned @dswij.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label May 12, 2025
@barun511 barun511 force-pushed the parruck/fix-lint-span branch from ffddadf to 73a19a0 Compare May 12, 2025 21:59
@@ -448,6 +455,7 @@ fn check_final_expr<'tcx>(

fn emit_return_lint(
cx: &LateContext<'_>,
lint_span: Span,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not super confident that this is the way we want to go - but it seemed like the lint_span and the suggestion_span had to diverge here. Happy to take suggestions!

@@ -84,14 +84,14 @@ fn test_macro_call() -> i32 {
}

fn test_void_fun() {
//~^^ needless_return
//~^ needless_return
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to change these because the lint span now starts on the immediate previous line, not the one before

|
LL | fn test_void_fun() {
| _____________________^
LL | | return;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely convinced that we shouldn't extend this span upto at least the full line?

@@ -608,10 +590,10 @@ LL + let _ = 42;
|

error: unneeded `return` statement
--> tests/ui/needless_return.rs:371:20
--> tests/ui/needless_return.rs:371:21
|
LL | let _ = 42; return;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example in this instance I think the previous span was slightly better. But as I don't have high conviction, leaving as is for now and we can address

@barun511
Copy link
Author

Still have some tests to fix - but I'll get to those once there's alignment on approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Needlessly Verbose Replacement Suggestion for needless_return
3 participants