rust-lang/rust · error · anyhow::Error

failed to parse version

Error message

failed to parse version

What it means

Thrown by Tool::new in bump-stage0 when src/version cannot be parsed into exactly three u16 components. The file is read, trimmed, split on '.', each part parsed as u16, and the result collected into a [u16; 3] array via try_into. Failure means either the wrong number of components or a non-numeric component.

Source

Thrown at src/tools/bump-stage0/src/main.rs:39

}

impl Tool {
    fn new(compiler_date: Option<String>, rustfmt_date: Option<String>) -> Result<Self, Error> {
        let channel = match std::fs::read_to_string("src/ci/channel")?.trim() {
            "stable" => Channel::Stable,
            "beta" => Channel::Beta,
            "nightly" => Channel::Nightly,
            other => anyhow::bail!("unsupported channel: {}", other),
        };

        // Split "1.42.0" into [1, 42, 0]
        let version = std::fs::read_to_string("src/version")?
            .trim()
            .split('.')
            .map(|val| val.parse())
            .collect::<Result<Vec<_>, _>>()?
            .try_into()
            .map_err(|_| anyhow::anyhow!("failed to parse version"))?;

        let existing = parse_stage0_file();

        Ok(Self {
            channel,
            version,
            compiler_date,
            rustfmt_date,
            config: existing.config,
            checksums: IndexMap::new(),
        })
    }

    fn update_stage0_file(mut self) -> Result<(), Error> {
        const COMMENTS: &str = r#"# The configuration above this comment is editable, and can be changed
# by forks of the repository if they have alternate values.
#
# The section below is generated by `./x.py run src/tools/bump-stage0`,

View on GitHub (pinned to 7088e4b63a)

Solutions

  1. Open src/version and confirm it is exactly MAJOR.MINOR.PATCH with three numeric components (e.g. 1.82.0).
  2. Ensure no trailing newline/whitespace inside components and no extra dot-separated fields.
  3. Confirm each number is within 0..=65535.

Example fix

// before
$ cat src/version
1.82

// after
$ echo 1.82.0 > src/version
Defensive patterns

Strategy: validation

Validate before calling

// Validate the version string shape before parsing.
let raw = std::fs::read_to_string("src/version")?.trim().to_string();
let parts: Vec<&str> = raw.split('.').collect();
if parts.len() != 3 || parts.iter().any(|p| p.parse::<u16>().is_err()) {
    eprintln!("src/version '{raw}' is not MAJOR.MINOR.PATCH with numeric u16 parts");
    std::process::exit(1);
}

Prevention

When it happens

Trigger: src/version contains fewer or more than three dot-separated numbers (e.g. '1.82' or '1.82.0.0'); a component is non-numeric or empty; a component exceeds the u16 max (65535).

Common situations: Editing src/version during a release and leaving an incomplete value; accidental newline or whitespace inside a component; tooling wrote a pre-release suffix (e.g. '1.82.0-dev') that the parser does not handle.

Understand the failure class

Related errors


AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10). Data as JSON: /api/errors/47829d072533138b. Report an issue: GitHub.