requirements.references.procedure
Requirements index · View definition
Requirement
A source item MUST choose its references under
for each candidate definition by this procedure, and MAY carry several:
- If the item is a test designed to verify the definition, it MUST use
{test}. A test helper a reviewer reaches by following such a test needs no reference to the definition.- Otherwise, if the item is a root of the definition’s implementation, it MUST use
{impl}. Code or a type carries out part of a definition when it makes a decision, performs a check, produces an output, or handles a case the definition specifies, or when the definition constrains its shape: fields, variants, serialized form, or validation. A root is such an item that no other item marked{impl}for the definition reaches, where an item reaches what it calls, the types it uses, and the implementations of trait methods it calls, and what those reach in turn. An item reached from a root needs no reference to the definition. An item that is a site of a distributed definition underneeds no reference to it; its site review covers it.
- Otherwise, if the item should be re-checked or kept in sync when the definition changes, it MUST use
{cite}.- If the item carries no reference after applying steps 1 to 3 to every definition and no assessment reads it under
, it MUST cite the built-in
habeas:utilunderwhen it serves other code. An item that does neither carries out behavior that needs a requirement, or is not needed.
A
{fixme}reference is added independently of this procedure, and MUST NOT count as an item’s reference for.
Rationale
Verdict. The five {test} items for requirements.references.procedure cover the parts of the procedure that validation can check mechanically. I found no unacknowledged gap.
What the procedure requires.
- Step 1: a test MUST use
{test}. A test helper needs no reference. - Steps 2 and 3: a root of an implementation uses
{impl}, and otherwise an item that should be kept in sync uses{cite}. - Step 4: an item with no other reference cites
habeas:util. - A
{fixme}MUST NOT count as a reference for coverage.
What the implementation checks. The {impl} sites are src/rust_coverage.rs#fn[unreferenced_items] and src/rust_coverage.rs#fn[validate_rust_functions]. They enforce two things:
- A test function without
{test}is a validation error. - Any other item with no valid reference,
habeas:utilcitation or recent evidence read is reported as uncovered.
Choosing between {impl} roots, reachability and {cite} is a judgment made in review. Nothing in the code checks it, so it has no mechanical test to ask for.
Mapping obligations to tests.
- Step 1,
{test}required.src/rust_coverage.rs#mod[tests]/fn[test_functions_need_a_test_reference]asserts the exact list of flagged names. A{test}before the function or inside its body is accepted, sotestedandtested_in_bodyare not flagged.untested,only_cited(only{cite}),untested_async(#[tokio::test(...)]) andnested_untestedare flagged.#[cfg(test)]and#[rstest]items are not treated as tests.tests/coverage.rs#fn[a_test_without_a_test_reference_fails_validation_even_in_mod_tests]asserts the full validation error forchecksinmod tests. It also asserts that the helperfixturein the same module gets no error and no warning, which covers “a helper needs no reference”.
- Step 4 and the other coverage rules.
tests/references.rs#fn[fenced_references_in_comments_and_built_in_rules_are_validated]asserts the following:- A fenced
habeas:utilcitation covers its function (glue). - An inline reference inside a fence body also covers its function (
empty). - Invalid citations leave items uncovered. These are unknown or removed built-ins, a wrong role, and an unclosed fence.
- Only valid citations other than
habeas:utilneed a citation review.
- A fenced
{fixme}is not a reference.tests/references.rs#fn[a_fixme_does_not_count_as_an_items_reference]covers a named{fixme}and an unnamed:::{fixme}with only:github:. Each leaves its function with a “no recent coverage” error. The same fixme next to a real{impl}leaves the function covered.- Coverage through evidence reads.
tests/references.rs#fn[items_named_by_recent_evidence_have_recent_coverage_whatever_their_hash]shows that outline inputs from evidence records, citation reviews and site reviews cover items, including methods in a read impl block and stale hashes. Only the unread function is reported.
Residual notes.
- A plain inline
{cite}ofhabeas:utilis not exercised in these particular tests. Therequirements.references.utilrequirement owns that behavior and its tests. - Whether a root
{impl}or a{cite}is the right reference for a given item is a review judgment. It is not delegated to these tests.
Inputs
Implementation
Input 11: outline src/rust_coverage.rs fn[validate_rust_functions]
- File:
src/rust_coverage.rs - Selector:
fn[validate_rust_functions] - Kind:
fn src/rust_coverage.rs:475–554
// {impl}`requirements.ci.errors`
// {impl}`requirements.references.procedure`
pub(crate) fn validate_rust_functions(
root: &Path,
sources: &[PathBuf],
definitions: &BTreeMap<String, Declaration>,
reads: &EvidenceReads,
errors: &mut Vec<String>,
discovery_errors: &mut Vec<String>,
progress: &mut impl FnMut(InspectionProgress),
) -> Vec<UncoveredItem> {
let mut uncovered = Vec::new();
progress(InspectionProgress {
stage: RUST_COVERAGE_STAGE,
completed: 0,
total: None,
});
let files = rust_files(root, sources);
let total = files.len();
for (completed, file) in files.into_iter().enumerate() {
progress(InspectionProgress {
stage: RUST_COVERAGE_STAGE,
completed,
total: Some(total),
});
let label = display_path(root, &file);
let source = match fs::read_to_string(&file) {
Ok(source) => source,
Err(error) => {
let error = format!("{label}: cannot read Rust source: {error}");
discovery_errors.push(error.clone());
errors.push(error);
continue;
}
};
match unreferenced_items(&source, definitions) {
Ok((outline, missing)) => {
// Only a test without `{test}` fails validation; other items
// without coverage are reported, not errors.
// {impl}`requirements.references.coverage.tests`
let untested = untested_tests(&source, &outline, definitions);
for (_, line, name) in &untested {
errors.push(format!(
"{label}:{line}: test function {name} has no {{test}} reference to a requirement or example"
));
}
for (index, line, kind, name) in missing {
// A test without `{test}` is already a validation error,
// so it is not also a coverage warning.
if reads.covers(&label, &outline, index)
|| untested.iter().any(|(node, _, _)| *node == index)
{
continue;
}
uncovered.push(UncoveredItem {
file: label.clone(),
selectors: crate::coverage_history::enclosing_selectors(&outline, index),
error: uncovered_error(&label, line, kind, &name),
in_tests: crate::coverage_history::in_tests_module(&outline, index)
|| crate::coverage_history::in_tests_file(Path::new(&label)),
});
}
}
Err(error) => {
let error = format!(
"{label}:{}: cannot parse Rust source: {}",
error.line, error.message
);
discovery_errors.push(error.clone());
errors.push(error);
}
}
}
progress(InspectionProgress {
stage: RUST_COVERAGE_STAGE,
completed: total,
total: Some(total),
});
uncovered
}
Input 12: outline src/rust_coverage.rs fn[unreferenced_items]
- File:
src/rust_coverage.rs - Selector:
fn[unreferenced_items] - Kind:
fn src/rust_coverage.rs:333–378
/// The functions, methods, structs, enums, and unions of a Rust source with
/// no valid reference in a comment belonging to them, with the source's
/// outline.
// {impl}`requirements.references.builtin_definitions`
// {impl}`requirements.references.procedure`
// {impl}`requirements.references.outline_comments`
// {impl}`requirements.references.roles`
// {impl}`requirements.definitions.references`
// {impl}`requirements.references.util`
pub(crate) fn unreferenced_items(
source: &str,
definitions: &BTreeMap<String, Declaration>,
) -> Result<(outline::Outline, Unreferenced), OutlineError> {
let outline = outline::parse_with(&outline::RUST_PROFILE, source)?;
let mut cited = vec![false; outline.nodes.len()];
let counts =
|kind: crate::ReferenceKind, name: &str| covering_reference(kind, name, definitions);
for comment in &outline.comments {
if reference_roles(&source[comment.byte_start..comment.byte_end], false)
.iter()
.any(|role| counts(role.kind, role.name))
{
cited[comment.owner] = true;
}
}
for fence in crate::fenced::comment_fences(source, &outline) {
if let Some(owner) = fence.owner
&& fence.closed
&& counts(fence.kind, &fence.name)
{
cited[owner] = true;
}
}
let missing = outline
.nodes
.iter()
.zip(cited)
.enumerate()
.filter_map(|(index, (node, cited))| {
let kind = item_kind(node.kind)?;
let name = node.display_name()?;
(!cited).then_some((index, node.declaration_line, kind, name))
})
.collect();
Ok((outline, missing))
}
Tests
Input 6: outline src/rust_coverage.rs mod[tests]/fn[test_functions_need_a_test_reference]
- File:
src/rust_coverage.rs - Selector:
mod[tests]/fn[test_functions_need_a_test_reference] - Kind:
fn src/rust_coverage.rs:710–738
// {test}`requirements.references.coverage.tests`
// {test}`requirements.references.procedure`
#[test]
fn test_functions_need_a_test_reference() {
let source = concat!(
"// {test}`requirements.example`\n#[test]\nfn tested() {}\n\n",
"#[test]\nfn tested_in_body() {\n // {test}`requirements.example`\n}\n\n",
"#[test]\nfn untested() {}\n\n",
"// {cite}`requirements.example`\n#[tokio::test]\nasync fn only_cited() {}\n\n",
"#[tokio::test(flavor = \"multi_thread\")]\nasync fn untested_async() {}\n\n",
"#[cfg(test)]\nfn not_a_test() {}\n\n",
"#[rstest]\nfn other_attribute() {}\n\n",
"mod tests {\n #[test]\n fn nested_untested() {}\n}\n",
);
let outline = crate::outline::parse_with(&crate::outline::RUST_PROFILE, source).unwrap();
let names: Vec<String> = super::untested_tests(source, &outline, &definitions())
.into_iter()
.map(|(_, _, name)| name)
.collect();
assert_eq!(
names,
[
"untested",
"only_cited",
"untested_async",
"nested_untested"
]
);
}
Input 7: outline tests/coverage.rs fn[a_test_without_a_test_reference_fails_validation_even_in_mod_tests]
- File:
tests/coverage.rs - Selector:
fn[a_test_without_a_test_reference_fails_validation_even_in_mod_tests] - Kind:
fn tests/coverage.rs:296–321
// {test}`requirements.references.coverage.tests`
// {test}`requirements.references.coverage.test_module`
// {test}`requirements.references.procedure`
#[test]
fn a_test_without_a_test_reference_fails_validation_even_in_mod_tests() {
let temp = project();
let root = temp.path();
fs::write(
root.join("src/lib.rs"),
"fn parse() {}\n\nmod tests {\n fn fixture() {}\n\n #[test]\n fn checks() {}\n}\n",
)
.unwrap();
commit(root, "first");
let errors = habeas::validate_repository(root).unwrap().errors;
assert!(
errors.iter().any(|error| error
== "src/lib.rs:7: test function checks has no {test} reference to a requirement or example"),
"{errors:#?}"
);
// The helper in `mod tests` is neither an error nor a warning.
assert!(
!errors.iter().any(|error| error.contains("fixture")),
"{errors:#?}"
);
assert_eq!(warned(root), ["parse"]);
}
Input 8: outline tests/references.rs fn[fenced_references_in_comments_and_built_in_rules_are_validated]
- File:
tests/references.rs - Selector:
fn[fenced_references_in_comments_and_built_in_rules_are_validated] - Kind:
fn tests/references.rs:72–129
// {test}`requirements.references.roles`
// {test}`requirements.references.builtin_definitions`
// {test}`requirements.references.rust_item_coverage`
// {test}`requirements.references.procedure`
// {test}`requirements.references.util`
#[test]
fn fenced_references_in_comments_and_built_in_rules_are_validated() {
let temp = project();
let root = temp.path();
let cr = role("cite");
let source = format!(
"// :::{cr} habeas:util\n// Glue that formats output.\n// :::\nfn glue() {{}}\n\n\
// {cr}`habeas:none`\nfn inline() {{}}\n\n\
// :::{cr} habeas:util\n// {cr}`rules.ready`\n// :::\nfn empty() {{}}\n\n\
// :::{im} habeas:util\n// Wrong role.\n// :::\nfn wrong_role() {{}}\n\n\
// :::{cr} habeas:other\n// Unknown.\n// :::\nfn unknown() {{}}\n\n\
// :::{cr} rules.ready\n// never closed\n\n// :::\nfn unclosed() {{}}\n\n\
// :::{cr} habeas:none\n// Formats output.\n// :::\nfn fenced_none() {{}}\n",
im = role("impl"),
);
fs::write(root.join("src/lib.rs"), source).unwrap();
let errors = errors(root);
for expected in [
// `habeas:none` was removed: it is an unknown name in either form.
"src/lib.rs:6: {cite}`habeas:none` has no matching built-in definition",
"src/lib.rs:30: {cite}`habeas:none` has no matching built-in definition",
"src/lib.rs:14: built-in habeas:util may only be referenced with {cite}",
"src/lib.rs:19: {cite}`habeas:other` has no matching built-in definition",
"src/lib.rs:24: fenced {cite} reference to rules.ready has no closing fence",
"src/lib.rs:7: function inline has no recent coverage: it has no requirement or example reference, and no recent evidence record or review read it",
"src/lib.rs:17: function wrong_role has no recent coverage: it has no requirement or example reference, and no recent evidence record or review read it",
"src/lib.rs:22: function unknown has no recent coverage: it has no requirement or example reference, and no recent evidence record or review read it",
"src/lib.rs:28: function unclosed has no recent coverage: it has no requirement or example reference, and no recent evidence record or review read it",
"src/lib.rs:33: function fenced_none has no recent coverage: it has no requirement or example reference, and no recent evidence record or review read it",
] {
assert!(has(&errors, expected), "missing {expected:?}: {errors:#?}");
}
// A fenced citation of habeas:util covers its function, as does an
// inline reference in a fence body.
assert!(!has(&errors, "function glue"), "{errors:#?}");
assert!(!has(&errors, "function empty"), "{errors:#?}");
// Only valid citations other than habeas:util need reviews.
assert!(has(
&errors,
"missing citation review for src/lib.rs fn[empty]"
));
for item in ["glue", "inline", "fenced_none"] {
assert!(
!has(
&errors,
&format!("missing citation review for src/lib.rs fn[{item}]")
),
"{errors:#?}"
);
}
// Built-ins need no evidence.
assert!(!has(&errors, "evidence/habeas:"), "{errors:#?}");
}
Input 9: outline tests/references.rs fn[a_fixme_does_not_count_as_an_items_reference]
- File:
tests/references.rs - Selector:
fn[a_fixme_does_not_count_as_an_items_reference] - Kind:
fn tests/references.rs:363–389
// {test}`requirements.references.procedure`
// {test}`requirements.references.rust_item_coverage`
// {test}`requirements.references.roles`
#[test]
fn a_fixme_does_not_count_as_an_items_reference() {
let temp = project();
let root = temp.path();
let fx = role("fixme");
fs::write(
root.join("src/lib.rs"),
format!(
"// :::{fx} rules.ready\n// The gap.\n// :::\nfn gap() {{}}\n\n\
// :::{fx}\n// :github: example/rules#1\n// :::\nfn tracked() {{}}\n\n\
// {}`rules.ready`\n// :::{fx} rules.ready\n// Another gap.\n// :::\nfn implemented() {{}}\n",
role("impl")
),
)
.unwrap();
let errors = errors(root);
for expected in [
"src/lib.rs:4: function gap has no recent coverage: it has no requirement or example reference, and no recent evidence record or review read it",
"src/lib.rs:9: function tracked has no recent coverage: it has no requirement or example reference, and no recent evidence record or review read it",
] {
assert!(has(&errors, expected), "missing {expected:?}: {errors:#?}");
}
assert!(!has(&errors, "function implemented"), "{errors:#?}");
}
Input 10: outline tests/references.rs fn[items_named_by_recent_evidence_have_recent_coverage_whatever_their_hash]
- File:
tests/references.rs - Selector:
fn[items_named_by_recent_evidence_have_recent_coverage_whatever_their_hash] - Kind:
fn tests/references.rs:801–862
// {test}`requirements.references.rust_item_coverage`
// {test}`requirements.references.coverage.history`
// {test}`requirements.references.procedure`
#[test]
fn items_named_by_recent_evidence_have_recent_coverage_whatever_their_hash() {
let temp = project();
let root = temp.path();
let source = "fn read_directly() {}\n\nstruct Thing;\n\nimpl Thing {\n fn method(&self) {}\n}\n\nfn changed() {}\n\nfn unread() {}\n";
fs::write(root.join("src/lib.rs"), source).unwrap();
let input = |item: &str| habeas::outline_input(root, "src/lib.rs", item).unwrap();
let mut stale = input("fn[changed]");
stale["hash"] = json!("0".repeat(64));
// An ordinary record reads one item; a citation review reads the impl
// block containing a method; a site review records a stale hash.
fs::write(
root.join("evidence/rules.ready.json"),
json!({"inputs": [input("fn[read_directly]")]}).to_string(),
)
.unwrap();
fs::create_dir_all(root.join("evidence/citations/src/lib.rs")).unwrap();
fs::write(
root.join("evidence/citations/src/lib.rs/struct[Thing].json"),
json!({"inputs": [input("impl[Thing]"), input("struct[Thing]")]}).to_string(),
)
.unwrap();
fs::create_dir_all(root.join("evidence/sites/rules.ready/src/lib.rs")).unwrap();
fs::write(
root.join("evidence/sites/rules.ready/src/lib.rs/fn[changed].json"),
json!({"inputs": [stale]}).to_string(),
)
.unwrap();
let uncovered = |errors: &[String]| {
errors
.iter()
.filter(|error| error.contains(" has no recent coverage: "))
.map(|error| error.split(':').take(3).collect::<Vec<_>>().join(":"))
.collect::<Vec<_>>()
};
// Recent coverage names a node by file and selector, whatever hash a
// record gave it: a stale hash still covers it.
let found = errors(root);
assert_eq!(
uncovered(&found),
["src/lib.rs:11: function unread has no recent coverage"],
"{found:#?}"
);
// Editing a read item, or a method inside a read impl block, keeps it
// covered while some recent version of an evidence file names it.
fs::write(
root.join("src/lib.rs"),
source
.replace("fn read_directly() {}", "fn read_directly() { 1; }")
.replace("fn method(&self) {}", "fn method(&self) { 2; }"),
)
.unwrap();
let found = errors(root);
assert_eq!(
uncovered(&found),
["src/lib.rs:11: function unread has no recent coverage"],
"{found:#?}"
);
}
Referenced definitions
Input 2: requirements selection requirements.references.roles
requirements.references.roles:md/requirements/references.md:3–49
:::{req} roles
Project text files MAY use the `{impl}`, `{cite}`, and `{test}` roles with a backtick-delimited full requirement or example name, or with a built-in name under {cite}`requirements.references.builtin_definitions`, and MAY use the `{fixme}` role in fenced form. A reference MAY instead be written in fenced form, `:::{role} name` on one line, a body, and a closing fence, following the fence rules of {cite}`requirements.ci.span` and {cite}`requirements.ci.fence_lengths`; the fenced form is the same edge with attached commentary, and the inline form carries none. In a source comment, fence lines MUST be recognized after removing each line's comment delimiters within one comment run under {cite}`requirements.references.outline_comments`, and a fence that does not close within its comment run MUST be a validation error. Each reference is a directed edge between its source and the named definition. A source is a project source item or a requirement or example declaration. The roles MUST mean:
- `{cite}`: the source relies on, supports, or refers to the definition. It is an
edge from the source to the definition.
- `{impl}`: the source implements part of the definition: it makes a decision,
performs a check, produces an output, or handles a case that the definition
specifies. A requirement MAY implement part of another requirement by refining
one of its obligations. Calling code that implements a definition, or
producing a result a caller uses to meet it, MUST NOT by itself count as
implementing it. A check MUST count only if the definition states it, or the
source could not meet one of the definition's obligations without it; source
that checks it is consistent with a definition, such as recognizing a form the
definition specifies in order to decide whether to run other behavior, relies
on that definition and calls for `{cite}`. A requirement stating a convention
for every output of a kind, such as every validation error, is implemented by
the source that carries out the convention as a whole, such as the step that
collects and reports those outputs.
- `{test}`: the source is designed to verify behavior the definition specifies:
a test through its scenario and the assertions about that scenario's outcome,
or a named example through the concrete case it describes.
- `{fixme}`: the source acknowledges a known gap in fulfilling the definition. It
MUST use the fenced form, and its body MUST describe the gap. The body MAY
begin with option lines naming issues that track the gap, one per line, in the
form `:github: <owner>/<repo>#<number>`, such as
`:github: rust-lang/rust#123`. `github` MUST be the only recognized option.
A named `{fixme}` MAY appear only in sources outside the book. Validation MUST report
any other option line, a `:github:` value not in that form, an inline
`{fixme}`, a `{fixme}` in a requirement or example declaration, and a
`{fixme}` whose body, without option lines and comment delimiters, is empty.
An unnamed `{fixme}`, a fence of `:::{fixme}` with no name, MAY appear in any
project text, including a requirement or example body, to tie that place to
the issues it names. It MUST have at least one `:github:` option line and MAY
have a description; it is not a reference edge, acknowledges no gap, needs no
coverage, and does not count as a reference for Rust item coverage. Its
issues are checked under {cite}`requirements.cli.fixme_issues`.
`{impl}`, `{test}`, and `{fixme}` are edges from the definition to the source.
Only requirements and examples are assessed; code is reviewed as part of the
definitions it implements or tests.
```text
{impl}`requirements.references.roles`
{cite}`requirements.references.roles`
{test}`requirements.references.roles`
```
:::
Input 3: requirements selection requirements.references.distributed
requirements.references.distributed:md/requirements/references.md:472–519
:::{req} distributed
A requirement MAY be distributed: it states obligations that each of many sites
in the sources must uphold on its own, such as a convention every validation
function follows, and MAY also state obligations that particular code carries
out, which that code implements with `{impl}`. A `{req}` body declares a distributed requirement
by containing one or more nested query directives: `:::{sites} <name>` for a
site query, which finds the places the obligation applies, or
`:::{violations} <name>` for a violation query, which finds constructs likely to
break it. A requirement with a violation query MUST also have a site query.
Query names MUST be single identifier segments under
{cite}`requirements.ci.identifiers`, unique within the requirement. A query
directive outside a `{req}` body MUST be a validation error. Each query body
MUST be one fenced `yaml` code block containing a mapping with only these keys:
- `language`, required: the name of an outline profile with a grammar under
{cite}`requirements.references.outlines`: `rust`, `python`, `typescript`,
`tsx`, `css`, `markdown`, `toml`, or `yaml`.
- `paths`, optional: project-relative files or directories. Only sources at or
under one of them are searched; without it, every source of the language is.
- `exclude`, optional: project-relative files or directories whose sources are
not searched, even under `paths`.
- `rule`, required, with optional `utils` and `constraints`: an ast-grep rule
core in the syntax of Habeas's pinned `ast-grep-config` version, matched
against the language's pinned grammar.
- `within`, required for violation queries and not allowed for site queries:
the name of a site query in the same requirement.
- `match` and `no_match`, required: nonempty lists of source snippets in the
query's language. Each `match` snippet MUST contain at least one match of the
query, and each `no_match` snippet none, where a violation query counts only matches inside a site of its `within` query in the same snippet.
Validation MUST report a query whose body is not such a mapping, whose rule does
not compile, whose `within` names no site query of the requirement, a violation query without `within`, or one of whose snippets fails to parse or has the wrong match result, and a site query
that matches nothing in the project. Queries MUST search exactly the sources
reference discovery considers under {cite}`requirements.references.discovery`, in
their original text.
A match's site MUST be the innermost outline node, under
{cite}`requirements.references.outlines`, whose range contains the match; for a violation query, it MUST instead be the innermost site of its `within` query that contains the match, and a match inside none of that query's
sites MUST be discarded. A requirement's sites MUST be the distinct sites of all
its queries' matches. Each site MUST have a site review under
{cite}`requirements.references.site_review`, and needs no reference to the
requirement; being a site MUST NOT count as a reference for
{cite}`requirements.references.rust_item_coverage`, because a distributed
requirement concerns a cross-cutting obligation, not why the item exists.
Upgrading `ast-grep-config` MAY change matches and MUST be treated as a
deliberate change. The book MUST render each query directive as a badge
naming its kind and name, followed by its code block.
:::
Input 4: requirements selection requirements.references.rust_item_coverage
requirements.references.rust_item_coverage:md/requirements/references.md:224–226
:::{req} rust_item_coverage
During repository validation, Habeas MUST parse every first-party Rust source file: every `.rs` file among the sources reference discovery considers under {cite}`requirements.references.discovery`, except those under the project-root `vendor` directory. Each explicitly declared function or method, including trait methods and test helpers, and each struct, enum, and union is an item that can be covered. An item is covered when it has a valid `{impl}`, `{cite}`, or `{test}` reference to a defined requirement or named example, or a valid citation of the built-in `habeas:util` under {cite}`requirements.references.util`, in a Rust comment attached to it or within its body; or when its outline node, or an outline node containing it, is recorded with its current hash as an outline input of an evidence record, a citation review, or a site review. Outline inputs recorded from selected search snippets under {cite}`requirements.authoring.finish_search.inputs` MUST count alongside mandatory inputs and additional reads. Comments belong to items under {cite}`requirements.references.outline_comments`; a comment before a field, variant, or attribute inside an item belongs to that item. A named example MUST reference a requirement under {cite}`requirements.examples.definition`. A reference in a string literal, on an enclosing module or impl block, or only in an evidence input MUST NOT count for the items it encloses. Habeas MUST report a Rust parse failure instead of silently skipping the file. Only {cite}`requirements.references.coverage.tests` and {cite}`requirements.references.coverage.examples` make an uncovered item a validation error; other items without recent coverage are warned about under {cite}`requirements.references.coverage.report`.
:::
Input 5: requirements selection requirements.references.util
requirements.references.util:md/requirements/references.md:51–66
:::{req} util
Habeas MUST provide the built-in `habeas:util` under
{cite}`requirements.references.builtin_definitions`, with this text:
> Cite this on an item that serves other code, including code outside the
> project such as a library calling a trait implementation it requires, and
> carries out no requirement or example itself: it has no obligations and no
> end-user-observable behavior of its own. A review that reaches it from a root judges what it does
> as part of that root.
Only `{cite}` MAY reference it, inline or fenced, with or without commentary. An
item whose only citations are of `habeas:util` MUST NOT need a citation review
under {cite}`requirements.references.citation_review`. A citation of
`habeas:util` MUST cover its item under
{cite}`requirements.references.rust_item_coverage`.
:::
Other sources
Input 1: requirements selection requirements.references.procedure
requirements.references.procedure:md/requirements/references.md:68–97
:::{req} procedure
A source item MUST choose its references under {cite}`requirements.references.roles`
for each candidate definition by this procedure, and MAY carry several:
1. If the item is a test designed to verify the definition, it MUST use
`{test}`. A test helper a reviewer reaches by following such a test needs no
reference to the definition.
2. Otherwise, if the item is a root of the definition's implementation, it
MUST use `{impl}`. Code or a type carries out part of a definition when it
makes a decision, performs a check, produces an output, or handles a case
the definition specifies, or when the definition constrains its shape:
fields, variants, serialized form, or validation. A root is such an item
that no other item marked `{impl}` for the definition reaches, where an item
reaches what it calls, the types it uses, and the implementations of trait
methods it calls, and what those reach in turn. An item reached from a root
needs no reference to the definition. An item that is a site of a distributed definition
under {cite}`requirements.references.distributed` needs no reference to it;
its site review covers it.
3. Otherwise, if the item should be re-checked or kept in sync when the
definition changes, it MUST use `{cite}`.
4. If the item carries no reference after applying steps 1 to 3 to every
definition and no assessment reads it under
{cite}`requirements.references.rust_item_coverage`, it MUST cite the
built-in `habeas:util` under {cite}`requirements.references.util` when it
serves other code. An item that does neither carries out behavior that needs
a requirement, or is not needed.
A `{fixme}` reference is added independently of this procedure, and MUST NOT
count as an item's reference for {cite}`requirements.references.rust_item_coverage`.
:::