-
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
How do crate-level macro attributes deal with standard library prelude? #110082
Comments
Right now the behavior on stable is that #108221 accidentally broke this behavior causing regressions in some I think we can break this behavior intentionally as well, because the crater regression were obtained in a very unnatural setup - crater compiles those crates for x86 host instead of their expected embedded targets making them fully unconfigured. |
What is injected right now (edition 2021): #[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std; // this std is hygienic // no_std
#[prelude_import]
use core::prelude::rust_2021::*;
#[macro_use]
extern crate core; // this core is hygienic
#[macro_use]
extern crate compiler_builtins; // this compiler_builtins is hygienic // no_core |
I think a reasonable behavior would be to inject the standard library prelude once after all the crate-level attributes are expanded and the root AST is fixed. Alternative 1: what exactly is injected would be determined by crate attributes at that point (remaining on the expanded root). For fully unconfigured crates that would mean that they always link Alternative 2: what exactly is injected would be determined by the "pre-configured attribute list" determined before any macro expansion (see #108221 for details). This would give a choice to fully unconfigured crates to control their |
Another possibility - change how Crate-level |
…pkin expand: Change how `#![cfg(FALSE)]` behaves on crate root Previously it removed all other attributes from the crate root. Now it removes only attributes below itself (during both regular expansion and pre-configuration). So it becomes possible to configure some global crate properties even for fully unconfigured crates. Fixes rust-lang#104633 Part of rust-lang#110082
…pkin expand: Change how `#![cfg(FALSE)]` behaves on crate root Previously it removed all other attributes from the crate root. Now it removes only attributes below itself (during both regular expansion and pre-configuration). So it becomes possible to configure some global crate properties even for fully unconfigured crates. Fixes rust-lang#104633 Part of rust-lang#110082
…pkin expand: Change how `#![cfg(FALSE)]` behaves on crate root Previously it removed all other attributes from the crate root. Now it removes only attributes below itself (during both regular expansion and pre-configuration). So it becomes possible to configure some global crate properties even for fully unconfigured crates. Fixes rust-lang#104633 Part of rust-lang#110082
…pkin expand: Change how `#![cfg(FALSE)]` behaves on crate root Previously it removed all other attributes from the crate root. Now it removes only attributes below itself (during both regular expansion and pre-configuration). So it becomes possible to configure some global crate properties even for fully unconfigured crates. Fixes rust-lang#104633 Part of rust-lang#110082
Here I'll talk about hightly unstable crate-level macro attributes first, but this issue is relevant even on stable because crate level
#![cfg(...)]
is also such a macro (sort of), and it is supported since Rust 1.0.This case caused issues in #108221.
We assume that macros work with token streams.
Implicitly injected extern prelude does not have any token representation, so I conclude that crate-level macro attributes should only receive explicitly written user code as input (collected during token collection as usual).
Now the question is how and when standard library prelude is added to output of a crate level attribute (including
#![cfg(FALSE)]
) because eventually it should be added there.Note: #104633 is a similar issue discussing the fate of
#![feature]
attributes on a fully unconfigured crate.The text was updated successfully, but these errors were encountered: