rust-lang/cargo · error
malformed output when learning about crate-type
Error message
malformed output when learning about crate-type {} information
{} What it means
While querying `rustc` for metadata about a crate type (e.g. `cdylib`, `bin`), Cargo expected a line of output but the iterator was empty. This happens in `parse_fingerprint`/`rustc --print` probing where rustc is invoked to learn file names for a specific crate type but produced no line to consume.
Solutions
- Re-run with `cargo build -vv` to capture the exact rustc command and stdout/stderr shown in the error's `output_err_info`.
- Disable any `RUSTC_WRAPPER`/`RUSTC_WORKSPACE_WRAPPER` (e.g. sccache) and retry to isolate wrapper corruption.
- Verify the crate type is valid for the target: check `[lib] crate-type` in `Cargo.toml` against the target's supported types.
- Reinstall/switch the toolchain with `rustup update` or `rustup override set stable`.
Example fix
// before RUSTC_WRAPPER=sccache cargo build --target wasm32-wasi // after (isolate wrapper) unset RUSTC_WRAPPER cargo build --target wasm32-wasi -vv
Defensive patterns
Strategy: try-catch
Validate before calling
null
Type guard
null
Try / catch
match target_info::parse_file_names(&output, &err, &mut lines) {
Ok(Some((p, s))) => Ok(()),
Ok(None) => Ok(()), // unsupported crate type, handle gracefully
Err(e) => { log::warn!("rustc crate-type probe failed: {e}"); disable_wrapper_and_retry()? },
} Prevention
- Pin a known-good toolchain in CI (`rustup default <pinned>`).
- Test `RUSTC_WRAPPER`s against a `--print` query before trusting them.
- Validate the target supports the crate-type before building (`rustc --print=crate-types --target <t>`).
When it happens
Trigger: Running a build for a crate type the active toolchain's rustc emits nothing for, or when rustc output is truncated/malformed (e.g. a broken toolchain, an injected `RUSTC_WRAPPER` that swallows stdout, or a misconfigured `--print` query).
Common situations: Switching toolchains (nightly vs stable) where a crate type is partially supported; sccache or other wrappers corrupting rustc stdout; cross-compilation with a target that lacks full crate-type support; partial rustc installations.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- output of --print= missing when learning about…
- cannot compile ` ` as the target ` ` does not support any…
- cannot mix `proc-macro` crate type with others
- cannot produce for ` ` as the target ` ` does not support…
- crate types can only be specified for libraries and example…
AI-assisted analysis of rust-lang/cargo@98a09e7e7d (2026-08-11).
Data as JSON: /api/errors/ca977566f105ed6e.
Report an issue: GitHub.
Appendix: source
Thrown at src/compiler/build_context/target_info.rs:710
///
/// 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 98a09e7e7d)