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
Factor out pluralisation checks in diagnostics #64238
C-cleanupCategory: PRs that clean code up or issues documenting cleanup.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-help-wantedCall for participation: Help is requested to fix this 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.
The following pattern is common in diagnostic messages in rustc:
format!("found {} thing{}", x,if x != 1{"s"} else {""})
It would be good to extract all of these pluralisation checks into a function or macro:
format!("found {} thing{}", x, pluralise(x))
There's already one in src/librustc/ty/error.rs, but it's not used anywhere else, so we could move it to somewhere in src/librustc_errors, and replace the occurrences of this pattern with the macro.
@V1shvesh: searching for { "s" } else { "" } and { "" } else { "s" } in rustc, I can see a few cases that weren't caught by #64280, e.g. in resolve_lifetime.rs, diagnostics.rs, etc. Let's keep this issue open until they've all been replaced with the new macro.
C-cleanupCategory: PRs that clean code up or issues documenting cleanup.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-help-wantedCall for participation: Help is requested to fix this 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
V1shvesh commentedon Sep 7, 2019
I'd love to be assigned to this issue!
Centril commentedon Sep 7, 2019
@rustbot assign @V1shvesh
V1shvesh commentedon Sep 7, 2019
So, I have moved the macro under
src/librustc_errorsin a file calledpluralise.rs. I have also located all the occurrences of the pattern.I am a bit new to Rust, so I still am learning about the module system. How shall I pull the macro into the scope of all the relevant files?
varkor commentedon Sep 7, 2019
@V1shvesh: I'd put it in
src/librustc_errors/lib.rs, so we don't have one new file for a single macro. Then you can use it fromuse syntax::errors;.V1shvesh commentedon Sep 7, 2019
Thanks for pointing me in the right direction @varkor!
Rollup merge of rust-lang#64280 - V1shvesh:master, r=Centril
varkor commentedon Sep 9, 2019
@V1shvesh: searching for
{ "s" } else { "" }and{ "" } else { "s" }in rustc, I can see a few cases that weren't caught by #64280, e.g. inresolve_lifetime.rs,diagnostics.rs, etc. Let's keep this issue open until they've all been replaced with the new macro.glorv commentedon Sep 10, 2019
I have open a pr to refactor the pluralisations remain, @Centril please have a look at it, thanks.
V1shvesh commentedon Sep 10, 2019
@varkor Oh, my bad. @glorv thanks for helping out!
Rollup merge of rust-lang#64342 - glorv:master, r=varkor
Rollup merge of rust-lang#64342 - glorv:master, r=varkor
Rollup merge of rust-lang#64342 - glorv:master, r=varkor
Rollup merge of rust-lang#64342 - glorv:master, r=varkor
Rollup merge of rust-lang#64342 - glorv:master, r=varkor
Rollup merge of rust-lang#64342 - glorv:master, r=varkor
Rollup merge of rust-lang#64342 - glorv:master, r=varkor
Rollup merge of rust-lang#64342 - glorv:master, r=varkor
Rollup merge of rust-lang#64342 - glorv:master, r=varkor