Skip to content

Fix invalid mut T suggestion for &mut T in missing lifetime error#151530

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
reddevilmidzy:e0106
Feb 18, 2026
Merged

Fix invalid mut T suggestion for &mut T in missing lifetime error#151530
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
reddevilmidzy:e0106

Conversation

@reddevilmidzy
Copy link
Member

@reddevilmidzy reddevilmidzy commented Jan 23, 2026

close: #150077

When suggesting to return an owned value instead of a borrowed one, the diagnostic was only removing & instead of &mut , resulting in invalid syntax like mut T. This PR fixes the span calculation to properly cover the entire &mut prefix.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 23, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@reddevilmidzy reddevilmidzy marked this pull request as ready for review February 1, 2026 05:33
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 1, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Feb 1, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 1, 2026

r? @mati865

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

@mati865
Copy link
Member

mati865 commented Feb 3, 2026

@rustbot reroll

@rustbot rustbot assigned fee1-dead and unassigned mati865 Feb 3, 2026
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a test for &mut str?

Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to use let chains if possible here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can you add a test for &mut str?

Okay! In the existing code, &mut str was suggesting str.
sugg_is_str_to_string was handling only the case for the return type, so I fixed this part.

Would be nice to use let chains if possible here.

cool! I've applied your suggestion

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 17, 2026
@rust-log-analyzer

This comment has been minimized.

@reddevilmidzy
Copy link
Member Author

@bors squash

* Find ref prefix span for owned suggestions
* Improve missing lifetime suggestions for `&mut str`
@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 17, 2026

🔨 2 commits were squashed into e0d9d47.

@reddevilmidzy
Copy link
Member Author

@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 (such as code changes or more information) from the author. labels Feb 17, 2026
@fee1-dead
Copy link
Member

LGTM, thanks

@bors r+ rollup

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 17, 2026

📌 Commit e0d9d47 has been approved by fee1-dead

It is now in the queue for this repository.

@rust-bors rust-bors bot added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Feb 17, 2026
@rust-bors rust-bors bot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 17, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Feb 18, 2026
Fix invalid `mut T` suggestion for `&mut T` in missing lifetime error

close: rust-lang#150077

When suggesting to return an owned value instead of a borrowed one, the diagnostic was only removing `&` instead of `&mut `, resulting in invalid syntax like `mut T`. This PR fixes the span calculation to properly cover the entire `&mut ` prefix.
jhpratt added a commit to jhpratt/rust that referenced this pull request Feb 18, 2026
Fix invalid `mut T` suggestion for `&mut T` in missing lifetime error

close: rust-lang#150077

When suggesting to return an owned value instead of a borrowed one, the diagnostic was only removing `&` instead of `&mut `, resulting in invalid syntax like `mut T`. This PR fixes the span calculation to properly cover the entire `&mut ` prefix.
jhpratt added a commit to jhpratt/rust that referenced this pull request Feb 18, 2026
Fix invalid `mut T` suggestion for `&mut T` in missing lifetime error

close: rust-lang#150077

When suggesting to return an owned value instead of a borrowed one, the diagnostic was only removing `&` instead of `&mut `, resulting in invalid syntax like `mut T`. This PR fixes the span calculation to properly cover the entire `&mut ` prefix.
rust-bors bot pushed a commit that referenced this pull request Feb 18, 2026
Rollup of 19 pull requests

Successful merges:

 - #145399 (Unify wording of resolve error)
 - #150473 (tail calls: fix copying non-scalar arguments to callee)
 - #152637 (Add a note about elided lifetime)
 - #152657 (std: move `exit` out of PAL)
 - #152729 (compiler: Don't mark `SingleUseConsts` MIR pass as "required for soundness")
 - #152753 (remove the explicit error for old `rental` versions)
 - #152758 (Remove ShallowInitBox.)
 - #151530 (Fix invalid `mut T` suggestion for `&mut T` in missing lifetime error)
 - #152179 (Add documentation note about signed overflow direction)
 - #152474 (Implement opt-bisect-limit for MIR)
 - #152509 (tests/ui/test-attrs: add annotations for reference rules)
 - #152672 (std: use libc version of `_NSGetArgc`/`_NSGetArgv`)
 - #152711 (resolve: Disable an assert that no longer holds)
 - #152732 (add regression test for 147958)
 - #152745 (Fix ICE in `suggest_param_env_shadowing` with incompatible args)
 - #152749 (make `rustc_allow_const_fn_unstable` an actual `rustc_attrs` attribute)
 - #152756 (Miri: recursive validity: also recurse into Boxes)
 - #152770 (carryless_mul: mention the base)
 - #152778 (Update tracking issue number for final_associated_functions)
