Skip to content

Commit ec5a78a

Browse files
committed
P-037 B1: dag.rs kernel guard reads metadata without indexing
The workspace denies clippy::indexing_slicing, and the B1 guard indexed the cargo metadata JSON directly. Use Value::get like the rest of the file. Test code only; no binary changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KmiyfrkaG9sJruTcshM2oq
1 parent 5c6207e commit ec5a78a

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

  • rust/crates/own-diagnostics/tests

‎rust/crates/own-diagnostics/tests/dag.rs‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,24 @@ fn all_deps() -> HashMap<String, BTreeSet<String>> {
297297
.expect("cargo metadata runs");
298298
let meta: Value = serde_json::from_slice(&out.stdout).expect("metadata JSON parses");
299299
let mut all = HashMap::new();
300-
for pkg in meta["packages"].as_array().expect("packages") {
301-
let deps = pkg["dependencies"].as_array().expect("dependencies array");
300+
for pkg in meta
301+
.get("packages")
302+
.and_then(Value::as_array)
303+
.expect("packages")
304+
{
305+
let deps = pkg
306+
.get("dependencies")
307+
.and_then(Value::as_array)
308+
.expect("dependencies array");
302309
let names = deps
303310
.iter()
304-
.filter_map(|d| d["name"].as_str())
311+
.filter_map(|d| d.get("name").and_then(Value::as_str))
305312
.map(str::to_owned);
306313
all.insert(
307-
pkg["name"].as_str().expect("pkg name").to_owned(),
314+
pkg.get("name")
315+
.and_then(Value::as_str)
316+
.expect("pkg name")
317+
.to_owned(),
308318
names.collect(),
309319
);
310320
}

0 commit comments

Comments
 (0)