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§
- Diagnostic
Info - 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
Explainentry. - 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
codemust be a realREGISTRYentry, enforced bytests/diagnostics_registry.rs. Everyexampleneeds its compiled pair underbynk-tests/tests/fixtures/explain/<code>/:bad.bynkandgood.bynk, or, for a rule that needs a second unit or abynk.toml, project treesbad/andgood/. - INDEX_
PATH - The hosted diagnostic index page (the generated
reference/diagnosticspage). 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, orNonewhen 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’scodeDescription, 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_errorreads 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 behinddocs/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
blurbandexamplewhere the code has one (elsenull). Sorted by code. This is the generator behindsite/src/generated/diagnostics.json, which the routesite/src/pages/reference/diagnostics/[code].astrorenders; 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.