Skip to content

unnecessary_wraps: do not include the whole body in the lint span #14777

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

samueltardieu
Copy link
Contributor

@samueltardieu samueltardieu commented May 10, 2025

Using the function declaration, by stripping the body, is enough to convey the lint message.

changelog: [unnecessary_wraps]: do not include the whole body in the lint span

Closes #14773

@rustbot
Copy link
Collaborator

rustbot commented May 10, 2025

r? @blyxyas

rustbot has assigned @blyxyas.
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 10, 2025
@blyxyas
Copy link
Member

blyxyas commented May 14, 2025

I'm actually not sure about this one, only spanning the signature imo signifies that the issue is with the function signature, and really the too of the issue is with the returned expression.

Isn't there an option to like annotate several unconnected places with span_lint_then?

Something like:

error: the result is unnecessarily wrapped in an Option
  |
LL| fn my_func(args: &[usize]) -> Option<usize> {
  |                               ^^^^^^^^^^^^^
note: the only returns are from `Some` variants
 -> `return Some(ret)`
 -> `x.unwrap_or_else(|| Some(y))`
 -> (...the other branch ends)

Although each option should probably be truncated to guard against really big chains of maps and and_thens

@samueltardieu
Copy link
Contributor Author

I'm actually not sure about this one, only spanning the signature imo signifies that the issue is with the function signature

That was the intent: if we assume the code is correct, then the issue is really with the function signature, which requires an Option or Result while it probably shouldn't. We wouldn't want to suggest that some code path would need to return None if this is not needed.

Though I agree that a note talking about only Some or Ok being returned would be definitely useful to add here. I'll see if pointing at them is doable without spamming the output.

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels May 14, 2025
@rustbot
Copy link
Collaborator

rustbot commented May 14, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@samueltardieu
Copy link
Contributor Author

Done. Example:

error: this function's return value is unnecessarily wrapped by `Option`
  --> tests/ui/unnecessary_wraps.rs:86:5
   |
LL |     fn func12() -> Option<i32> {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: remove `Option` from the return type...
   |
LL -     fn func12() -> Option<i32> {
LL +     fn func12() -> i32 {
   |
help: ...and then remove the surrounding `Some()` from returning expressions
   |
LL -         Some(1)
LL +         1

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels May 15, 2025
Using the function declaration, by stripping the body, is enough to
convey the lint message.
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.

unnecessary_wraps: Annoyingly large span
4 participants