Skip to main content

tree_root_for

Function tree_root_for 

Source
pub fn tree_root_for<'a>(
    trees: &'a [(PathBuf, PathBuf)],
    pf: &ParsedFile,
) -> &'a Path
Expand description

The include tree that discovered pf, found by matching its absolute path against each tree’s root — not trees[0] unconditionally, since R3.9 (#1113) lets a file live under any include tree, not just the first. Falls back to trees[0] for a pf with no abs_path (unreachable for a real adapter: only synthetic units, which never declare binding, go without one) or if it somehow matches none. The longest matching root wins, in case one include tree is nested inside another.

A trees root is only absolute when Roots’s own project_root is — a relative project root (bynkc build ., the ordinary CLI shape) leaves every tree root relative, while pf.abs_path() (bynk-project’s parse_sources, via std::path::absolute) is always absolute. Comparing them directly with starts_with would never match, silently collapsing this back to the trees[0] bug it exists to fix. Each root is resolved through the same std::path::absolute before comparing, matching abs_path’s own normalisation exactly rather than requiring the caller to have already absolutised Roots::project_root.