Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use workspace lints for crates in compiler/ #138084

Merged
merged 5 commits into from
Mar 9, 2025

Conversation

nnethercote
Copy link
Contributor

@nnethercote nnethercote commented Mar 6, 2025

This is nicer and hopefully less error prone than specifying lints via bootstrap.

r? @jieyouxu

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Mar 6, 2025
@petrochenkov
Copy link
Contributor

Maybe add a tidy check making sure that every compiler/*/Cargo.toml file has workspace = true?

Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

This approach seems reasonable to me. I opened #138106 to track an cleanup follow-up to handle them consistently, but is not a blocker for this PR.

EDIT: bootstrap thread: https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Consistent.20handling.20of.20compiler.2F*.20RUSTFLAGs.20and.20lints

Cargo.toml Outdated
Comment on lines 69 to 72
# NOTE: rustc-specific lints (e.g. `rustc::internal`) aren't supported by
# Cargo. They are specified for `compiler/` crates in
# `src/bootstrap/src/core/builder/cargo.rs`.
Copy link
Member

Choose a reason for hiding this comment

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

Question: do you know if we have a cargo issue to link to? Even if this isn't going to be implemented for a long time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ehuss said that #44690 is probably a blocker. I updated the comment to mention that issue.

Comment on lines +1081 to +1083
// NOTE: these flags are added to RUSTFLAGS, which is ignored when
// compiling proc macro crates such as `rustc_macros`,
// unfortunately.
Copy link
Member

Choose a reason for hiding this comment

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

Discussion: yeah this is unfortunate.

One way to do this is by unconditionally passing an arbitrary flag and asserting its presence in each compiler crate. Ugly, but it could work I think.

-- #138035 (comment)

We should probably investigate if we want to switch over to that approach to make sure the lints get consistently applied to all compiler crates.

Copy link
Member

Choose a reason for hiding this comment

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

But for this PR, it's not a blocker. I find the workspace lints approach for non-internal lints still less "magical" than doing all of them here.

@jieyouxu jieyouxu added S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 6, 2025
@jieyouxu
Copy link
Member

jieyouxu commented Mar 6, 2025

It was added in rust-lang#129523 to enable building on stable when there were
`cfg(bootstrap)` occurrences in the crate. But those are gone now, so
the section can be removed.
`llvm_enzyme` is now in the extra `check-cfg` list in bootstrap, so it
doesn't need to be handled explicitly here.
By naming them in `[workspace.lints.rust]` in the top-level
`Cargo.toml`, and then making all `compiler/` crates inherit them with
`[lints] workspace = true`. (I omitted `rustc_codegen_{cranelift,gcc}`,
because they're a bit different.)

The advantages of this over the current approach:
- It uses a standard Cargo feature, rather than special handling in
  bootstrap. So, easier to understand, and less likely to get
  accidentally broken in the future.
- It works for proc macro crates.

It's a shame it doesn't work for rustc-specific lints, as the comments
explain.
And fix the new errors in the handful of crates that didn't have a
`#![warn(unreachable_pub)]`.
(Except for `rustc_codegen_cranelift`.)

It's no longer necessary now that `unreachable_pub` is in the workspace
lints.
@nnethercote nnethercote marked this pull request as ready for review March 7, 2025 21:46
@rustbot
Copy link
Collaborator

rustbot commented Mar 7, 2025

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred in compiler/rustc_sanitizers

cc @rust-lang/project-exploit-mitigations, @rcvalle

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

Some changes occurred in exhaustiveness checking

cc @Nadrieril

This PR changes Stable MIR

cc @oli-obk, @celinval, @ouz-a

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

rustc_error_messages was changed

cc @davidtwco, @compiler-errors, @TaKO8Ki

Some changes occurred in compiler/rustc_attr_data_structures

cc @jdonszelmann

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

Some changes occurred in diagnostic error codes

cc @GuillaumeGomez

@nnethercote
Copy link
Contributor Author

@jieyouxu: I think this is ready to go.

  • The llvm_enzyme issue is fixed. There's a new commit removing it from compiler/rustc_builtin_macros/Cargo.toml.
  • The Zulip discussion hasn't surfaced any alternative suggestions.
  • I agree with @petrochenkov that a tidy check would be good. It will be similar to the existing edition.rs check, and I'm happy to write it, but it won't happen until next week. If you're willing to accept that in a follow-up PR then we could get this PR in the queue now.

@jieyouxu
Copy link
Member

jieyouxu commented Mar 8, 2025

Yes, I think the tidy check isn't a blocker and can be done separately. I'll file an issue so we don't forgor.

@rustbot label: -S-waiting-on-team +S-waiting-on-review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). labels Mar 8, 2025
Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

Thanks! This is a nice cleanup, and since we don't really have any alternative better approach yet, let's land this to allow consistently enforcing unreachable_pub and whatever other lints we may wish to enable for all compiler crates.

I have one question re. maybe mentioning the Cargo.toml workspace lint section in rustc-dev-guide vs the tool lints in bootstrap cargo, since they're now in two places and there is a "better place" for non-tool lints to go (in Cargo.toml).

@jieyouxu
Copy link
Member

jieyouxu commented Mar 8, 2025

@bors r+

@bors
Copy link
Contributor

bors commented Mar 8, 2025

📌 Commit 8a3e033 has been approved by jieyouxu

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 Mar 8, 2025
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Mar 9, 2025
…youxu

Use workspace lints for crates in `compiler/`

This is nicer and hopefully less error prone than specifying lints via bootstrap.

r? `@jieyouxu`
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 9, 2025
Rollup of 16 pull requests

Successful merges:

 - rust-lang#122790 (Apply dllimport in ThinLTO)
 - rust-lang#136127 (Allow `*const W<dyn A> -> *const dyn A` ptr cast)
 - rust-lang#136968 (Turn order dependent trait objects future incompat warning into a hard error)
 - rust-lang#137147 (Add exclude to config.toml)
 - rust-lang#137319 (Stabilize `const_vec_string_slice`)
 - rust-lang#137885 (tidy: add triagebot checks)
 - rust-lang#138040 (compiler: Use `size_of` from the prelude instead of imported)
 - rust-lang#138052 (strip `-Wlinker-messages` wrappers from `rust-lld` rmake test)
 - rust-lang#138084 (Use workspace lints for crates in `compiler/`)
 - rust-lang#138158 (Move more layouting logic to `rustc_abi`)
 - rust-lang#138160 (depend more on attr_data_structures and move find_attr! there)
 - rust-lang#138192 (crashes: couple more tests)
 - rust-lang#138216 (bootstrap: Fix stack printing when a step cycle is detected)
 - rust-lang#138232 (Reduce verbosity of GCC build log)
 - rust-lang#138233 (Windows: Don't link std (and run-make) against advapi32, except on win7)
 - rust-lang#138242 (Revert "Don't test new error messages with the stage 0 compiler")

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 9, 2025
…iaskrgr

Rollup of 12 pull requests

Successful merges:

 - rust-lang#136127 (Allow `*const W<dyn A> -> *const dyn A` ptr cast)
 - rust-lang#136968 (Turn order dependent trait objects future incompat warning into a hard error)
 - rust-lang#137319 (Stabilize `const_vec_string_slice`)
 - rust-lang#137885 (tidy: add triagebot checks)
 - rust-lang#138040 (compiler: Use `size_of` from the prelude instead of imported)
 - rust-lang#138084 (Use workspace lints for crates in `compiler/`)
 - rust-lang#138158 (Move more layouting logic to `rustc_abi`)
 - rust-lang#138160 (depend more on attr_data_structures and move find_attr! there)
 - rust-lang#138192 (crashes: couple more tests)
 - rust-lang#138216 (bootstrap: Fix stack printing when a step cycle is detected)
 - rust-lang#138232 (Reduce verbosity of GCC build log)
 - rust-lang#138242 (Revert "Don't test new error messages with the stage 0 compiler")

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 48caf81 into rust-lang:master Mar 9, 2025
6 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Mar 9, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 9, 2025
Rollup merge of rust-lang#138084 - nnethercote:workspace-lints, r=jieyouxu

Use workspace lints for crates in `compiler/`

This is nicer and hopefully less error prone than specifying lints via bootstrap.

r? ``@jieyouxu``
@nnethercote nnethercote deleted the workspace-lints branch March 9, 2025 21:08
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Mar 10, 2025
Revert <rust-lang#138084> to buy time to
consider options that avoids breaking downstream usages of cargo on
distributed `rustc-src` artifacts, where such cargo invocations fail due
to inability to inherit `lints` from workspace root manifest's
`workspace.lints` (this is only valid for the source rust-lang/rust
workspace, but not really the distributed `rustc-src` artifacts).

This breakage was reported in
<rust-lang#138304>.

This reverts commit 48caf81, reversing
changes made to c666287.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 10, 2025
…=Noratrieb

Revert "Use workspace lints for crates in `compiler/` rust-lang#138084"

Revert <rust-lang#138084> to buy time to consider options that avoids breaking downstream usages of cargo on distributed `rustc-src` artifacts, where such cargo invocations fail due to inability to inherit `lints` from workspace root manifest's `workspace.lints` (this is only valid for the source rust-lang/rust workspace, but not really the distributed `rustc-src` artifacts). The problem is that the `rustc-src` component doesn't include the root `Cargo.toml` manifest.

This breakage was reported in rust-lang#138304.

This reverts commit 48caf81, reversing changes made to c666287.

cc `@RalfJung`

r? `@nnethercote` (sorry, I didn't consider this being a thing 💀)
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 10, 2025
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#137931 (Add remark for missing `llvm-tools` component re. `rustc_private` linker failures related to not finding LLVM libraries)
 - rust-lang#138138 (Pass `InferCtxt` to `InlineAsmCtxt` to properly taint on error)
 - rust-lang#138223 (Fix post-merge workflow)
 - rust-lang#138268 (Handle empty test suites in GitHub job summary report)
 - rust-lang#138278 (Delegation: fix ICE with invalid `MethodCall` generation)
 - rust-lang#138281 (Fix O(tests) stack usage in edition 2024 mergeable doctests)
 - rust-lang#138305 (Subtree update of `rust-analyzer`)
 - rust-lang#138306 (Revert "Use workspace lints for crates in `compiler/` rust-lang#138084")

r? `@ghost`
`@rustbot` modify labels: rollup
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants