Diagnostics
Structured errors, Swift-style ownership messages, borrow notes, and nyra diag --json.
Ownership errors name the callee function, show its parameter types, and suggest &, clone, or move. Full guide: Ownership UX. Proactive snapshots (who owns / who borrows at a line): nyra inspect.
Ownership inspect
When errors are unclear — or while learning — ask the compiler for a binding’s state at a source line:
nyra inspect name --at main.ny:42
nyra check . --ownership-verbose
Compile-time only (no runtime reflection). Rust’s stable toolchain does not ship this. Details: Ownership inspect.
nyra diag
nyra diag . --json
Emits structured JSON for editors and CI. Each entry includes code, label, notes, helps, and end positions (end_line, end_column). Same messages as nyra check / compile errors.
nyra explain
nyra explain E003
nyra explain P001
nyra explain --list
Prints a static explanation for stable diagnostic codes (like rustc --explain). Use after seeing error[E003]: in the terminal or LSP.
Import-related codes: E001 (path not found), E039 (selective import { name } missing or priv), W002 (unused import). See Imports guide → rules.
Ownership diagnostics
error: use of moved value 'user'
--> main.ny:8:14
|
6 | save(user)
| ---- value moved here (into `save`)
7 | print(user.name)
| ^^^^ value used after move
|
= note: `save(user: User)` takes owned `User`
= help: borrow instead: save(&user)
= help: or duplicate: save(clone user)
| Situation | Typical message | Fix |
|---|---|---|
| Use after move into call | was moved into save() | save(&user) (auto-borrow) or save(clone user) |
| Owned param when borrow expected | Type mismatch on &T | Omit & — compiler auto-borrows owned values |
| Explicit move intended | — | save(move user) skips auto-borrow |
| Keep binding after call | Move error | Change callee to &T or use clone |
Common borrow errors
| Message | Cause | |
|---|---|---|
| Use of moved value | Move-type used after move; callee may be named in note | |
| Cannot borrow as mutable | &mut aliasing conflict | |
| cannot return reference to local | Dangling & return | |
| cannot infer type for 'x' | Add annotation: let x: T = ... | |
| expected ',' or '}' between struct literal fields (P006) | Missing comma between literal fields, often after foo() | { a: f(), b: 1 } — commas in literals; struct defs use newlines |
| #[derive(Copy)] on non-Copy struct | Field not Copy (e.g. string) | |
| manual free warning | Double-free risk with auto-drop |
error: Use of moved value 'a'
--> main.ny:4:11
|
4 | print(a)
| ^