Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

apply lint levels of ancestors to pre-expansion lints in mod m; files - #166007

Closed
Albab-Hasan wants to merge 2 commits into
rust-lang:mainfrom
Albab-Hasan:pre-expansion-lints-inherit-crate-levels
Closed

Albab-Hasan wants to merge 2 commits into
rust-lang:mainfrom
Albab-Hasan:pre-expansion-lints-inherit-crate-levels

Conversation

@Albab-Hasan

Copy link
Copy Markdown
Contributor

a mod m; file is linted on its own when its loaded during expansion and that run only started from the command line levels. so #![deny(keyword_idents)] at the crate root or a lint attribute on an enclosing module never reached it. now the expander passes those attributes along.

fixes #132218

#165049 also fixes this by buffering the lints. this is the small version the -Zcrate-attr lint flag desugar needs, see #t-compiler > -Zcrate-attr lint flag aliasing

cc @jyn514

r? @JonathanBrouwer

@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 Nov 15, 2026
@Albab-Hasan

Copy link
Copy Markdown
Contributor Author

@Bryntet i only found #165049 after i had this written, sorry for not checking first. i dont want to step on your work. if this gets in the way of yours im happy to close it or rebase on top of whatever you prefer

@rust-bors

This comment has been minimized.

@JonathanBrouwer

JonathanBrouwer commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Merging this before #165049 seems like a good idea, as this will decrease the size of that PR which is already too big (and might take a while to get merged)

I feel like the approach of that PR is better long-term though.

pre-expansion lints of an out of line module only see the command line and the attributes of the module itself. lint level attributes on the crate root and on enclosing modules are ignored. this test records that behaviour.
…modules

an out of line module is linted on its own when its file is loaded during expansion, starting from the command line levels. the expander now keeps the lint level attributes of the enclosing modules in ModuleData and passes them along with the crate attributes, so the lint run enters those levels before the attributes of the module.

this also fixes the known-bug test for keyword_idents not reaching other files.
@JonathanBrouwer
JonathanBrouwer force-pushed the pre-expansion-lints-inherit-crate-levels branch from 81ca3aa to 7e846ca Compare November 17, 2026 12:46
@rustbot

rustbot commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@JonathanBrouwer

JonathanBrouwer commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

^ Rebase

I feel like we're copying a lot of attributes around, let's see what rust-timer thinks of that
@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 17, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 17, 2026
…-levels, r=<try>

apply lint levels of ancestors to pre-expansion lints in `mod m;` files
@rust-bors

This comment has been minimized.

@JonathanBrouwer JonathanBrouwer added needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. T-lang Relevant to the language team labels Nov 17, 2026
LoadedMod(ast::NodeId, &'a [ast::Attribute], &'a [Box<ast::Item>]),
/// The second field holds the attributes of the crate root and then of each enclosing
/// module. Only their lint levels are used, the attributes themselves are not checked.
LoadedMod(ast::NodeId, &'a [&'a [ast::Attribute]], &'a [ast::Attribute], &'a [Box<ast::Item>]),

@JonathanBrouwer JonathanBrouwer Nov 17, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you make this a struct variant?

View changes since the review

@JonathanBrouwer JonathanBrouwer Nov 17, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we put this file in the auxilliary folder?

View changes since the review

@JonathanBrouwer JonathanBrouwer Nov 17, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@JonathanBrouwer JonathanBrouwer Nov 17, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The implementation proposed by this PR fails the following test:

//@ check-pass
//@ edition: 2015

#[warn(keyword_idents_2018)]
fn main() {
    #[path = "lint_pre_expansion_extern_module_levels_aux.rs"]
    mod lint_pre_expansion_extern_module_levels_aux;
}

//~? WARN `try` is a keyword in the 2018 edition
//~? WARN this is accepted in the current edition
//~? WARN `async` is a keyword in the 2018 edition
//~? WARN this is accepted in the current edition

This would work with the implementation in #165049, and I think it is desirable for this to work. To make this work requires a different approach than this PR, that is, this PR is implementation-wise not a step towards that, so I feel iffy about merging this.

How do you feel about this?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah this only follows modules so #165049 is the better fix. id like it in as a stopgap for the crate-attr desugar but im fine closing it if youd rather wait

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I talked with @Bryntet in DMs and he says he's going to do the work to get #165049 merged soon. What is the state of crate-attr exactly? If that PR is merged in say a month or so, would that be ok?

@JonathanBrouwer JonathanBrouwer Nov 17, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also given that this PR seems to have a significant performance regression, which may be hard to fix? (not sure)
#166007 (comment)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the lint flag desugar is the main thing left and it waits on #165669 so a month is fine. ill close this in favor of #165049

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 17, 2026
@rustbot

rustbot commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rust-bors

rust-bors Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 660e459 (660e459736dac230d867f150662b9fce4f7fa038)
Base parent: 5c9cae3 (5c9cae324e6d8b9ed075e7717eabd972126b7d17)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown

Finished benchmarking commit (660e459): comparison URL.

Overall result: ❌ regressions - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never rustc-perf
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.4% [0.1%, 1.4%] 43
Regressions ❌
(secondary)
0.3% [0.2%, 0.6%] 7
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.4% [0.1%, 1.4%] 43

Max RSS (memory usage)

Results (primary -0.8%, secondary -0.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
1.3% [1.3%, 1.3%] 1
Regressions ❌
(secondary)
0.5% [0.5%, 0.5%] 1
Improvements ✅
(primary)
-2.9% [-2.9%, -2.9%] 1
Improvements ✅
(secondary)
-0.5% [-0.6%, -0.4%] 4
All ❌✅ (primary) -0.8% [-2.9%, 1.3%] 2

Cycles

Results (primary 2.7%, secondary -3.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.7% [2.7%, 2.7%] 1
Regressions ❌
(secondary)
0.6% [0.6%, 0.6%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.9% [-7.1%, -2.2%] 5
All ❌✅ (primary) 2.7% [2.7%, 2.7%] 1

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 466.359s -> 465.942s (-0.09%)
Artifact size: 405.36 MiB -> 405.37 MiB (0.00%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Nov 17, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. perf-regression Performance regression. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants