You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
rustc lexer/macro_rules diagnostics feature request: Color highlight acceptable characters #156458
A-diagnosticsArea: Messages for errors, warnings, and lintsD-diagnostic-infraDiagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
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`
tl;dr Any basic color choice may be fine, maybe green as if a "green light."
Accessibility/color blindness assumption: (Based on a quick online/AI query, simplified, no knowledge of the subject; please correct this if needed): It seems that there is no single "basic/mainstream" color that, when used as "pure/intense" for text foreground, would be invisible/difficult for the same person on both white background and black background (with no other colors nearby).
Also
major terminals/window managers/IDE's offer choice of background colors/themes, so there should be a way to workaround, as far as we don't use various non-black and non-white colors next to each other/contrasting with each other.
in Mac OS/Linux/Unix terminals/shells (and maybe in Windows Powershell, too), one can pipe the outputs (including error output) to a file, or to another command (like cat), which removes any color/formatting control escapes.
cargo build (and friends) take --color never parameter, like cargo build --color never; or, you can set the environment variable CARGO_TERM_COLOR=never. That does not work completely; for now you need to use cargo test --color=never -- --color=never (and friends), give thumbs up to rust-lang/cargo#1983.
The above generalization is not to discard/minimize needs of people with visual difficulties, but to be realistic about what we can provide, and what workarounds exist already.
in Mac OS/Linux/Unix terminals/shells (and maybe in Windows Powershell, too), one can pipe the outputs (including error output) to a file, or to another command (like cat), which removes any color/formatting control escapes.
Not sure if you meant it how it sounds, but the colours are controlled by the original tool that generates the text, not removed by the terminal, file, or command the output is piped to.
Tools can auto-detect whether they are writing to a terminal and disable coloured output. This requires the cooperation of the colour/terminal library, terminal app, and/or the OS. That's what happens when redirecting output, the command or file is detected as "not a terminal", so the tool doesn't output colour escapes.
Sometimes the detection doesn't work, and users will see raw output with colour codes in it (in tools that escape control codes). This can be rendered as colours using less --raw-control-chars or similar.
We already have a highlight mechanism (which is used most prominently by "expected/found" type errors, but also a few other places). The highlight color is currently magenta (as it was the only somewhat readable color that wasn't already used for other semantic meaning, it used to be bold white, but people thought it wasn't highlighted enough). Doing this should be relatively straightforward by modifying
A-diagnosticsArea: Messages for errors, warnings, and lintsD-diagnostic-infraDiagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
Activity
peter-lyons-kehl commentedon Jun 16, 2026
tl;dr Any basic color choice may be fine, maybe green as if a "green light."
Accessibility/color blindness assumption: (Based on a quick online/AI query, simplified, no knowledge of the subject; please correct this if needed): It seems that there is no single "basic/mainstream" color that, when used as "pure/intense" for text foreground, would be invisible/difficult for the same person on both white background and black background (with no other colors nearby).
Also
cat), which removes any color/formatting control escapes.cargo build(and friends) take--color neverparameter, likecargo build --color never; or, you can set the environment variableCARGO_TERM_COLOR=never. That does not work completely; for now you need to usecargo test --color=never -- --color=never(and friends), give thumbs up to rust-lang/cargo#1983.The above generalization is not to discard/minimize needs of people with visual difficulties, but to be realistic about what we can provide, and what workarounds exist already.
See also
teor2345 commentedon Jun 17, 2026
Not sure if you meant it how it sounds, but the colours are controlled by the original tool that generates the text, not removed by the terminal, file, or command the output is piped to.
Tools can auto-detect whether they are writing to a terminal and disable coloured output. This requires the cooperation of the colour/terminal library, terminal app, and/or the OS. That's what happens when redirecting output, the command or file is detected as "not a terminal", so the tool doesn't output colour escapes.
Sometimes the detection doesn't work, and users will see raw output with colour codes in it (in tools that escape control codes). This can be rendered as colours using
less --raw-control-charsor similar.estebank commentedon Oct 6, 2026
We already have a highlight mechanism (which is used most prominently by "expected/found" type errors, but also a few other places). The highlight color is currently magenta (as it was the only somewhat readable color that wasn't already used for other semantic meaning, it used to be bold white, but people thought it wasn't highlighted enough). Doing this should be relatively straightforward by modifying
rust/compiler/rustc_expand/src/mbe/macro_rules.rs
Lines 1646 to 1662 in abcef06
to use
rust/compiler/rustc_errors/src/diagnostic.rs
Line 619 in 4341575
mtan37 commentedon Oct 6, 2026
Hi @estebank , I'm new to the project and saw you left some useful pointers in your previous comment. I would love to work on this as my first issue!
estebank commentedon Oct 7, 2026
Feel free to do so! Make sure to read https://rustc-dev-guide.rust-lang.org/index.html
The change should be straightforward to make.
mtan37 commentedon Oct 7, 2026
Thank you for the link! I will read through it
@rustbot claim