Skip to main content

Module diagnostics

Module diagnostics 

Source
Expand description

Central registry of diagnostic codes.

This is the single source of truth for the bynk.* codes the compiler can emit. The reference page site/src/content/docs/reference/diagnostics.md is generated from render_markdown, and the test tests/diagnostics_registry.rs asserts that this table matches exactly the set of codes used across the compiler source — so a new code cannot be introduced without documenting it here, and a removed code cannot linger in the docs.

Each entry is a (code, summary) pair, optionally tagged with the grammar production(s) it constrains (grammar_symbol), and carries a severity (Error unless built via the crate-private warn helper). The category shown in the generated reference is derived from the second dotted segment of the code; the grammar weave (docs/grammar-semantics.json, the {{#grammar-semantics}} directive, and the “Grammar rules” line on each code’s own page) is generated from grammar_symbol.

Structs§

DiagnosticInfo
One documented diagnostic: its stable code and a one-line summary of the cause. The longer lesson, the cause and the fix with an example, is the code’s Explain entry.
Explain
A curated, offline-complete explanation of a diagnostic code (#853).

Constants§

BOOK_BASE_URL
The hosted site. No trailing slash: a site-root path (which begins with /) is appended directly.
D_PATH
The link contract between the toolchain and the site (web presence track, decision D2, #3876): every diagnostic links as {BOOK_BASE_URL}/d/<code>, and /d/ alone is the index. The site serves a page for every registry code behind it and decides where that page lives; the compiler names no docs page.
EXPLANATIONS
The curated explanations, keyed by code (DECISION B: highest-traffic, newcomer-facing codes first). Kept sorted by code; every code must be a real REGISTRY entry, enforced by tests/diagnostics_registry.rs. Every example needs its compiled pair under bynk-tests/tests/fixtures/explain/<code>/: bad.bynk and good.bynk, or, for a rule that needs a second unit or a bynk.toml, project trees bad/ and good/.
INDEX_PATH
The hosted diagnostic index page (the generated reference/diagnostics page). Each code’s own page is {INDEX_PATH}<code>/, which /d/<code> redirects to.
REGISTRY
Every diagnostic code the compiler emits, sorted by code.

Functions§

category
The category segment of a code (the part between the first two dots), e.g. "types" for "bynk.types.type_mismatch".
explain
The curated explanation for a diagnostic code, or None when the code has no explanation yet (the designed graceful-fallback state, DECISION B).
href
The link for any diagnostic code (#3876): {BOOK_BASE_URL}/d/<code> for a registry code, which the site serves a page for whether or not the code has an explanation; otherwise (a host-synthetic code) {BOOK_BASE_URL}/d/, the index. What the LSP’s codeDescription, the editor’s Explain panel, bynk explain, the MCP tools and the playground all link.
lookup
Look up a code’s registry entry by exact match — the one place crate::error::Severity::for_error reads a code’s severity, instead of hardcoding its own copy of the (small) warning set.
render_grammar_semantics_json
Invert the registry into a { "<rule>": [ { code, summary }, … ], … } map, serialised as pretty JSON with sorted keys and sorted codes. Only rules with at least one diagnostic appear. This is the generator behind docs/grammar-semantics.json, which the {{#grammar-semantics <rule>}} preprocessor directive consumes.
render_json
Every registry code as JSON, for the site’s page per code (#3876): its summary, severity, category (title and the index anchor of its heading), grammar constructs, and the curated blurb and example where the code has one (else null). Sorted by code. This is the generator behind site/src/generated/diagnostics.json, which the route site/src/pages/reference/diagnostics/[code].astro renders; the docs-consistency test keeps the committed file current.
render_markdown
Render the diagnostic index as a Markdown reference page, grouped by category. This is the generator behind site/src/content/docs/reference/diagnostics.md.