rustc lexer/macro_rules diagnostics feature request: Color highlight acceptable characters
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
This applies probably to macro_rules/macro v.2 only (correct this otherwise). When the lexer/tokenizer reports errors like
note: allowed there are: `{`, `[`, `=>`, `,`, `>`, `=`, `:`, `;`, `|`, `as` or `where`
then highlight each allowed characters/tokens (in terminals that use colors). This should not be a rocket science, since the error reporting already makes "error" red and "warning" yellow (though that is surely higher up the control chain).
macro_rules! m {
($e:expr ~ $id:ident) => {};
}
generates error:
Checking macro_ru v0.1.0 (/home/pkehl/macro_ru)
error: `$e:expr` is followed by `~`, which is not allowed for `expr` fragments
--> src/lib.rs:2:14
|
2 | ($e:expr ~ $id:ident) => {};
| ^ not allowed after `expr` fragments
|
= note: allowed there are: `=>`, `,` or `;`
and
macro_rules! m {
($t:ty ~ $id:ident) => {};
}
generates even less readable:
...
2 | ($t:ty ~ $id:ident) => {};
| ^ not allowed after `ty` fragments
|
= note: allowed there are: `{`, `[`, `=>`, `,`, `>`, `=`, `:`, `;`, `|`, `as` or `where`
As per https://internals.rust-lang.org/t/rustc-lexer-diagnostics-feature-request-color-highlight-acceptable-characters/24227.
@rustbot label +A-diagnostics +D-diagnostic-infra
Contributor guide
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 at the rustc lexer/tokenizer diagnostics for macro_rules fragment-following errors, using the expr and ty examples in the issue to reproduce the current output. Trace where allowed tokens are rendered and determine how terminal color highlighting is handled; done means each allowed character or token is visibly highlighted without changing the diagnostic content.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100