crates/mimir-driver/tests/no_trimmed_ice.rs
//! The driver must never make rustc ICE on a crate that emits no diagnostic
//! at all (dwarf 2026-10-17: every member failed on dependencies like
//! toml_edit — a fn's return type and its `let` types printed with trimmed
//! paths, the `trimmed_def_paths` query ran, and rustc panicked at session
//! end: "diagnostics were expected but none were emitted"). A clean crate
//! (no warning, as a dependency under --cap-lints) with a path return type
//! and a typed `let` compiles under the driver, and its ret / local parts
//! carry short types.
use std::path::PathBuf;
use std::process::Command;
use mimir_driver::read_tables;
#[test]
fn a_clean_crate_with_path_types_compiles_under_the_driver() {
let work = PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join(format!("no-trimmed-ice-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&work);
std::fs::create_dir_all(work.join("src")).unwrap();
// toml_edit 0.25.15: one of the dependencies that ICEd rustc under the
// driver on dwarf (compiled with --cap-lints: no diagnostic at all)
std::fs::write(work.join("Cargo.toml"), "[package]\nname = \"clean\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[dependencies]\ntoml_edit = \"=0.25.15\"\n\n[workspace]\n").unwrap();
std::fs::write(
work.join("src/lib.rs"),
"//! A crate without one warning.\n\n/// A point.\npub struct Point {\n /// x\n pub x: u32,\n}\n\n/// Points by key.\npub fn make(n: u32) -> std::collections::BTreeMap<u32, Point> {\n let mut m: std::collections::BTreeMap<u32, Point> = std::collections::BTreeMap::new();\n let p = Point { x: n };\n m.insert(n, p);\n m\n}\n",
)
.unwrap();
let out = work.join("out");
let o = Command::new(env!("CARGO_BIN_EXE_cargo-mimir-dump"))
.current_dir(&work)
.args(["--out", out.to_str().unwrap(), "--driver", env!("CARGO_BIN_EXE_mimir-driver"), "--", "--workspace", "--all-targets", "--offline"])
.output()
.unwrap();
let err = String::from_utf8_lossy(&o.stderr);
assert!(o.status.success() && !err.contains("panicked"), "the compile under the driver failed:\n{err}");
let n = read_tables(&out, "nodes").unwrap();
let (kind, ty) = (n.col("kind"), n.col("ty"));
let (pkg, id) = (n.col("crate"), n.col("id"));
let mut ret: Vec<&String> = n.rows.iter().filter(|r| r[kind] == "ret" && r[pkg] == "clean" && r[id].contains("make")).map(|r| &r[ty]).collect();
ret.dedup();
let locals: Vec<&String> = n.rows.iter().filter(|r| r[kind] == "local" && r[pkg] == "clean").map(|r| &r[ty]).collect();
assert!(n.rows.iter().any(|r| r[pkg] == "toml_edit"), "toml_edit was dumped too");
assert_eq!(ret, vec!["BTreeMap<u32, Point>"], "the return type, short");
assert!(locals.contains(&&"BTreeMap<u32, Point>".to_string()) && locals.contains(&&"Point".to_string()), "{locals:?}");
let _ = std::fs::remove_dir_all(&work);
}