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

Enabling keyword_idents lints doesn't warn about violations in other files #132218

Open
Zalathar opened this issue Oct 27, 2024 · 5 comments
Open
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Zalathar
Copy link
Contributor

Zalathar commented Oct 27, 2024

Consider this tiny two-file crate:

// main.rs
#![deny(keyword_idents)]

mod submod;

fn main() {}
// submod.rs
fn async() {}
fn await() {}
fn try() {}
fn dyn() {}
fn gen() {}

Building this crate should fail with several violations of the keyword_idents_2018 and keyword_idents_2024 lints. But instead, building unexpectedly succeeds!

(This particular example requires Rust 2015, but the same issue can be observed in 2018/2021 regarding the gen keyword only.)

@Zalathar Zalathar added A-edition-2024 Area: The 2024 edition A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 27, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 27, 2024
@Zalathar
Copy link
Contributor Author

I can reproduce this on 1.81-stable and 1.84-nightly/dev. No idea how old it is.

It seems to affect all of keyword_idents, keyword_idents_2018, and keyword_idents_2024.

If I put #![deny(keyword_idents)] inside submod.rs, the errors are reported as expected.

@Zalathar
Copy link
Contributor Author

Discovered while investigating CI failures in #132167.

@Zalathar Zalathar added the C-bug Category: This is a bug. label Oct 27, 2024
@ehuss
Copy link
Contributor

ehuss commented Oct 27, 2024

Thanks for the report! To clarify, the example should probably be built with edition 2015 (otherwise, the lint intentionally doesn't fire in editions >= when the keyword was added).

In general, this isn't a problem for edition migrations because it works correctly when the lint is passed on the command-line (which is how cargo fix works).

It looks like the pre-expansion lint pass is not able to propagate attribute-based lint level changes to nested modules. It does not have all the machinery that the normal lint passes have for propagating levels like that. For example, here it only passes in the attributes on the module.

cc @compiler-errors. Unless this seems like it would be easy to fix, I personally would lean towards not fixing it and documenting the limitation of pre-expansion lints, and to further emphasize in comments and the documentation (like it does here) that pre-expansion lints should be avoided unless absolutely necessary. Pre-expansion lints are soft deprecated since they have known limitations.

@Zalathar
Copy link
Contributor Author

To clarify, the example should probably be built with edition 2015 (otherwise, the lint intentionally doesn't fire in editions >= when the keyword was added).

Yes, though I should explicitly note that keyword_idents_2024 still has the same issue for the gen keyword when the crate edition is 2018 or 2021.

@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 27, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 28, 2024
…youxu

Known-bug test for `keyword_idents` lint not propagating to other files

Known-bug test for `keyword_idents` lint not propagating to other files when configured via attribute (rust-lang#132218).
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 28, 2024
Rollup merge of rust-lang#132253 - Zalathar:keyword-idents-bug, r=jieyouxu

Known-bug test for `keyword_idents` lint not propagating to other files

Known-bug test for `keyword_idents` lint not propagating to other files when configured via attribute (rust-lang#132218).
@traviscross
Copy link
Contributor

@rustbot labels -A-edition-2024

This isn't particularly related to Rust 2024, so we're going to drop that label.

@rustbot rustbot removed the A-edition-2024 Area: The 2024 edition label Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants