User-facing diagnostics print the Rust Debug of internal AST structs, spans and all
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 14
- Forks
- 2
- Avg merge
- 12h 42m
- Merged PRs (30d)
- 61
Description
Type has had a Display impl since src/syntax/types.rs:892. Fifteen user-facing messages in the checker format types with {:?} instead, so a diagnostic quotes the compiler's internal representation rather than the type the user wrote.
E3003 is the one a new user hits first:
fn takes(x : i32) -> i32 { return x; }
fn main() -> i32 { let t = Tensor<f32, [2,2]>::uninit(); return takes(t); }
Error[E3003] at 0:0: Type mismatch in argument 1 for function 'takes'. Expected Scalar(I32), got
Tensor(F32, [Number(NumberExpr { value: "2", ty: Some(I32), span: Span { line: 0, column: 0,
length: 0 } }), Number(NumberExpr { value: "2", ty: Some(I32), span: Span { line: 0, column: 0,
length: 0 } })], None)
What the user wrote was Tensor<f32, [2, 2]>, and Display prints exactly that. The dimension list is the worst of it: every dimension is a full NumberExpr with its own (empty) span, so a rank-2 tensor costs four lines of noise and a rank-4 one is unreadable.
The cross-topology message does the same with a whole placement:
Error: Cross-topology access error: 't' (type: Tensor(F32, [Number(NumberExpr { value: "4", ...
Scope
grep -rn '{:?}' src/hir/ --include=*.rs | grep -E 'format!|push\(' -> 15 sites. Not all of them are types (a few print an Expr, which has no Display), so this is a per-site judgement rather than a blanket substitution:
- where the value is a
Type, useDisplay; - where it is an
Expror another AST node with noDisplay, either give it one or describe the node rather than dumping it.
Why it matters for a release
This is the first impression of the compiler's error quality, on the most common error there is. It also leaks internal struct names (NumberExpr, Stated, Custom) into the user's terminal, which makes them look like things the language has.
Found while fixing Vx#334 / Vx#431, whose reproductions all render this way. Related: the spans in that dump are all 0:0, which is filed separately.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the 15 matches from grep -rn '{:?}' src/hir/ --include=*.rs | grep -E 'format!|push\(', then read the Type Display implementation in src/syntax/types.rs:892. Reproduce E3003 with the example and inspect each site to distinguish Type values from other AST nodes. Done means user-facing diagnostics no longer expose internal AST structs, spans, or names.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100