Skip to content

Conversation

@mu001999
Copy link
Contributor

@mu001999 mu001999 commented Jul 18, 2025

https://github.com/rust-lang/rust/blob/master/compiler/rustc_passes/src/dead.rs#L360-L361 won't insert assoc items into the live set, so that impl items cannot be marked live.

This PR lets impls and impl items can inherit lint levels of the corresponding traits and trait items.

Fixes #144060

r? @petrochenkov

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 18, 2025
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

This behavior seems really non-local and pretty broad. #[allow(dead_code)] on a trait definition suppresses all dead code warnings in all impls with this change?

@mu001999 mu001999 force-pushed the dead-code/allow-trait branch from 7eba1f1 to 7a9e2e2 Compare July 19, 2025 01:34
@mu001999
Copy link
Contributor Author

#[allow(dead_code)] on a trait definition suppresses all dead code warnings in all impls with this change?

@compiler-errors yes, and I think this makes sense. We would have only one trait definition but many impls, letting #[allow(dead_code)] on traits propagate to impls is convenient. Otherwise we need to add #[allow(dead_code)] also on each impls which use unused items.

@petrochenkov
Copy link
Contributor

r? @compiler-errors

@petrochenkov
Copy link
Contributor

Hmm, why did rustbot assign it to me again?
I'll just block this on #144863 now.
@rustbot blocked

@rustbot rustbot added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 4, 2025
@mu001999
Copy link
Contributor Author

mu001999 commented Aug 4, 2025

Hmm, why did rustbot assign it to me again?

I tried reassigning, but rustbot didn’t respond after waiting a while, so I deleted the comment. 😂

@cjgillot cjgillot self-assigned this Aug 4, 2025
@petrochenkov petrochenkov removed their assignment Aug 5, 2025
@bors
Copy link
Collaborator

bors commented Aug 5, 2025

☔ The latest upstream changes (presumably #144863) made this pull request unmergeable. Please resolve the merge conflicts.

@mu001999 mu001999 force-pushed the dead-code/allow-trait branch from 7a9e2e2 to c1be949 Compare August 7, 2025 16:34
@mu001999
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Aug 10, 2025
@tgross35
Copy link
Contributor

@cjgillot gentle ping for a review here

@wesleywiser wesleywiser added the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Sep 25, 2025
@wesleywiser
Copy link
Member

Nominated the issue for lang team discussion, let's see what they think before merging.

@mu001999
Copy link
Contributor Author

mu001999 commented Sep 25, 2025

oh, I missed the non-local in the note from @compiler-errors

and if the trait is non-local, the dead-code lint level won't spread to the local impls. cc @wesleywiser

we only care about local traits, see https://github.com/rust-lang/rust/pull/144113/files#diff-719b4f36bbbf3b3bf48683429408f5d27e5633f70c1144a93554bd536d5bf655R786

@traviscross traviscross added T-lang Relevant to the language team I-lang-nominated Nominated for discussion during a lang team meeting. labels Oct 8, 2025
@traviscross traviscross added P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. labels Oct 8, 2025
@Nadrieril Nadrieril changed the title Impls and impl items inherit lint levels of the corresponding traits and trait items Impls and impl items inherit dead_code lint level of the corresponding traits and trait items Oct 8, 2025
@tmandry
Copy link
Member

tmandry commented Oct 8, 2025

@rfcbot reviewed

@traviscross
Copy link
Contributor

How does what's proposed in this PR compare with @nikomatsakis' model in #144060 (comment)?

@mu001999
Copy link
Contributor Author

How does what's proposed in this PR compare with @nikomatsakis' model in #144060 (comment)?

For examples given by @nikomatsakis:

pub trait Foo { }
impl Foo for u32 { }

struct PrivateType;
impl Foo for PrivateType { } // <-- warns as dead, even though Foo is public

struct AnotherPrivateType;
impl Foo for AnotherPrivateType; { } // <-- warns as dead, even though Foo is public

works like before.

#[allow(dead_code)]
pub trait Foo { }
impl Foo for u32 { }

struct PrivateType;
impl Foo for PrivateType { } // <-- no warning, trait is "allowed"

struct AnotherPrivateType;
impl Foo for AnotherPrivateType; { } // <-- no warning, trait is "allowed"

This one is related to this PR. And it will work as expected after this PR.

pub trait Foo { }
impl Foo for u32 { }

struct PrivateType;
#[allow(dead_code)]
impl Foo for PrivateType { } // <-- no warning, impl is allowed

struct AnotherPrivateType;
impl Foo for AnotherPrivateType; { } // <-- warns as dead, even though Foo is public

works like before.

@traviscross
Copy link
Contributor

Thanks. OK.

@rfcbot reviewed

@rust-rfcbot rust-rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Oct 15, 2025
@rust-rfcbot
Copy link
Collaborator

🔔 This is now entering its final comment period, as per the review above. 🔔

@rust-rfcbot rust-rfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Oct 15, 2025
@nikomatsakis
Copy link
Contributor

@rfcbot reviewed

Nice work @mu001999 !

@traviscross traviscross removed I-lang-nominated Nominated for discussion during a lang team meeting. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang labels Oct 22, 2025
@rust-rfcbot rust-rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Oct 25, 2025
@rust-rfcbot
Copy link
Collaborator

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@mu001999
Copy link
Contributor Author

@wesleywiser I think the lable S-blocked can be removed now, right?

@mu001999
Copy link
Contributor Author

And friendly ping @cjgillot

@tgross35 tgross35 removed the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Nov 19, 2025
@tgross35
Copy link
Contributor

@wesleywiser I think the lable S-blocked can be removed now, right?

And friendly ping @cjgillot

Fyi you can use @rustbot label -S-blocked to adjust labels yourself. @rustbot reroll allows you to ask for a new reviewer given it's been a while (but give Camille another week or two since they self-assigned and I just adjusted the labels now.)

@mu001999
Copy link
Contributor Author

mu001999 commented Nov 19, 2025

Fyi you can use @rustbot label -S-blocked to adjust labels yourself.

thanks, glad to know that ;)

@mu001999
Copy link
Contributor Author

@cjgillot friendly ping

@wesleywiser
Copy link
Member

r? compiler

@rustbot rustbot assigned mati865 and unassigned cjgillot Dec 11, 2025
@mati865
Copy link
Member

mati865 commented Dec 12, 2025

The idea sounds good to me (based on the discussions), but I know nothing of this code.

@rustbot reroll

@rustbot rustbot assigned jdonszelmann and unassigned mati865 Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team to-announce Announce this issue on triage meeting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lint regression: dead_code ignores #[allow(dead_code)] on traits