{"record":{"id":"dba286ab3965c29a","repo":"rust-lang/rust","slug":"rustc-metadata-did-not-contain-commit-hash","errorCode":null,"errorMessage":"rustc metadata did not contain commit hash","messagePattern":"rustc metadata did not contain commit hash","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/tools/miri/miri-script/src/commands.rs","lineNumber":143,"sourceCode":"            Command::Squash => Self::squash(),\n        }\n    }\n\n    fn toolchain(new_commit: Option<String>, flags: Vec<String>) -> Result<()> {\n        let sh = Shell::new()?;\n        sh.change_dir(miri_dir()?);\n        let new_commit = match new_commit {\n            Some(c) => c,\n            None => sh.read_file(\"rust-version\")?.trim().to_owned(),\n        };\n        let current_commit = {\n            let rustc_info = cmd!(sh, \"rustc +miri --version -v\").read();\n            if let Ok(rustc_info) = rustc_info {\n                let metadata = rustc_version::version_meta_for(&rustc_info)?;\n                Some(\n                    metadata\n                        .commit_hash\n                        .ok_or_else(|| anyhow!(\"rustc metadata did not contain commit hash\"))?,\n                )\n            } else {\n                None\n            }\n        };\n        // Check if we already are at that commit.\n        if current_commit.as_ref() == Some(&new_commit) {\n            if active_toolchain()? != \"miri\" {\n                cmd!(sh, \"rustup override set miri\").run()?;\n            }\n            return Ok(());\n        }\n        // Install and setup new toolchain.\n        cmd!(sh, \"rustup toolchain uninstall miri\").run()?;\n\n        cmd!(sh, \"rustup-toolchain-install-master -n miri -c cargo -c rust-src -c rustc-dev -c llvm-tools -c rustfmt -c clippy {flags...} -- {new_commit}\")\n            .run()\n            .context(\"Failed to run rustup-toolchain-install-master. If it is not installed, run 'cargo install rustup-toolchain-install-master'.\")?;","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/src/tools/miri/miri-script/src/commands.rs#L125-L161","documentation":"Returned from toolchain() when rustc_version::version_meta_for parses the `rustc +miri --version -v` output but the resulting VersionMeta has commit_hash == None. The script needs the commit hash to decide whether the installed 'miri' toolchain already matches the target commit, so it aborts.","triggerScenarios":"Running `miri-script toolchain` (or any path that calls it) where rustc was built without embedding commit metadata — typically a distro or custom rustc build, or a rustc built with release-debuginfo stripped.","commonSituations":"Using a locally-built rustc without the commit-hash git embedding; a distro rustc package that omits verbose metadata; running against a rustc stage1 build that lacks the full version string.","solutions":["Install a rustc that includes commit metadata (official rustup nightly, or a rust built from a clean git checkout with the metadata embedded).","Pass the commit explicitly to bypass detection: `miri-script toolchain <commit>`.","Ensure the `rust-version` file in the miri tree points at a commit available via rustup-toolchain-install-master."],"exampleFix":"// before\nlet metadata = rustc_version::version_meta_for(&rustc_info)?;\nSome(metadata.commit_hash.ok_or_else(||\n    anyhow!(\"rustc metadata did not contain commit hash\"))?,\n)\n\n// after: fall back to the file's commit when metadata is incomplete\nlet commit = metadata.commit_hash\n    .or_else(|| std::fs::read_to_string(\"rust-version\").ok()?.trim().to_owned().into())\n    .ok_or_else(|| anyhow!(\n        \"rustc metadata did not contain commit hash; \\\n         pass one explicitly with `miri-script toolchain <commit>`\"\n    ))?;","handlingStrategy":"fallback","validationCode":"// Detect missing commit hash up front and decide whether to bypass detection:\nlet has_hash = std::process::Command::new(\"rustc\")\n    .arg(\"+miri\").arg(\"--version\").arg(\"-v\").output()\n    .map(|o| String::from_utf8_lossy(&o.stdout).contains(\"commit-hash:\")).unwrap_or(false);\nif !has_hash { /* pass <commit> explicitly to miri-script toolchain */ }","typeGuard":"null","tryCatchPattern":"match miri_script::Command::toolchain(commit.clone(), flags) {\n    Ok(()) => Ok(()),\n    Err(e) if e.to_string().contains(\"commit hash\") => {\n        eprintln!(\"re-run with an explicit commit: miri-script toolchain <commit>\");\n        Err(e)\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Use a rustc build that embeds commit metadata (official nightly or clean git build).","Pass the target commit explicitly to miri-script toolchain.","Keep rust-version file pointing at an installable commit."],"tags":["miri","toolchain","rustc","metadata"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}