needless_borrow: do not contradict dangerous_implicit_autorefs - #14810
Merged
Conversation
Collaborator
Member
Author
|
@Urgau |
samueltardieu
force-pushed
the
issue-14743
branch
2 times, most recently
from
May 15, 2025 12:47
39ee603 to
969e514
Compare
Member
Author
|
@rustbot note Beta nomination for 1.88 The |
blyxyas
requested changes
May 22, 2025
blyxyas
left a comment
Member
There was a problem hiding this comment.
LGTM, thanks! ❤️ Just what I assume is a typo.
| ); | ||
| }, | ||
| State::DerefedBorrow(state) => { | ||
| // Do not suggest removing a non-mandatory `&` in `&*rawptr` in an `unside` context, |
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
force-pushed
the
issue-14743
branch
from
May 23, 2025 09:12
969e514 to
0a059d9
Compare
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 -->
Member
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
skiefucker
added a commit
to skiefucker/rust-clippy
that referenced
this pull request
Jul 19, 2026
…orefs` Add Logic: If the innermost expression of the borrow is a deref of a raw pointer, and the borrow after multiple Index/Field operations, is used to call a method with `#[rustc_no_implicit_autorefs]`, skip the lint. Remove the narrow `&*raw_ptr` pattern check added in PR rust-lang#14810. The old guard only matched the literal `&*raw_ptr`. Add Test `issue_17414` to `tests/ui/needless_borrow.rs` covering: - `(&(*tuple_slice).field).method()` — the reported case - `(&*raw_slice).len()` and `(&*raw_slice)[idx]` — direct deref - nested tuple field access through a raw pointer - array indexing via `Index::index` on a raw pointer - trait method dispatch (`dyn T`) through a raw pointer Problems Left: - Index Op of slice/array: `(*slice)[0]` can compile, but index method of Index trait has `#[rustc_no_implicit_autorefs]`. (See codes in tests/ui/needless_borrow.rs) - Is there any other operation between deref raw pointer and method with #[rustc_no_implicit_autorefs]? changelog: [`needless_borrow`]: do not contradict `dangerous_implicit_autorefs`.
skiefucker
added a commit
to skiefucker/rust-clippy
that referenced
this pull request
Jul 19, 2026
…orefs` Add Logic: If the innermost expression of the borrow is a deref of a raw pointer, and the borrow after multiple Index/Field operations, is used to call a method with `#[rustc_no_implicit_autorefs]`, skip the lint. Remove the narrow `&*raw_ptr` pattern check added in PR rust-lang#14810. The old guard only matched the literal `&*raw_ptr`. Add Test `issue_17414` to `tests/ui/needless_borrow.rs` covering: - `(&(*tuple_slice).field).method()` — the reported case - `(&*raw_slice).len()` and `(&*raw_slice)[idx]` — direct deref - nested tuple field access through a raw pointer - array indexing via `Index::index` on a raw pointer - trait method dispatch (`dyn T`) through a raw pointer Problems Left: - Index Op of slice/array: `(*slice)[0]` can compile, but index method of Index trait has `#[rustc_no_implicit_autorefs]`. (See codes in tests/ui/needless_borrow.rs) - Is there any other operation between deref raw pointer and method with #[rustc_no_implicit_autorefs]? changelog: [`needless_borrow`]: do not contradict `dangerous_implicit_autorefs`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rust 1.88 introduces the
dangerous_implicit_autorefslint which warns about using implicit autorefs on a place obtained from a raw pointer, as this may create aliasing issues.Prevent
clippy::needless_borrowfrom 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'sdangerous_implicit_autorefslint even though the refererences are not mandatory@rustbot label +beta-nominated
Summary Notes
Generated by triagebot, see help for how to add more