rust-bors bot pushed a commit that referenced this pull request Feb 18, 2026
Rollup of 20 pull requests

Successful merges:

 - #145399 (Unify wording of resolve error)
 - #150473 (tail calls: fix copying non-scalar arguments to callee)
 - #152637 (Add a note about elided lifetime)
 - #152729 (compiler: Don't mark `SingleUseConsts` MIR pass as "required for soundness")
 - #152751 (Rename dep node "fingerprints" to distinguish key and value hashes)
 - #152753 (remove the explicit error for old `rental` versions)
 - #152758 (Remove ShallowInitBox.)
 - #151530 (Fix invalid `mut T` suggestion for `&mut T` in missing lifetime error)
 - #152179 (Add documentation note about signed overflow direction)
 - #152474 (Implement opt-bisect-limit for MIR)
 - #152509 (tests/ui/test-attrs: add annotations for reference rules)
 - #152672 (std: use libc version of `_NSGetArgc`/`_NSGetArgv`)
 - #152711 (resolve: Disable an assert that no longer holds)
 - #152725 (Rework explanation of CLI lint level flags)
 - #152732 (add regression test for 147958)
 - #152745 (Fix ICE in `suggest_param_env_shadowing` with incompatible args)
 - #152749 (make `rustc_allow_const_fn_unstable` an actual `rustc_attrs` attribute)
 - #152756 (Miri: recursive validity: also recurse into Boxes)
 - #152770 (carryless_mul: mention the base)
 - #152778 (Update tracking issue number for final_associated_functions)
@rust-bors rust-bors bot merged commit a544b5d into rust-lang:main Feb 18, 2026
11 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Feb 18, 2026
rust-timer added a commit that referenced this pull request Feb 18, 2026
Rollup merge of #151530 - reddevilmidzy:e0106, r=fee1-dead

Fix invalid `mut T` suggestion for `&mut T` in missing lifetime error

close: #150077

When suggesting to return an owned value instead of a borrowed one, the diagnostic was only removing `&` instead of `&mut `, resulting in invalid syntax like `mut T`. This PR fixes the span calculation to properly cover the entire `&mut ` prefix.
@reddevilmidzy reddevilmidzy deleted the e0106 branch February 19, 2026 00:12
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Feb 19, 2026
Rollup of 20 pull requests

Successful merges:

 - rust-lang/rust#145399 (Unify wording of resolve error)
 - rust-lang/rust#150473 (tail calls: fix copying non-scalar arguments to callee)
 - rust-lang/rust#152637 (Add a note about elided lifetime)
 - rust-lang/rust#152729 (compiler: Don't mark `SingleUseConsts` MIR pass as "required for soundness")
 - rust-lang/rust#152751 (Rename dep node "fingerprints" to distinguish key and value hashes)
 - rust-lang/rust#152753 (remove the explicit error for old `rental` versions)
 - rust-lang/rust#152758 (Remove ShallowInitBox.)
 - rust-lang/rust#151530 (Fix invalid `mut T` suggestion for `&mut T` in missing lifetime error)
 - rust-lang/rust#152179 (Add documentation note about signed overflow direction)
 - rust-lang/rust#152474 (Implement opt-bisect-limit for MIR)
 - rust-lang/rust#152509 (tests/ui/test-attrs: add annotations for reference rules)
 - rust-lang/rust#152672 (std: use libc version of `_NSGetArgc`/`_NSGetArgv`)
 - rust-lang/rust#152711 (resolve: Disable an assert that no longer holds)
 - rust-lang/rust#152725 (Rework explanation of CLI lint level flags)
 - rust-lang/rust#152732 (add regression test for 147958)
 - rust-lang/rust#152745 (Fix ICE in `suggest_param_env_shadowing` with incompatible args)
 - rust-lang/rust#152749 (make `rustc_allow_const_fn_unstable` an actual `rustc_attrs` attribute)
 - rust-lang/rust#152756 (Miri: recursive validity: also recurse into Boxes)
 - rust-lang/rust#152770 (carryless_mul: mention the base)
 - rust-lang/rust#152778 (Update tracking issue number for final_associated_functions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

E0106: help diagonistic suggests invalid syntax mut T

5 participants

Comments