Skip to content

Conversation

@BennoLossin
Copy link
Contributor

@BennoLossin BennoLossin commented Feb 6, 2026

This is implementing the lint described in #151583. The plan is to run a crater run on this lint before deciding on how to add this to the language.

An important detail that I noticed when implementing was that it must recursively look at the target type. Since dereferencing to a concrete type that then derefs to a generic has the same problem.

@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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 6, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@BennoLossin

This comment was marked as resolved.

@rustbot
Copy link
Collaborator

rustbot commented Feb 6, 2026

Error: Label needs-crater can only be set by Rust team members

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip.

@BennoLossin

This comment was marked as duplicate.

@rustbot
Copy link
Collaborator

rustbot commented Feb 6, 2026

Error: Label needs-crater can only be set by Rust team members

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip.

@BennoLossin
Copy link
Contributor Author

@rustbot label +I-lang-nominated

@rustbot rustbot added the I-lang-nominated Nominated for discussion during a lang team meeting. label Feb 6, 2026
@rust-log-analyzer
Copy link
Collaborator

The job pr-check-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
REPOSITORY                                   TAG       IMAGE ID       CREATED      SIZE
ghcr.io/dependabot/dependabot-updater-core   latest    b72a662c47e3   6 days ago   790MB
=> Removing docker images...
Deleted Images:
untagged: ghcr.io/dependabot/dependabot-updater-core:latest
untagged: ghcr.io/dependabot/dependabot-updater-core@sha256:57ef9cc45f72cc4258ee1baa8243bc3cd55c0a0e570b6768c37346247be35f0d
deleted: sha256:b72a662c47e31df2e7bf59368b2b83be239f02a1baa721393717711a1a719df9
deleted: sha256:3e13ccd80f19769f39008cfc6549938e1ea4905f47b028c1df2dd6085191386c
deleted: sha256:842807995a512b2c5a9b241a3aecdbe79af6b0642d96fa5460cfcf0c9d8be295
deleted: sha256:0f9074b9f46f4570eb7cb4b65fcb3c3d909f9b1d14ca66b30508117b6deda303
deleted: sha256:2ca99cb9251d19157c56b5d91c8961bb4b35196a5ca9b4ffdccbf24abbfe2a5f
---
    |
124 |     pub fn as_ref(&self) -> InternedRef<'_, T> {
    |                   ^^^^^
...
188 | impl<T: Internable> Deref for Interned<T> {
    | ----------------------------------------- trait implemented here
189 |     type Target = T;
    |     ----------- with `Target` set here
    |
    = note: `#[warn(inherent_method_on_receiver)]` on by default

warning: inherent methods on types that implement `Deref` or `Receiver` shadow methods of their target
   --> src/tools/rust-analyzer/crates/intern/src/intern.rs:223:19
    |
223 |     pub fn as_raw(self) -> *const T {
    |                   ^^^^
...
300 | impl<T> Deref for InternedRef<'_, T> {
    | ------------------------------------ trait implemented here
301 |     type Target = T;
    |     ----------- with `Target` set here

warning: inherent methods on types that implement `Deref` or `Receiver` shadow methods of their target
   --> src/tools/rust-analyzer/crates/intern/src/intern.rs:238:21
    |
238 |     pub fn to_owned(self) -> Interned<T> {
    |                     ^^^^
...
300 | impl<T> Deref for InternedRef<'_, T> {
    | ------------------------------------ trait implemented here
301 |     type Target = T;
    |     ----------- with `Target` set here

warning: inherent methods on types that implement `Deref` or `Receiver` shadow methods of their target
   --> src/tools/rust-analyzer/crates/intern/src/intern.rs:243:16
    |
243 |     pub fn get(self) -> &'a T {
    |                ^^^^
...
300 | impl<T> Deref for InternedRef<'_, T> {
    | ------------------------------------ trait implemented here
301 |     type Target = T;
    |     ----------- with `Target` set here

warning: inherent methods on types that implement `Deref` or `Receiver` shadow methods of their target
   --> src/tools/rust-analyzer/crates/intern/src/intern.rs:252:38
    |
252 |     pub unsafe fn decrement_refcount(self) {
    |                                      ^^^^
...
300 | impl<T> Deref for InternedRef<'_, T> {
    | ------------------------------------ trait implemented here
301 |     type Target = T;
    |     ----------- with `Target` set here

warning: inherent methods on types that implement `Deref` or `Receiver` shadow methods of their target
   --> src/tools/rust-analyzer/crates/intern/src/intern.rs:267:32
    |
267 |     pub fn change_lifetime<'b>(self) -> InternedRef<'b, T> {
    |                                ^^^^
...
300 | impl<T> Deref for InternedRef<'_, T> {
    | ------------------------------------ trait implemented here
301 |     type Target = T;
    |     ----------- with `Target` set here

[RUSTC-TIMING] semver test:false 0.427
[RUSTC-TIMING] expect_test test:false 0.295

let (impl_id, target_id) = find_impl_and_target_id(tcx, deref_trait, ty);
return Some(CheckResult { impl_plus_target: vec![(impl_id, target_id)] });
}
if let Some(mut result) = check(tcx, infcx, typing_env, target_ty) {
Copy link
Member

Choose a reason for hiding this comment

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

This feels like you could end up in an infinite loop, e.g.

impl Deref for StructA {
  type Target = StructB;
}
impl Deref for StructB {
  type Target = StructA;
}

That doesn't matter for the crater run tho

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could use recursion limit: tcx.recursion_limit().value_within_limit(..)

@Nadrieril
Copy link
Member

@bors try

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Feb 6, 2026
@Darksonn Darksonn removed the I-lang-nominated Nominated for discussion during a lang team meeting. label Feb 6, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 6, 2026

☀️ Try build successful (CI)
Build commit: 7b3da91 (7b3da9103634dffd4f4365cfd8642427c781d99f, parent: 035b01b794602d5861daa43ac792f372f8981ed7)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants