-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
A nonexistent inner attribute in lib.rs
or main.rs
breaks every procedural macro used within the entire crate
#118455
Comments
@rustbot label D-verbose D-confusing A-attributes A-macros Regressed between 1.37 and 1.38: https://rust.godbolt.org/z/eoczvTcd7 |
maybe related #110082 |
When we encounter code like ```rust #![non_existent] #[derive(Clone)] struct S; fn main() { S.clone(); } ``` we avoid emitting errors about the `derive` (which isn't early resolved as normal, but *has* a later resolution) and stop the compiler from advancing to later stages, to avoid knock down errors from the `derive` not being evaluated. Recovering these would be possible, but would produce incorrect errors in the cases where had the outer attribute been present it would have modified the behavior/evaluation of the `derive` attributes. Fix rust-lang#118455.
@chenyukang I took a stab at a minimally invasive attempt (by using |
oops, I didn't know you created a PR, |
When we encounter code like ```rust struct S; fn main() { S.clone(); } ``` we avoid emitting errors about the `derive` (which isn't early resolved as normal, but *has* a later resolution) and stop the compiler from advancing to later stages, to avoid knock down errors from the `derive` not being evaluated. Recovering these would be possible, but would produce incorrect errors in the cases where had the outer attribute been present it would have modified the behavior/evaluation of the `derive` attributes. Fix rust-lang#118455.
…trochenkov Suppress unhelpful diagnostics for unresolved top level attributes Fixes rust-lang#118455, unresolved top level attribute error didn't imported prelude and already have emitted an error, report builtin macro and attributes error by the way, so `check_invalid_crate_level_attr` in can ignore them. Also fixes rust-lang#89566, fixes rust-lang#67107. r? `@petrochenkov`
…trochenkov Suppress unhelpful diagnostics for unresolved top level attributes Fixes rust-lang#118455, unresolved top level attribute error didn't imported prelude and already have emitted an error, report builtin macro and attributes error by the way, so `check_invalid_crate_level_attr` in can ignore them. Also fixes rust-lang#89566, fixes rust-lang#67107. r? ``@petrochenkov``
…trochenkov Suppress unhelpful diagnostics for unresolved top level attributes Fixes rust-lang#118455, unresolved top level attribute error didn't imported prelude and already have emitted an error, report builtin macro and attributes error by the way, so `check_invalid_crate_level_attr` in can ignore them. Also fixes rust-lang#89566, fixes rust-lang#67107. r? ```@petrochenkov```
…ochenkov Suppress unhelpful diagnostics for unresolved top level attributes Fixes rust-lang#118455, unresolved top level attribute error didn't imported prelude and already have emitted an error, report builtin macro and attributes error by the way, so `check_invalid_crate_level_attr` in can ignore them. Also fixes rust-lang#89566, fixes rust-lang#67107. r? `@petrochenkov`
Rollup merge of rust-lang#118533 - chenyukang:yukang-fix-118455, r=petrochenkov Suppress unhelpful diagnostics for unresolved top level attributes Fixes rust-lang#118455, unresolved top level attribute error didn't imported prelude and already have emitted an error, report builtin macro and attributes error by the way, so `check_invalid_crate_level_attr` in can ignore them. Also fixes rust-lang#89566, fixes rust-lang#67107. r? `@petrochenkov`
Code
Current output
Desired output
Rationale and extra context
Having an inner nonexistent attribute in
lib.rs
ormain.rs
shouldn't break every procedural macro in the entire crate.Usually, one would detect this error just after writing, but when contained within
#[cfg_attr(not(feature = "some-feature", invalid_attribute))]
it can remain undetected for a while due to rust-analyzer not reporting errors for every feature combination, and causing the developer to have to deal with potentially several hundred errors without any clear lead on what caused it.When this bug is triggered while having and using, for example, a struct deriving
#[derive(Clone, Eq, PartialEq)]
or any other trait, it'll make the compiler emit an error for every attempt to use them. For moderately large projects this means suddenly having hundreds to thousands of errors not related to the actual change from one commit to the next one.Other cases
No response
Anything else?
The bug exists at least in versions
1.72.1
(stable) and1.76.0-nightly (a1a37735c 2023-11-23)
.Playground link: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=45f3021f3d7420b1d8e76d3295d5e283
The text was updated successfully, but these errors were encountered: