guibiao 0.9.0

圭表 (Guibiao) — Tianheng's dependency-light static observation core (derived from modou). Declare crate, module, and dependency-source boundaries in Rust — dependencies by name, module imports, and each dependency's declared source kind (git/registry/path) for manifest hygiene — observed from cargo metadata and source use-scans, reacted in CI. No AST: the syn-free gnomon of the family.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
use super::helpers::*;
// --- external-crate confinement (`confine_external_crate`) ------------------------------

pub(super) fn confine(governed: &str, crate_name: &str) -> ModuleBoundary {
    ModuleBoundary::in_crate("x")
        .module(governed)
        .confine_external_crate(crate_name)
        .because("the platform vocabulary stays behind the ffi module")
}

/// An import of the confined crate inside a `#[path]`-remapped module is observed.
///
/// Kept for the CONTRACT rather than for a change: the behaviour is already correct, and this pins it
/// so `intent/external-crate-confinement.md` cannot drift away from it again. Its bound once listed
/// `#[path]`-remapped modules among the scanner's out-of-scope bounds long after the scanner began
/// following such a remap to its target, which would have let a reader dismiss a real escape here as
/// governed policy.
#[test]
pub(super) fn confine_observes_an_import_inside_a_path_remapped_module() {
    let (result, violations) = run_module_check(
        "confine-remapped",
        &[
            ("lib.rs", "pub mod ffi;\npub mod service;\n"),
            ("ffi.rs", "\n"),
            ("service.rs", "#[path = \"far.rs\"]\npub mod inner;\n"),
            ("far.rs", "use libc::c_int;\n"),
        ],
        confine("crate::ffi", "libc"),
    );
    assert!(result.is_ok(), "{result:?}");
    assert_eq!(violations.len(), 1, "{violations:?}");
    assert_eq!(violations[0].target(), "libc");
    assert!(
        violations[0].finding.contains("crate::service::inner"),
        "the finding must name the remapped module: {:?}",
        violations[0].finding
    );
}

#[test]
pub(super) fn confine_flags_an_external_import_outside_the_subtree() {
    // The confined crate is the target; the offending importer module is the finding.
    let (result, violations) = run_module_check(
        "confine-outside",
        &[
            ("lib.rs", "pub mod ffi;\npub mod service;\n"),
            ("ffi.rs", "\n"),
            ("service.rs", "use libc::c_int;\n"),
        ],
        confine("crate::ffi", "libc"),
    );
    assert!(result.is_ok(), "{result:?}");
    assert_eq!(violations.len(), 1, "{violations:?}");
    assert_eq!(violations[0].target(), "libc");
    assert_eq!(violations[0].finding, "crate::service");
    let file = violations[0].file.as_deref().expect("carries its file");
    assert!(file.ends_with("service.rs"), "names the offender: {file}");
}

#[test]
pub(super) fn confine_is_clean_within_the_subtree() {
    let (result, violations) = run_module_check(
        "confine-within",
        &[
            ("lib.rs", "pub mod ffi;\n"),
            ("ffi.rs", "use libc::c_int;\n"),
        ],
        confine("crate::ffi", "libc"),
    );
    assert!(result.is_ok(), "{result:?}");
    assert!(
        violations.is_empty(),
        "within the subtree is clean: {violations:?}"
    );
}

#[test]
pub(super) fn confine_allows_beneath_the_subtree() {
    let (result, violations) = run_module_check(
        "confine-beneath",
        &[
            ("lib.rs", "pub mod ffi;\n"),
            ("ffi.rs", "pub mod raw;\n"),
            ("ffi/raw.rs", "use libc::c_int;\n"),
        ],
        confine("crate::ffi", "libc"),
    );
    assert!(result.is_ok(), "{result:?}");
    assert!(
        violations.is_empty(),
        "a module beneath the permitted subtree is clean: {violations:?}"
    );
}

#[test]
pub(super) fn confine_flags_a_prefix_colliding_sibling_of_the_subtree() {
    // `crate::ffi_utils` is neither `crate::ffi` nor beneath `crate::ffi::` (`::`-delimited).
    let (result, violations) = run_module_check(
        "confine-sibling",
        &[
            ("lib.rs", "pub mod ffi;\npub mod ffi_utils;\n"),
            ("ffi.rs", "\n"),
            ("ffi_utils.rs", "use libc::c_int;\n"),
        ],
        confine("crate::ffi", "libc"),
    );
    assert!(result.is_ok(), "{result:?}");
    assert_eq!(violations.len(), 1, "{violations:?}");
    assert_eq!(violations[0].finding, "crate::ffi_utils");
}

#[test]
pub(super) fn confine_observes_a_glob_and_a_bare_import() {
    let (result, violations) = run_module_check(
        "confine-glob",
        &[
            ("lib.rs", "pub mod ffi;\npub mod a;\npub mod b;\n"),
            ("ffi.rs", "\n"),
            ("a.rs", "use libc::*;\n"),
            ("b.rs", "use libc;\n"),
        ],
        confine("crate::ffi", "libc"),
    );
    assert!(result.is_ok(), "{result:?}");
    let findings: Vec<&str> = violations.iter().map(|v| v.finding.as_str()).collect();
    assert_eq!(violations.len(), 2, "{violations:?}");
    assert!(
        findings.contains(&"crate::a") && findings.contains(&"crate::b"),
        "{findings:?}"
    );
}

#[test]
pub(super) fn confine_ignores_a_different_external_crate() {
    let (result, violations) = run_module_check(
        "confine-other-crate",
        &[
            ("lib.rs", "pub mod ffi;\npub mod service;\n"),
            ("ffi.rs", "\n"),
            ("service.rs", "use serde::Deserialize;\n"),
        ],
        confine("crate::ffi", "libc"),
    );
    assert!(result.is_ok(), "{result:?}");
    assert!(
        violations.is_empty(),
        "the rule observes only the confined crate: {violations:?}"
    );
}

#[test]
pub(super) fn confine_of_an_unimported_crate_is_clean_with_no_error() {
    // No cargo-metadata cross-check: confining a crate the target never imports is clean,
    // exactly as forbidding a crate you do not depend on is clean — never a constitution error.
    let (result, violations) = run_module_check(
        "confine-unimported",
        &[
            ("lib.rs", "pub mod ffi;\npub mod service;\n"),
            ("ffi.rs", "\n"),
            ("service.rs", "use serde::Deserialize;\n"),
        ],
        confine("crate::ffi", "libc"),
    );
    assert!(
        result.is_ok(),
        "no error for an unimported confined crate: {result:?}"
    );
    assert!(violations.is_empty(), "{violations:?}");
}

#[test]
pub(super) fn confine_resolves_a_shadowing_root_module_as_internal_no_false_positive() {
    // A crate-root `mod libc;` shadows the extern prelude, so a root-file bare `use libc::…`
    // is the INTERNAL `crate::libc`, not the external crate — the external scan must not
    // observe it, or the rule would false-positive against the crate's own module.
    let (result, violations) = run_module_check(
        "confine-shadow",
        &[
            ("lib.rs", "pub mod libc;\npub mod ffi;\nuse libc::helper;\n"),
            ("libc.rs", "pub fn helper() {}\n"),
            ("ffi.rs", "\n"),
        ],
        confine("crate::ffi", "libc"),
    );
    assert!(result.is_ok(), "{result:?}");
    assert!(
        violations.is_empty(),
        "a shadowing root module resolves internal, not as the confined external crate: {violations:?}"
    );
}

#[test]
pub(super) fn confine_observes_submodule_bare_and_leading_colon_forms() {
    let (result, violations) = run_module_check(
        "confine-forms",
        &[
            ("lib.rs", "pub mod ffi;\npub mod service;\npub mod other;\n"),
            ("ffi.rs", "\n"),
            ("service.rs", "use libc::c_int;\n"),
            ("other.rs", "use ::libc::c_void;\n"),
        ],
        confine("crate::ffi", "libc"),
    );
    assert!(result.is_ok(), "{result:?}");
    let findings: Vec<&str> = violations.iter().map(|v| v.finding.as_str()).collect();
    assert_eq!(violations.len(), 2, "{violations:?}");
    assert!(
        findings.contains(&"crate::service") && findings.contains(&"crate::other"),
        "both a submodule-bare and a leading-`::` external import are observed: {findings:?}"
    );
}

/// `use libc as _;` imports the confined crate and binds no name, which is still an import of `libc` outside the
/// permitted module.
#[test]
pub(super) fn confine_observes_a_use_aliased_to_underscore() {
    let (result, violations) = run_module_check(
        "confine-as-underscore",
        &[
            ("lib.rs", "pub mod ffi;\npub mod service;\n"),
            ("ffi.rs", "\n"),
            ("service.rs", "#[allow(unused_imports)]\nuse libc as _;\n"),
        ],
        confine("crate::ffi", "libc"),
    );
    assert!(result.is_ok(), "{result:?}");
    let findings: Vec<&str> = violations.iter().map(|v| v.finding.as_str()).collect();
    assert_eq!(findings, ["crate::service"], "{violations:?}");
}

/// A `use` inside a string literal or a macro body is not an import: a string literal is one literal token, and no
/// `use` reader records a `use` written inside a macro's group — a `macro_rules!` definition or an invocation.
#[test]
pub(super) fn confine_ignores_a_use_inside_a_string_literal_or_macro_body() {
    for (name, service) in [
        (
            "confine-string",
            "pub fn f() { let _s = \"use libc::c_int;\"; }\n",
        ),
        (
            "confine-macro-rules",
            "macro_rules! m { () => { use libc::c_int; }; }\n",
        ),
        ("confine-macro-call", "some_macro! { use libc::c_int; }\n"),
    ] {
        let (result, violations) = run_module_check(
            name,
            &[
                ("lib.rs", "pub mod ffi;\npub mod service;\n"),
                ("ffi.rs", "\n"),
                ("service.rs", service),
            ],
            confine("crate::ffi", "libc"),
        );
        assert!(result.is_ok(), "{name}: {result:?}");
        assert!(violations.is_empty(), "{name}: no use: {violations:?}");
    }
}

#[test]
pub(super) fn confine_dedups_multiple_imports_from_one_importer() {
    let (result, violations) = run_module_check(
        "confine-dedup",
        &[
            ("lib.rs", "pub mod ffi;\npub mod service;\n"),
            ("ffi.rs", "\n"),
            ("service.rs", "use libc::c_int;\nuse libc::c_void;\n"),
        ],
        confine("crate::ffi", "libc"),
    );
    assert!(result.is_ok(), "{result:?}");
    assert_eq!(
        violations.len(),
        1,
        "one importer importing the confined crate twice yields one violation: {violations:?}"
    );
}

#[test]
pub(super) fn confine_identity_is_injective_across_confined_crates() {
    // The highest-risk invariant: two confinements of different crates on the same subtree,
    // breached by the same importer, must NOT collapse — baselining one must not mask the
    // other. Injectivity comes from the target being the confined crate.
    let files = [
        ("lib.rs", "pub mod ffi;\npub mod service;\n"),
        ("ffi.rs", "\n"),
        ("service.rs", "use libc::c_int;\nuse winapi::HANDLE;\n"),
    ];
    let (r1, libc_v) = run_module_check("confine-inj-libc", &files, confine("crate::ffi", "libc"));
    let (r2, winapi_v) = run_module_check(
        "confine-inj-winapi",
        &files,
        confine("crate::ffi", "winapi"),
    );
    assert!(r1.is_ok() && r2.is_ok(), "{r1:?} {r2:?}");
    assert_eq!(libc_v.len(), 1, "{libc_v:?}");
    assert_eq!(winapi_v.len(), 1, "{winapi_v:?}");
    assert_eq!(libc_v[0].target(), "libc");
    assert_eq!(winapi_v[0].target(), "winapi");
    assert_eq!(
        libc_v[0].finding, winapi_v[0].finding,
        "same offending importer — only the target (confined crate) differs"
    );
    // Baseline only the libc violation; the winapi violation must still react.
    let baseline = Baseline::of(&Report::new(libc_v.clone()));
    let mut both = Report::new(vec![libc_v[0].clone(), winapi_v[0].clone()]);
    apply_baseline(&mut both, &baseline);
    assert!(both.violations[0].baselined, "libc is baselined");
    assert!(
        !both.violations[1].baselined,
        "winapi is NOT masked by libc's baseline — distinct target keeps identity injective"
    );
    assert_eq!(
        Outcome::Violations(both).exit_code(),
        1,
        "the new winapi violation still fails"
    );
}

#[test]
pub(super) fn confine_canonicalizes_a_raw_identifier_crate_name() {
    // The confined crate name and the observed head canonicalize (`r#name` -> `name`), so a
    // boundary written with either form matches an import written with either form.
    let (result, violations) = run_module_check(
        "confine-raw-id",
        &[
            ("lib.rs", "pub mod ffi;\npub mod service;\n"),
            ("ffi.rs", "\n"),
            ("service.rs", "use r#async::spawn;\n"),
        ],
        confine("crate::ffi", "async"),
    );
    assert!(result.is_ok(), "{result:?}");
    assert_eq!(
        violations.len(),
        1,
        "raw and plain crate-name forms are one identity: {violations:?}"
    );
    assert_eq!(violations[0].target(), "async");
}

#[test]
pub(super) fn confine_on_the_crate_root_is_a_constitution_error() {
    let (result, _violations) = run_module_check(
        "confine-on-crate",
        &[("lib.rs", "use libc::c_int;\n")],
        confine("crate", "libc"),
    );
    let err = result.expect_err("confining to the crate root is a constitution error");
    assert_eq!(err, confine_external_crate_on_crate_error("x"));
}

#[test]
pub(super) fn confine_unknown_subtree_is_a_constitution_error() {
    let (result, _violations) = run_module_check(
        "confine-unknown",
        &[("lib.rs", "pub mod ffi;\n"), ("ffi.rs", "\n")],
        confine("crate::nope", "libc"),
    );
    let err = result.expect_err("an unreachable permitted subtree is a constitution error");
    assert_eq!(err, unknown_module_error("crate::nope", "x"));
}

#[test]
pub(super) fn confine_honors_warn_severity() {
    let boundary = ModuleBoundary::in_crate("x")
        .module("crate::ffi")
        .confine_external_crate("libc")
        .warn()
        .because("advisory during adoption");
    let (result, violations) = run_module_check(
        "confine-warn",
        &[
            ("lib.rs", "pub mod ffi;\npub mod service;\n"),
            ("ffi.rs", "\n"),
            ("service.rs", "use libc::c_int;\n"),
        ],
        boundary,
    );
    assert!(result.is_ok(), "{result:?}");
    assert_eq!(violations.len(), 1, "{violations:?}");
    assert_eq!(violations[0].severity, Severity::Warn);
    assert_eq!(
        Outcome::Violations(Report::new(violations)).exit_code(),
        0,
        "a warn-only confinement does not fail CI"
    );
}

#[test]
pub(super) fn confine_external_crate_rule_text_and_json_params() {
    let rule = ModuleRule::ConfineExternalCrate {
        crate_name: "libc".to_string(),
    };
    assert_eq!(rule.label(), "external crate confined to module");
    assert_eq!(rule.polarity(), Polarity::AllowlistGap);
    assert_eq!(
        rule.text(),
        "confines external crate libc to this module's subtree"
    );
    assert_eq!(
        rule.json_params(),
        vec![("external_crate", serde_json::json!("libc"))]
    );
}

#[test]
pub(super) fn confine_external_crate_projects_its_crate_and_subtree() {
    // The full constitution projection (not just the rule params): the declared module
    // subtree and the confined crate must both be legible without reading the rule label.
    let constitution = Constitution::new("p").boundary(
        ModuleBoundary::in_crate("app")
            .module("crate::ffi")
            .confine_external_crate("libc")
            .because("the raw libc surface stays behind the ffi module"),
    );

    let text = constitution_text(&constitution);
    assert!(
        text.contains("crate::ffi"),
        "the declared subtree is named: {text}"
    );
    assert!(
        text.contains("confines external crate libc"),
        "the confined crate is named: {text}"
    );

    let doc: serde_json::Value = serde_json::from_str(&constitution_json(&constitution)).unwrap();
    assert_eq!(
        doc["boundaries"][0]["rule"],
        "external crate confined to module"
    );
    // The declared module subtree is the boundary target (declaration view); the confined
    // crate projects under the self-describing `external_crate` key.
    assert_eq!(doc["boundaries"][0]["target"], "crate::ffi");
    assert_eq!(doc["boundaries"][0]["external_crate"], "libc");
    assert!(doc["boundaries"][0]["forbidden"].is_null());
    assert!(doc["boundaries"][0]["only"].is_null());
}

#[test]
pub(super) fn confine_matches_a_hyphenated_package_name_against_its_underscore_identifier() {
    // A package with a `-` (e.g. `windows-sys`) is imported through its `_` identifier
    // (`use windows_sys::…`) — a `use` path cannot contain `-`. The confined name is written in
    // package form yet must match the identifier the scanner observes, or the rule would silently
    // never react for exactly the hyphenated FFI/platform crates it targets (a false negative).
    let (result, violations) = run_module_check(
        "confine-hyphen",
        &[
            ("lib.rs", "pub mod ffi;\npub mod service;\n"),
            ("ffi.rs", "\n"),
            (
                "service.rs",
                "use windows_sys::Win32::Foundation::HANDLE;\n",
            ),
        ],
        confine("crate::ffi", "windows-sys"),
    );
    assert!(result.is_ok(), "{result:?}");
    assert_eq!(
        violations.len(),
        1,
        "a hyphenated package name matches its underscore import identifier: {violations:?}"
    );
    assert_eq!(violations[0].target(), "windows_sys");
    assert_eq!(violations[0].finding, "crate::service");
}

