Skip to content

Factor out pluralisation checks in diagnostics #64238

@varkor

Description

@varkor

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.

macro_rules! pluralise {
($x:expr) => {
if $x != 1 { "s" } else { "" }
};
}

This issue has been assigned to @V1shvesh via this comment.

Metadata

Metadata

Assignees

Labels

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.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions