Skip to content
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

cg_llvm: Reduce visibility of some items outside the llvm module #136721

Merged
merged 1 commit into from
Feb 11, 2025

Conversation

dpaoliello
Copy link
Contributor

@dpaoliello dpaoliello commented Feb 8, 2025

Next piece of #135502

This reduces the visibility of items (other than those in the llvm module) so that dead code analysis will correctly identify unused items.

@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 Feb 8, 2025
@dpaoliello dpaoliello changed the title rustc_codegen_llvm: Reduce visibility of items outside of the llvm module rustc_codegen_llvm: Reduce visibility of items outside (other than the llvm module) Feb 8, 2025
Comment on lines 2 to 3
#![expect(dead_code)]
#![expect(unreachable_pub)]
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm reluctant to do this, even temporarily, because it has the side-effect of disabling dead-code warnings throughout the whole module, even for things that should be warnings (e.g. an unused pub(crate) helper function).

And we would be unable to get rid of it until all of the unwanted warnings are fixed individually.

Copy link
Member

Choose a reason for hiding this comment

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

hmm. how do nested deny and expect work, exactly?

Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC, expect behaves exactly like allow, except that it also emits an unfulfilled_lint_expectations (which is a warning by default) if it doesn't suppress anything.

So if you have warn/deny on an outer module, and then allow/expect on an inner module/item, the diagnostic is suppressed as you would expect.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you mean nested in the other direction, I have no idea.

(But I have noticed that if I put #[allow(dead_code)] on an enum, and then #[warn(dead_code)] on one of its variants, there is no diagnostic even if that variant is unused. And if I replace the warn with expect, the expectation is violated.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, removed this and re-added the workaround in lib.rs

@dpaoliello dpaoliello requested a review from Zalathar February 11, 2025 00:41
@Zalathar Zalathar changed the title rustc_codegen_llvm: Reduce visibility of items outside (other than the llvm module) cg_llvm: Reduce visibility of some items outside the llvm module Feb 11, 2025
@Zalathar
Copy link
Contributor

Looks good, thanks.

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Feb 11, 2025

📌 Commit 5f29273 has been approved by Zalathar

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 11, 2025
jhpratt added a commit to jhpratt/rust that referenced this pull request Feb 11, 2025
cg_llvm: Reduce visibility of some items outside the `llvm` module

Next piece of rust-lang#135502

This reduces the visibility of items (other than those in the `llvm` module) so that dead code analysis will correctly identify unused items.
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 11, 2025
Rollup of 11 pull requests

Successful merges:

 - rust-lang#136606 (Fix long lines which rustfmt fails to format)
 - rust-lang#136663 (Stabilize `NonZero::count_ones`)
 - rust-lang#136672 (library: doc: core::alloc::Allocator: trivial typo fix)
 - rust-lang#136704 (Improve examples for file locking)
 - rust-lang#136721 (cg_llvm: Reduce visibility of some items outside the `llvm` module)
 - rust-lang#136813 (rustc_target: Add the fp16 target feature for AArch32)
 - rust-lang#136830 (fix i686-unknown-hurd-gnu x87 footnote)
 - rust-lang#136832 (Fix platform support table for i686-unknown-uefi)
 - rust-lang#136835 (Stop using span hack for contracts feature gating)
 - rust-lang#136837 (Overhaul how contracts are lowered on fn-like bodies)
 - rust-lang#136839 (fix ensure_monomorphic_enough)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 6153a8d into rust-lang:master Feb 11, 2025
6 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Feb 11, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Feb 11, 2025
Rollup merge of rust-lang#136721 - dpaoliello:cleanllvm2, r=Zalathar

cg_llvm: Reduce visibility of some items outside the `llvm` module

Next piece of rust-lang#135502

This reduces the visibility of items (other than those in the `llvm` module) so that dead code analysis will correctly identify unused items.
@dpaoliello dpaoliello deleted the cleanllvm2 branch February 11, 2025 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants