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
@flip1995 flip1995 added beta-accepted Accepted for backporting to the compiler in the beta channel. and removed beta-nominated Nominated for backporting to the compiler in the beta channel. labels Jun 19, 2025
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jun 19, 2025
…ust-lang#14810)

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 rust-lang/rust-clippy#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

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_SUMMARY_START -->

### Summary Notes

- [Beta nomination for
1.88](rust-lang/rust-clippy#14810 (comment))
by [samueltardieu](https://github.com/samueltardieu)

Generated by triagebot, see
[help](https://forge.rust-lang.org/triagebot/note.html) for how to add
more
<!--
TRIAGEBOT_SUMMARY_DATA_START$${"entries_by_url":{"https://github.com/rust-lang/rust-clippy/pull/14810#issuecomment-2883753957":{"title":"Beta
nomination for
1.88","comment_url":"https://github.com/rust-lang/rust-clippy/pull/14810#issuecomment-2883753957","author":"samueltardieu"}}}$$TRIAGEBOT_SUMMARY_DATA_END
-->

<!-- TRIAGEBOT_SUMMARY_END -->
<!-- TRIAGEBOT_END -->
@flip1995
Copy link
Member

rust-lang/rust#142725

flip1995 pushed a commit to flip1995/rust that referenced this pull request Jun 19, 2025
…ust-lang#14810)

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 rust-lang/rust-clippy#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

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_SUMMARY_START -->

### Summary Notes

- [Beta nomination for
1.88](rust-lang/rust-clippy#14810 (comment))
by [samueltardieu](https://github.com/samueltardieu)

Generated by triagebot, see
[help](https://forge.rust-lang.org/triagebot/note.html) for how to add
more
<!--
TRIAGEBOT_SUMMARY_DATA_START$${"entries_by_url":{"https://github.com/rust-lang/rust-clippy/pull/14810#issuecomment-2883753957":{"title":"Beta
nomination for
1.88","comment_url":"https://github.com/rust-lang/rust-clippy/pull/14810#issuecomment-2883753957","author":"samueltardieu"}}}$$TRIAGEBOT_SUMMARY_DATA_END
-->

<!-- TRIAGEBOT_SUMMARY_END -->
<!-- TRIAGEBOT_END -->
cuviper pushed a commit to cuviper/rust that referenced this pull request Jun 20, 2025
…ust-lang#14810)

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 rust-lang/rust-clippy#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

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_SUMMARY_START -->

### Summary Notes

- [Beta nomination for
1.88](rust-lang/rust-clippy#14810 (comment))
by [samueltardieu](https://github.com/samueltardieu)

Generated by triagebot, see
[help](https://forge.rust-lang.org/triagebot/note.html) for how to add
more
<!--
TRIAGEBOT_SUMMARY_DATA_START$${"entries_by_url":{"https://github.com/rust-lang/rust-clippy/pull/14810#issuecomment-2883753957":{"title":"Beta
nomination for
1.88","comment_url":"https://github.com/rust-lang/rust-clippy/pull/14810#issuecomment-2883753957","author":"samueltardieu"}}}$$TRIAGEBOT_SUMMARY_DATA_END
-->

<!-- TRIAGEBOT_SUMMARY_END -->
<!-- TRIAGEBOT_END -->
cuviper pushed a commit to cuviper/rust that referenced this pull request Jun 20, 2025
…ust-lang/rust-clippy#14810)

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 rust-lang/rust-clippy#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

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_SUMMARY_START -->


- [Beta nomination for
1.88](rust-lang/rust-clippy#14810 (comment))
by [samueltardieu](https://github.com/samueltardieu)

Generated by triagebot, see
[help](https://forge.rust-lang.org/triagebot/note.html) for how to add
more
<!--
TRIAGEBOT_SUMMARY_DATA_START$${"entries_by_url":{"https://github.com/rust-lang/rust-clippy/pull/14810#issuecomment-2883753957":{"title":"Beta
nomination for
1.88","comment_url":"https://github.com/rust-lang/rust-clippy/pull/14810#issuecomment-2883753957","author":"samueltardieu"}}}$$TRIAGEBOT_SUMMARY_DATA_END
-->

<!-- TRIAGEBOT_SUMMARY_END -->
<!-- TRIAGEBOT_END -->
bors added a commit to rust-lang/rust that referenced this pull request Jun 20, 2025
[beta] backports

- Make the assertion in `Ident::new` debug-only. #140880
- Avoid creating an empty identifer in `Symbol::to_ident_string`. #141318
- Backport rust-lang/stdarch#1818 for 1.88 #142694
- [beta] Clippy backport #142725
    - ICE:
        - rust-lang/rust-clippy#14776
    - Lint contradictions:
        - rust-lang/rust-clippy#14703
        - rust-lang/rust-clippy#14810
    - Smaller (in LoC changes) fixes:
        - rust-lang/rust-clippy#14733
        - rust-lang/rust-clippy#14730

r? cuviper
rust-bors bot added a commit to rust-lang/rust that referenced this pull request Jun 20, 2025
[beta] backports

- Make the assertion in `Ident::new` debug-only. #140880
- Avoid creating an empty identifer in `Symbol::to_ident_string`. #141318
- Backport rust-lang/stdarch#1818 for 1.88 #142694
- [beta] Clippy backport #142725
    - ICE:
        - rust-lang/rust-clippy#14776
    - Lint contradictions:
        - rust-lang/rust-clippy#14703
        - rust-lang/rust-clippy#14810
    - Smaller (in LoC changes) fixes:
        - rust-lang/rust-clippy#14733
        - rust-lang/rust-clippy#14730

r? cuviper

try-job: x86_64-msvc-ext2
bors added a commit to rust-lang/rust that referenced this pull request Jun 21, 2025
[beta] backports

- Make the assertion in `Ident::new` debug-only. #140880
- Avoid creating an empty identifer in `Symbol::to_ident_string`. #141318
- Backport rust-lang/stdarch#1818 for 1.88 #142694
- [beta] Clippy backport #142725
    - ICE:
        - rust-lang/rust-clippy#14776
    - Lint contradictions:
        - rust-lang/rust-clippy#14703
        - rust-lang/rust-clippy#14810
    - Smaller (in LoC changes) fixes:
        - rust-lang/rust-clippy#14733
        - rust-lang/rust-clippy#14730
-  [win][ci] Update LLVM toolchain used to build LLVM to 20 #140757

r? cuviper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-accepted Accepted 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
4 participants