Skip to content

needless_borrow: do not contradict dangerous_implicit_autorefs #14810

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
May 23, 2025

Conversation

samueltardieu
Copy link
Contributor

@samueltardieu samueltardieu commented May 15, 2025

Rust 1.88 introduces the dangerous_implicit_autorefs lint which warns about using implicit autorefs on a place obtained from a raw pointer, as this may create aliasing issues.

Prevent clippy::needless_borrow from triggering in this case, by disabling the lint when taking a reference on a raw pointer dereference. There might be a better way for doing this in the long run with a finer way of distinguish the problematic cases, but this will prevent Clippy from contradicting the compiler in the meantime.

Fixes #14743

changelog: [needless_borrow]: do not contradict the compiler's dangerous_implicit_autorefs lint even though the refererences are not mandatory

@rustbot label +beta-nominated

Summary Notes

Generated by triagebot, see help for how to add more

@rustbot
Copy link
Collaborator

rustbot commented May 15, 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 S-waiting-on-review Status: Awaiting review from the assignee but also interested parties beta-nominated Nominated for backporting to the compiler in the beta channel. labels May 15, 2025
@samueltardieu
Copy link
Contributor Author

samueltardieu commented May 15, 2025

@Urgau Any other cases you might be thinking about that would not be covered here? After our discussion, I switched to ignoring references on dereferences of raw pointers altogether.

@samueltardieu samueltardieu force-pushed the issue-14743 branch 2 times, most recently from 39ee603 to 969e514 Compare May 15, 2025 12:47
@samueltardieu
Copy link
Contributor Author

samueltardieu commented May 15, 2025

@rustbot note Beta nomination for 1.88

The dangerous_implicit_autorefs compiler lint that we contradict has already entered beta 1.88. We should also target the same version to avoid lints going back and forth.

Copy link
Member

@blyxyas blyxyas 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! ❤️ Just what I assume is a typo.

@@ -997,6 +997,15 @@ fn report<'tcx>(
);
},
State::DerefedBorrow(state) => {
// Do not suggest removing a non-mandatory `&` in `&*rawptr` in an `unside` context,
Copy link
Member

Choose a reason for hiding this comment

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

Probably a "unsafe" typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, fixed!

@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 22, 2025
Rust 1.88 introduces the `dangerous_implicit_autorefs` lint which warns
about using implicit autorefs on a place obtained from a raw pointer,
as this may create aliasing issues.

Prevent `clippy::needless_borrow` from triggering in this case,
by disabling the lint when taking a reference on a raw pointer
dereference. There might be a better way for doing this in the long run
with a finer way of distinguish the problematic cases, but this will
prevent Clippy from contradicting the compiler in the meantime.
@samueltardieu samueltardieu requested a review from blyxyas May 23, 2025 09:13
@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 23, 2025
Copy link
Member

@blyxyas blyxyas 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! ❤️

@blyxyas blyxyas added this pull request to the merge queue May 23, 2025
Merged via the queue into rust-lang:master with commit 7ab910f May 23, 2025
11 checks passed
@samueltardieu samueltardieu deleted the issue-14743 branch May 23, 2025 21:20
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. 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.

dangerous_implicit_autorefs lint suggestion triggers clippy::needless_borrow
3 participants