rust-lang/cargo · error
malformed output when learning about crate-type {} informati
Error message
malformed output when learning about crate-type {} information
{} What it means
In parse_crate_type (target_info.rs:664-692), Cargo runs `rustc --print=...` and reads crate-type information line by line. After confirming the crate type is supported (no 'unsupported crate type' in stderr), it expects at least one more line of output; if `lines.next()` is None, the rustc output is malformed/truncated and Cargo bails naming the crate-type and the captured output.
Source
Thrown at src/compiler/build_context/target_info.rs:679
///
/// This function can not handle more than one file per type (with wasm32-unknown-emscripten, there
/// are two files for bin (`.wasm` and `.js`)).
fn parse_crate_type(
crate_type: &CrateType,
cmd: &ProcessBuilder,
output: &str,
error: &str,
lines: &mut str::Lines<'_>,
) -> CargoResult<Option<(String, String)>> {
let not_supported = error.lines().any(|line| {
(line.contains("unsupported crate type") || line.contains("unknown crate type"))
&& line.contains(&format!("crate type `{}`", crate_type))
});
if not_supported {
return Ok(None);
}
let Some(line) = lines.next() else {
anyhow::bail!(
"malformed output when learning about crate-type {} information\n{}",
crate_type,
output_err_info(cmd, output, error)
)
};
let mut parts = line.trim().split("___");
let prefix = parts.next().unwrap();
let Some(suffix) = parts.next() else {
return error_missing_print_output("file-names", cmd, output, error);
};
Ok(Some((prefix.to_string(), suffix.to_string())))
}
/// Helper for creating an error message for missing output from a certain `--print` request.
fn error_missing_print_output<T>(
request: &str,
cmd: &ProcessBuilder,View on GitHub (pinned to 0e07a15537)
Solutions
- Inspect the full error (Cargo prints rustc stdout/stderr) to see what rustc actually returned.
- Disable rustc wrappers temporarily (`unset RUSTC_WRAPPER RUSTC_WORKSPACE_WRAPPER`) to isolate the cause.
- Reinstall/repair the toolchain with `rustup toolchain install`.
- If using a custom target JSON, ensure the crate-type list is valid.
Example fix
// before $ RUSTC_WRAPPER=./broken-wrapper cargo build error: malformed output when learning about crate-type cdylib information // after $ unset RUSTC_WRAPPER && cargo build
Defensive patterns
Strategy: try-catch
Try / catch
// Run a smoke test of rustc --print in CI; surface wrapper problems early
match std::process::Command::new(rustc)
.args(["--print", "crate-type", "--", "-"])
.output()
{
Ok(o) if !o.stdout.is_empty() => { /* ok */ }
_ => eprintln!("rustc --print output looks broken; check wrappers/install"),
} Prevention
- Pin rustc/rustc-wrapper versions in CI.
- Smoke-test `rustc --print` output when adding a new wrapper.
- Keep toolchain installs intact (rustup repair / reinstall).
When it happens
Trigger: A custom rustc (or rustc wrapper) that returns success for `--print` but emits fewer lines than Cargo expects; a broken/raced rustc installation; a misbehaving `RUSTC_WRAPPER`/`RUSTC` override; partial rustc output due to a signal/timeout.
Common situations: Using sccache or a custom rustc wrapper that mangles --print output; corrupted toolchain install; concurrent builds racing on a shared target dir; very old or patched rustc.
Related errors
- output of --print={request} missing when learning about targ
- could not find specification for target `{target}`. Depend
- {}: {:?}
- rustc load ok
- able to invoke rustc
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/ca977566f105ed6e.json.
Report an issue: GitHub.