rust-lang/rust · error · syn::Error
CFG_RELEASE env var: {err}
Error message
CFG_RELEASE env var: {err} What it means
Emitted by the current_version proc macro in rustc_macros. The macro reads the CFG_RELEASE environment variable via proc_macro::tracked::env_var, then parses it as major.minor.patch (ignoring any -suffix like -dev or -nightly). If the env var is missing (tracked::env_var returns Err) or the value cannot be parsed into three numeric components (parse_str returns None), the macro emits a compile-time syn::Error at the call site. This macro is used by rustc_session to embed the compiler version into the binary.
Source
Thrown at compiler/rustc_macros/src/current_version.rs:12
use proc_macro::TokenStream;
use proc_macro2::Span;
use quote::quote;
pub(crate) fn current_version(_input: TokenStream) -> TokenStream {
let env_var = "CFG_RELEASE";
TokenStream::from(match RustcVersion::parse_cfg_release(env_var) {
Ok(RustcVersion { major, minor, patch }) => quote!(
// The produced literal has type `rustc_session::RustcVersion`.
Self { major: #major, minor: #minor, patch: #patch }
),
Err(err) => syn::Error::new(Span::call_site(), format!("{env_var} env var: {err}"))
.into_compile_error(),
})
}
struct RustcVersion {
major: u16,
minor: u16,
patch: u16,
}
impl RustcVersion {
fn parse_cfg_release(env_var: &str) -> Result<Self, Box<dyn std::error::Error>> {
let value = proc_macro::tracked::env_var(env_var)?;
Self::parse_str(&value)
.ok_or_else(|| format!("failed to parse rustc version: {:?}", value).into())
}
View on GitHub (pinned to 7088e4b63a)
Solutions
- Always build the compiler through ./x.py build or ./x.py check, which sets CFG_RELEASE and all other required environment variables.
- If you must invoke cargo directly, set CFG_RELEASE manually, e.g.: CFG_RELEASE="1.89.0-dev" cargo build -p rustc_session.
- Verify the value is parseable: it must contain at least two dot-separated numeric components (e.g., "1.89.0" or "1.89.0-dev").
- Check bootstrap.example.toml and the bootstrap code for how CFG_RELEASE is derived from the version field.
Example fix
# before: direct cargo build without bootstrap env cargo build -p rustc_session # error: CFG_RELEASE env var: ... # after: build through bootstrap which sets CFG_RELEASE ./x.py build --stage 1 compiler/rustc_session # or set the env var manually: CFG_RELEASE="1.89.0-dev" cargo build -p rustc_session
Defensive patterns
Strategy: validation
Validate before calling
// Before building a rustc crate that uses the current_version macro,
// verify that CFG_RELEASE is set and parseable.
fn validate_cfg_release() -> Result<(), String> {
let val = std::env::var("CFG_RELEASE").map_err(|_| "CFG_RELEASE env var is not set")?;
let core = val.split('-').next().unwrap_or("");
let parts: Vec<&str> = core.split('.').collect();
if parts.len() < 2 {
return Err(format!("CFG_RELEASE '{}' is not a valid version (expected major.minor.patch)", val));
}
for p in &parts {
p.parse::<u16>().map_err(|_| format!("CFG_RELEASE '{}' has non-numeric component", val))?;
}
Ok(())
} Try / catch
// This error is a compile-time syn::Error emitted by the proc macro. // It cannot be caught at runtime. Prevent it by ensuring the build // environment has CFG_RELEASE set (normally handled by ./x.py bootstrap). // The error appears as: error: CFG_RELEASE env var: <message>
Prevention
- Always build the compiler through ./x.py, which sets CFG_RELEASE via bootstrap.
- Never run bare cargo build on individual rustc crates without the bootstrap environment.
- If scripting CI around rustc, export CFG_RELEASE explicitly (e.g., CFG_RELEASE="$(cat src/version)" ).
- Ensure the version string is numeric major.minor[.patch] with an optional -suffix.
When it happens
Trigger: Building a rustc compiler crate (e.g., rustc_session) that invokes the current_version macro without the CFG_RELEASE environment variable set, or with a value that doesn't contain at least major.minor as numbers. Normal builds go through ./x.py which sets CFG_RELEASE via the bootstrap system.
Common situations: Running cargo build directly inside a rustc sub-crate instead of through ./x.py; CI scripts that build rustc components without invoking bootstrap; a broken or incomplete bootstrap configuration that fails to export CFG_RELEASE; manually setting CFG_RELEASE to a non-semver string.
Related errors
- src/stage0 doesn't contain a checksum for {}. Pre-built arti
- failed verification
- failed to run: {args}
- no cargo executable found at `{}`
- {} not found
AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10).
Data as JSON: /api/errors/21cf8377337721be.
Report an issue: GitHub.