Skip to content

Commit

Permalink
Auto merge of rust-lang#115066 - allaboutevemirolive:pluralize_macro,…
Browse files Browse the repository at this point in the history
… r=Nilstrieb

Redefine the pluralize macro's arm

Redefine the unintuitive pluralize macro's arm because of the negation. The initial code starts with check if count is not 1, which is confusing and unintuitive.

The arm shoud start with checking,

- if "count" `is 1` then, append `""` (empty string) - indicate as singular
- Then check if "count" `is not 1` (more than 1), append `"s"` - indicate as plural

Before:
```rs
// This arm is abit confusing since it start with checking, if "count" is more than 1, append "s".
($x:expr) => {
    if $x != 1 { "s" } else { "" }
};
```

After:
```rs
// Pluralize based on count (e.g., apples)
($x:expr) => {
    if $x == 1 { "" } else { "s" }
};
```
  • Loading branch information
bors committed Aug 22, 2023
2 parents d8c69df + 5dce0e6 commit 3e9e574
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ pub mod builtin;

#[macro_export]
macro_rules! pluralize {
// Pluralize based on count (e.g., apples)
($x:expr) => {
if $x != 1 { "s" } else { "" }
if $x == 1 { "" } else { "s" }
};
("has", $x:expr) => {
if $x == 1 { "has" } else { "have" }
Expand Down

0 comments on commit 3e9e574

Please sign in to comment.