Skip to content

Consider deref'ed argument as non-temporary #15172

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

Merged
merged 1 commit into from
Jun 30, 2025

Conversation

samueltardieu
Copy link
Contributor

@samueltardieu samueltardieu commented Jun 29, 2025

If there are more than one dereference (there is one corresponding matched with a borrow in any case), consider that the argument might point to a place expression, which is the safest choice.

Also, use an appropriate number of dereferences in suggestions involving arguments using themselves multiple dereferences.

Fixes #15166

changelog: [swap_with_temporary]: fix false positive leading to different semantics being suggested, and use the right number of dereferences in suggestion

r? y21

Summary Notes

Managed by @rustbot—see help for details

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jun 29, 2025
@samueltardieu
Copy link
Contributor Author

@rustbot label +I-suggestion-causes-bug +beta-nominated
@rustbot note beta-nomination

Nominating for beta (1.89) since the lint and the issue with I-suggestion-causes-bug have been recently introduced in 1.88, it would be great not to keep this for long. If a 1.88.1 issue is released, it could also be useful to try to let this in.

@rustbot rustbot added beta-nominated Nominated for backporting to the compiler in the beta channel. I-suggestion-causes-bug Issue: The suggestion compiles but changes the code to behave in an unintended way labels Jun 29, 2025
If there are more than one dereference (there is one corresponding
matched with a borrow in any case), consider that the argument might
point to a place expression, which is the safest choice.

Also, use an appropriate number of dereferences in suggestions involving
arguments using themselves multiple dereferences.
Copy link
Member

@y21 y21 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@y21 y21 added this pull request to the merge queue Jun 30, 2025
Merged via the queue into rust-lang:master with commit 936baca Jun 30, 2025
11 checks passed
@samueltardieu samueltardieu deleted the issue-15166 branch June 30, 2025 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-nominated Nominated for backporting to the compiler in the beta channel. I-suggestion-causes-bug Issue: The suggestion compiles but changes the code to behave in an unintended way 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.

swap_with_temporary mis-detects MutexGuards as temporaries
3 participants