#[test]
pub(super) fn confine_observes_an_aliased_import_of_the_confined_crate() {
    // `use libc as c;` still imports libc; the alias is dropped at expansion, so the confined
    // crate's head is observed regardless of a local rename.
    let (result, violations) = run_module_check(
        "confine-alias",
        &[
            ("lib.rs", "pub mod ffi;\npub mod service;\n"),
            ("ffi.rs", "\n"),
            ("service.rs", "use libc as c;\n"),
        ],
        confine("crate::ffi", "libc"),
    );
    assert!(result.is_ok(), "{result:?}");
    assert_eq!(
        violations.len(),
        1,
        "an aliased import is still observed: {violations:?}"
    );
    assert_eq!(violations[0].target(), "libc");
    assert_eq!(violations[0].finding, "crate::service");
}

// The fourth inherited bound this capability's intent names, declared and pinned rather than left only in
// prose. The intent item and typed register now name the same bound.
//
// Probed before it was declared: the assertion here is that `extern crate libc;` outside the permitted
// subtree yields no violation, which is the scanner's use-only behaviour rather than a reasoned claim.
#[test]
pub(super) fn confine_ignores_an_extern_crate_declaration() {
    let (result, violations) = run_module_check(
        "confine-extern-crate",
        &[
            ("lib.rs", "pub mod ffi;\npub mod service;\n"),
            ("ffi.rs", "\n"),
            ("service.rs", "extern crate libc;\n"),
        ],
        confine("crate::ffi", "libc"),
    );
    assert!(result.is_ok(), "{result:?}");
    assert!(
        violations.is_empty(),
        "the rule is use-only: an `extern crate` declaration is not observed: {violations:?}"
    );
}

#[test]
pub(super) fn confine_external_crate_is_cfg_blind_to_unenabled_cfg_arms() {
    let (result, violations) = run_module_check(
        "confine-cfg-blind",
        &[
            ("lib.rs", "pub mod ffi;\npub mod service;\n"),
            ("ffi.rs", "\n"),
            (
                "service.rs",
                "#[cfg(impossible_predicate)]\nuse libc::c_int;\n",
            ),
        ],
        confine("crate::ffi", "libc"),
    );
    assert!(result.is_ok(), "{result:?}");
    assert_eq!(violations.len(), 1, "{violations:?}");
    assert_eq!(violations[0].target(), "libc");
    assert_eq!(violations[0].finding, "crate::service");
}

/// A module governed by name alone (`crate::bad`) is reachable from two separate compilation units — a
/// `lib` and a `bin` target sharing one `src/` directory, each with its own conventional `mod bad;` that
/// resolves to the identical physical file — and the confinement violation each unit's own copy carries
/// is reported once per unit, not conflated into one and not silently dropped for either.
///
/// This is the real hazard the previous, misleadingly-named occupant of this test claimed to guard:
/// its own fixture declared no `bin` target at all (`TempWorkspace::metadata` only ever emits one `lib`
/// target) and was byte-for-byte the same fixture as
/// [`confine_flags_an_external_import_outside_the_subtree`] above, adding no coverage beyond it under a
/// name that promised otherwise. `check_module_boundary`'s per-root evaluation (each root walked as its
/// own corpus, sibling roots excluded from each other's file set) already gets this right; this pins it.
#[test]
pub(super) fn confine_external_crate_evaluates_each_unit_at_a_coincident_conventional_path() {
    let ws = TempWorkspace::new("confine-lib-bin-coincident");
    ws.write("lib.rs", "pub mod ffi;\npub mod bad;\n");
    ws.write("main.rs", "pub mod ffi;\npub mod bad;\nfn main() {}\n");
    ws.write("ffi.rs", "\n");
    ws.write("bad.rs", "use libc::c_int;\n");
    let metadata = serde_json::json!({
        "packages": [{
            "name": "x",
            "targets": [
                { "kind": ["lib"], "src_path": ws.src().join("lib.rs").to_string_lossy() },
                { "kind": ["bin"], "src_path": ws.src().join("main.rs").to_string_lossy() },
            ],
        }],
    });
    let mut violations = Vec::new();
    let result = check_module_boundary(&metadata, &confine("crate::ffi", "libc"), &mut violations);
    assert!(result.is_ok(), "{result:?}");
    assert_eq!(
        violations.len(),
        2,
        "the coincident-path leak exists once per compilation unit and must be reported for each, \
         not merged into one and not dropped for either: {violations:?}"
    );
    let units: std::collections::BTreeSet<String> = violations
        .iter()
        .map(|v| {
            v.fact().to_json()["fields"]["unit"]
                .as_str()
                .expect("unit is a string")
                .to_string()
        })
        .collect();
    assert_eq!(
        units,
        std::collections::BTreeSet::from(["lib.rs".to_string(), "main.rs".to_string()]),
        "each unit's own copy of the leak must carry that unit's own label: {violations:?}"
    );
}