rust-lang / rust-lang/rust

Serial integers are bad error codes

Open
#151,922 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics A-error-codes C-cleanup T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Currently, error codes are seemingly added on the basis of "the last error code plus one". This is bad because it means entirely unrelated errors are placed next to each other. In general, errors about the same topic would ideally have similarities in their encoding.

We have a few plausible directions here:

  1. Shrug and embrace chaos
  2. Use a numeric encoding of the expected error space akin to SQLSTATE or HTTP status codes
  3. Switch to using text-based error codes using extant diagnostic slugs or something similar
  4. Switch to using text-based error codes resembling something like the reference's dotted-keys: https://doc.rust-lang.org/reference/identifiers.html#r-ident.syntax
  5. Nuke --explain

User feedback is consistently that at least some --explain outputs are helpful, so we probably shouldn't do 4 (incl. survey responses to direct questions at #t-compiler > Error codes still useful? @ 💬). The usual "and also..." we get is the --explain output is most useful in the earlier phases of learning Rust.

We probably shouldn't do 0 either. If nothing else, a serially increasing integer leads to merge conflicts as described in #t-compiler > Error codes still useful? @ 💬.

We probably will have to allow both error code schemata to coexist for a while since a "hard" migration would be very rough on our codebase, testing infrastructure, and programmer expectations. We'd even break integrations like evcxr's, which uses error codes because they are more robust than pattern-matching specific error messages. https://github.com/evcxr/evcxr

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the compiler's existing error-code assignment and --explain behavior, then read the linked compiler discussion and survey responses. Consider the compatibility requirements for evcxr and the proposed period of coexistence between schemas. Done means selecting and documenting a concrete error-code direction with a migration plan.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.