Typed sites
A banned call is exempt only as a typed site: site! wraps exactly one call,
and its first argument is a variant of a crate-private enum that names the place
and says why it is exempt. The enums are the manifest. The exemption is
#[expect], so a site that wraps no banned call is an error, and checks in
core/tests/sites.rs state what clippy cannot: that no other exemption exists,
that no lint group silences the lint, and that every member is bound by it. This replaces the tagged #[allow] of
surface-reads-writes-execs
(Enforcement); how the enforcement reads now is told in
io-surface.
Context
clippy.toml bans the constructors and the raw wrappers under one lint,
clippy::disallowed_methods, and a legitimate call opted out with a
hand-written #[allow(clippy::disallowed_methods, reason = "…")]. Three things
were wrong with that.
- One lint, so exemptions were prose. An allow names the lint, not the ban,
so an allow written for a spelling conversion silenced an
fs::readas readily. The reason opened with a tag ([surface:<slug>],[silent:<slug>],[test], and the untaggednative:,path-form:,host-env:,reaper:,REASONED-SILENT:), and only a scanner reading text held the tags to a manifest. - Function scope masked. Most allows sat on whole functions, so one exemption silenced every banned call in its body, including the ones added later.
- Nothing noticed a stale one. An
#[allow]over code that no longer contains a banned call is silent. Seventeen were found when the sites were converted.
Decision
-
A site wraps one call.
site!(Silent::ArgvBeforeMain, std::fs::read("/proc/self/cmdline")); for a method,site!(Silent::GitRoot, cwd => ancestors()). The receiver and every argument are evaluated outside the exemption, so a banned call nested in an argument still fires. The macro’s result chains (site!(…).unwrap(),site!(…)?), a chain of banned calls is split into one site each, and?and.awaitstay outside the macro. -
The first argument is a variant, and the variant is the manifest. It must implement the crate’s
Sitemarker trait.Surfacelists the sites that raise a card,Silentthose that raise none; a crate defines only the enums it uses. A variant’s doc says what the place is and why it is exempt (and, forSilent, why it raises no card). Several calls that serve one purpose share a variant. The enums arepub(crate), orpub(in crate::path)incore/src/path/site.rs, carry noALLconstant and no registry, and deriveClone, Copyalone, sodead_codereports a variant that no site uses; a variant used only under acfgcarries thatcfg. -
The exemption is
#[expect]. The macro emits#[expect(clippy::disallowed_methods, …)]on the one call, so a site that no longer wraps a banned call isunfulfilled_lint_expectations, and a stale exemption cannot outlive its call. Rustc alone does not run the lint, so only clippy reports a stale site. -
The macro file is
include!d, not shared.lint/site.rsat the repo root holds theSitetrait and the macros; each crate that has sites mounts it from a module namedsiteat its crate root (src/site.rs, whose first item is theinclude!, followed by that crate’s enums), and the macro addresses$crate::site::…. A shared crate would export the macro, and a lint expectation placed by a macro defined in another crate is never reported as unfulfilled, so the stale check would be lost. The macro is crate-local, with no#[macro_export]. -
Test, example and build code is not what the bans protect, and carries one blanket per unit. Each file directly under
<crate>/tests/opens with an inner#![allow(clippy::disallowed_methods, reason = "test code")]; a#[cfg(test)]module carries the outer allow beside its#[cfg], and nothing inside it carries one; an example and abuild.rscarry the inner allow with their own reason.ral-daemonandral-initramfskeep their crate-root allow: each is a guest init program, whose whole job is the syscalls the bans route, and links no ral shell. -
A wrong conversion is fixed, not exempted. Where an allow existed to paper over a lossy or by-spelling path operation, the code changed instead:
path::utf8is the one strict conversion for a path that must travel as text,path::shownthe one lossy conversion, for display only,path::spelled_parentthe by-spelling parent for a program’s own layout, and bytes stand in for a conversion where only a comparison was wanted. -
core/tests/sites.rsstates what clippy cannot. Its first check scans the Rust sources of every workspace member butvendor/, comments stripped, and every occurrence ofclippy::disallowed_methodsmust be one of four:- (a) in
lint/site.rs; - (b) an inner
#![allow(clippy::disallowed_methods, reason = "…")]among the leading attributes (only other inner attributes precede it) of an integration-test crate root, an example, abuild.rs, orral-daemon/src/lib.rsorral-initramfs/src/lib.rs; - (c) an outer
#[allow(clippy::disallowed_methods, reason = "test code")]on amoditem whose own attributes include a#[cfg(…)]whose predicate impliestest: exactlytest, anall(…)with atestconjunct, or exactlyany(test, feature = "test-util"). Any otherany(…)holds in a production build, andany(test, unix)would exempt production code on Unix; - (d) the one third-party-codegen exception, below.
A failure names
file:lineand the rule it breaks.Two further checks close the other ways round the lint’s name.
- No group silences the lint.
disallowed_methodsis astylelint, andclippy::allholdsstyle, so anallow,expectorwarnof either group would silence every ban without naming it. A test over the same sources flags, with itsfile:line, every attribute that names either group and is not adenyor aforbid. - Every member is bound. The bans and their
denyare the workspace’s lints, which a member takes through[lints]withworkspace = truein itsCargo.toml. A test reads the manifest of every workspace member butvendor/’s, which opts out by design, and fails one that lacks the table.
capability::Ungoverned::{read, read_dir, region, write, write_dir}are banned byclippy::disallowed_methods: authority minting requires a typed site, replacing the text-count allowlist andungoverned_gains_no_new_callertest. The pinned caller set for string containment helpers outsidepath/stays. - (a) in
Consequences
-
The macro has limits, each with its workaround. It binds the receiver and each argument once, outside the exemption, and every limit follows from that:
- a
&mutthat is used again is moved into the macro: write&mut *v; - a by-value receiver that is not
Copyis moved: write&x => m(); - a closure argument loses its expected signature: annotate its parameters,
|s: &str| …; - an argument whose type only the callee’s parameter fixes cannot be inferred from the macro’s binding: bind it first, with an annotated type;
- two-phase borrows are lost, so
site!(V, &mut v => push(v.len()))fails: bindv.len()first; - the result cannot borrow from a temporary created in the arguments: bind the temporary first;
- a banned function used as a value (
.and_then(Path::parent)) becomes a closure with a site inside, or a helper.
- a
-
A crate whose lib and bin targets both have sites mounts the module twice. The module is crate-local, so the library’s
sitecannot serve the binary.Amended 2026-10-27. Synod is binary-only and declares
mod site;once inmain.rs; the lib+bin case no longer arises. Broker service sites live insynod-machine-broker/src/site.rs; vm-manager keeps host/client sites.Amended 2026-11-24. The broker crate and its
site.rsare gone (windows-runs-openvmm).- Dropped: vm-manager’s
RootfsWrapProbe,RootfsWrapandBrokerPipeConnect. - Reused:
CheckoutRootresolvesopenvmm.exe, andConsoleLogOpenopens the openvmm log. - Widened:
SessionDiskFoldernow covers Windows.
Every banned call in
vm-manager/src/, the Win32 calls of the OpenVMM backend included, is asite!. There is no raw#[allow(clippy::disallowed_methods)]in production code.Amended 2026-12-01. Synod’s shell and its sites moved into the
desktoplibrary (desktop/src/site.rs);synodandexarch-guiare thin binaries, and thegenerate_context!exception is pinned in each one’smain.rs(TAURI_FILESinlint/tests/arch/sites.rs). - Dropped: vm-manager’s
-
One third-party-codegen exception, pinned.
tauri::generate_context!()insynod/src/main.rsexpands to code that exits the process, and prints, when building the context panics, andsite!wraps calls, not macro invocations. The statement carries a hand-written#[expect(clippy::disallowed_methods, clippy::disallowed_macros, …)], which the scan permits as rule (d), by file and by thegenerate_context!it precedes; being an#[expect], it is still reported if the expansion stops needing it. -
A program’s own files take no syscall site. Of the filesystem sites outside
path/, 93 were rawstd::fson files the program keeps, the user writes at its places, or the user names. They became operations ofral_core::own, whose every syscall is a walk primitive, so the module holds no syscall site, and the filesystem sites outsidepath/fell from 114 to 21. It has three authority-mint sites instead:Silent::{OwnRead, OwnWrite, OwnWriteDir}. The four functions that take a name the user gave are banned, and each caller is a typed site that says why the name is the user’s (own-files). -
The classification is for the reader.
SurfaceandSilentchange nothing the macro emits. A card is still raised where the operation is observed (io-surface), and the variant says that it is, or why it is not. -
Platform reach of the lint is the host’s. Windows clippy runs locally through
cargo xwin clippy --target x86_64-pc-windows-msvc; synod is linted only there, since the Linux workspace excludes it for its GUI dependencies. macOS clippy runs for ral-core and vm-manager (CC_aarch64_apple_darwin=clang), but ral, exarch and synod need the macOS SDK, so on a host without it their macOS-only code is not linted. -
project_slugkeys one-to-one. The conversion at the core of the old slug was lossy, so two cwds could share a key. A slug is now a readable part (still lossy, for a person scanning a listing), a-, and 16 hex digits of the SHA-256 of the cwd’s exact OS bytes (UTF-16 units on Windows), so two cwds that differ at all key apart.
Rejected
- A shared crate for the macro. The expectation is placed by a macro from another crate and is never reported as unfulfilled; the stale check is the point.
- A list of variants (
ALL) or a registry. A second statement of the set can disagree with the first;dead_codeon the enum states the one fact worth stating, that every variant is used. - An attribute on a function, or on a statement with several calls. One exemption then covers every banned call in its scope, which is the masking this removes.
- Tags in a reason string, scanned. A scanner reads text, not types or scopes, and a reason has to be well-formed to be found at all.
Where
lint/site.rs (the Site trait and site!); each crate’s src/site.rs
(Surface and Silent, as the crate needs them), with core/src/path/site.rs
for the path module’s own and desktop/src/site.rs for the desktop shell;
lint/tests/arch/sites.rs (the scan, the group check, the workspace-lints check and the
two pinned caller sets); clippy.toml
(the bans, and the header that states the discipline); spelled_parent and
utf8 in core/src/path/lex.rs, shown in core/src/path/show.rs,
project_slug in core/src/path/slug.rs.
Amended 2026-10-27. The guest init exemption now belongs to the sole binary root,
ral-guest/src/main.rs; assembly and supervision are modules of that program.core/tests/sites.rs::GUEST_INIT_ROOTSnames that one root.
Amended 2026-10-27. The host network gate is
netgate;core/tests/sites.rs::SRC_ROOTSincludesnetgate/srcin the site scan.