Skip to content

Conversation

@samueltardieu
Copy link
Member

@samueltardieu samueltardieu commented Dec 20, 2025

Rather than trying to reconstruct the reference type without the mut, remove the mut itself so that user-inserted lifetime information is preserved.

The message has been changed from "consider changing to [NON-MUT REF]" to "remove this mut"

changelog: [needless_pass_by_ref_mut]: preserve user-provided lifetime information

Fixes #16267

Rather than trying to reconstruct the reference type without the `mut`,
remove the `mut` itself so that user-inserted lifetime information is
preserved.

The message has been changed from "consider changing to [NON-MUT REF]"
to "remove this `mut`"
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Dec 20, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 20, 2025

r? @Jarcho

rustbot has assigned @Jarcho.
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

@github-actions
Copy link

github-actions bot commented Dec 20, 2025

Lintcheck changes for dcb19a0

Lint Added Removed Changed
clippy::needless_pass_by_ref_mut 0 0 169

This comment will be updated if you push new changes

sp,
"consider changing to".to_string(),
format!("&{}", snippet(cx, cx.tcx.hir_span(inner_ty.ty.hir_id), "_"),),
mut_span,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason not to use this as the lint span?

Copy link
Member Author

Choose a reason for hiding this comment

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

Given the existing message ("this argument is a mutable reference, but not used mutably") it makes sense to point to the whole argument when linting.

I'll change this to "this parameter is a mutable reference but is not used mutably" which is more correct though.

Tell me if you want me to change the span.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine with not dealing with this now. I have a general issue with how we use error spans that are way larger than what's needed to communicate the problem, but it's also unrelated to fixing the suggestion.

Copy link
Contributor

@Jarcho Jarcho left a comment

Choose a reason for hiding this comment

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

@Jarcho Jarcho added this pull request to the merge queue Dec 24, 2025
Merged via the queue into rust-lang:master with commit 31ea246 Dec 24, 2025
11 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Dec 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FP needless-pass-by-ref-mut with lifetimes

3 participants