Skip to content

Only allow bootstrap cfg in rustc & related #142160

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

Merged
merged 2 commits into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions library/core/src/iter/sources/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
///
/// ```
/// #![feature(iter_macro, coroutines)]
/// # #[cfg(not(bootstrap))]
/// # {
///
/// let it = std::iter::iter!{|| {
/// yield 1;
Expand All @@ -19,11 +17,10 @@
/// } }();
/// let v: Vec<_> = it.collect();
/// assert_eq!(v, [1, 2, 3]);
/// # }
/// ```
#[unstable(feature = "iter_macro", issue = "none", reason = "generators are unstable")]
#[allow_internal_unstable(coroutines, iter_from_coroutine)]
#[cfg_attr(not(bootstrap), rustc_builtin_macro)]
#[rustc_builtin_macro]
pub macro iter($($t:tt)*) {
/* compiler-builtin */
}
16 changes: 9 additions & 7 deletions src/bootstrap/src/core/builder/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,15 @@ impl Builder<'_> {
for (restricted_mode, name, values) in EXTRA_CHECK_CFGS {
if restricted_mode.is_none() || *restricted_mode == Some(mode) {
rustflags.arg(&check_cfg_arg(name, *values));

if *name == "bootstrap" {
// Cargo doesn't pass RUSTFLAGS to proc_macros:
// https://github.com/rust-lang/cargo/issues/4423
// Thus, if we are on stage 0, we explicitly set `--cfg=bootstrap`.
// We also declare that the flag is expected, which we need to do to not
// get warnings about it being unexpected.
hostflags.arg(check_cfg_arg(name, *values));
}
}
}

Expand All @@ -645,13 +654,6 @@ impl Builder<'_> {
if stage == 0 {
hostflags.arg("--cfg=bootstrap");
}
// Cargo doesn't pass RUSTFLAGS to proc_macros:
// https://github.com/rust-lang/cargo/issues/4423
// Thus, if we are on stage 0, we explicitly set `--cfg=bootstrap`.
// We also declare that the flag is expected, which we need to do to not
// get warnings about it being unexpected.
hostflags.arg("-Zunstable-options");
hostflags.arg("--check-cfg=cfg(bootstrap)");

// FIXME: It might be better to use the same value for both `RUSTFLAGS` and `RUSTDOCFLAGS`,
// but this breaks CI. At the very least, stage0 `rustdoc` needs `--cfg bootstrap`. See
Expand Down
5 changes: 4 additions & 1 deletion src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ const LLD_FILE_NAMES: &[&str] = &["ld.lld", "ld64.lld", "lld-link", "wasm-ld"];
/// (Mode restriction, config name, config values (if any))
#[expect(clippy::type_complexity)] // It's fine for hard-coded list and type is explained above.
const EXTRA_CHECK_CFGS: &[(Option<Mode>, &str, Option<&[&'static str]>)] = &[
(None, "bootstrap", None),
(Some(Mode::Rustc), "bootstrap", None),
(Some(Mode::Codegen), "bootstrap", None),
(Some(Mode::ToolRustc), "bootstrap", None),
(Some(Mode::ToolStd), "bootstrap", None),
(Some(Mode::Rustc), "llvm_enzyme", None),
(Some(Mode::Codegen), "llvm_enzyme", None),
(Some(Mode::ToolRustc), "llvm_enzyme", None),
Expand Down
Loading