Skip to content

Commit eb86daa

Browse files
committed
add "was" to pluralize macro and use it
1 parent f847261 commit eb86daa

File tree

5 files changed

+27
-21
lines changed

5 files changed

+27
-21
lines changed

compiler/rustc_lint_defs/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ macro_rules! pluralize {
2626
("is", $x:expr) => {
2727
if $x == 1 { "is" } else { "are" }
2828
};
29+
("was", $x:expr) => {
30+
if $x == 1 { "was" } else { "were" }
31+
};
2932
("this", $x:expr) => {
3033
if $x == 1 { "this" } else { "these" }
3134
};

compiler/rustc_typeck/src/check/expr.rs

+21-18
Original file line numberDiff line numberDiff line change
@@ -1839,25 +1839,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18391839
}
18401840
})
18411841
.partition(|field| field.2);
1842-
let remaining_private_fields_len = remaining_private_fields.len();
1843-
let names = match &remaining_private_fields
1844-
.iter()
1845-
.map(|(name, _, _)| name.to_string())
1846-
.collect::<Vec<_>>()[..]
1847-
{
1848-
_ if remaining_private_fields_len > 6 => String::new(),
1849-
[name] => format!("`{name}` "),
1850-
[names @ .., last] => {
1851-
let names = names.iter().map(|name| format!("`{name}`")).collect::<Vec<_>>();
1852-
format!("{} and `{last}` ", names.join(", "))
1853-
}
1854-
[] => unreachable!(),
1855-
};
18561842
err.span_labels(used_private_fields.iter().map(|(_, span, _)| *span), "private field");
1857-
err.note(format!(
1858-
"... and other private field{s} {names}that were not provided",
1859-
s = pluralize!(remaining_private_fields_len),
1860-
));
1843+
if !remaining_private_fields.is_empty() {
1844+
let remaining_private_fields_len = remaining_private_fields.len();
1845+
let names = match &remaining_private_fields
1846+
.iter()
1847+
.map(|(name, _, _)| name.to_string())
1848+
.collect::<Vec<_>>()[..]
1849+
{
1850+
_ if remaining_private_fields_len > 6 => String::new(),
1851+
[name] => format!("`{name}` "),
1852+
[names @ .., last] => {
1853+
let names = names.iter().map(|name| format!("`{name}`")).collect::<Vec<_>>();
1854+
format!("{} and `{last}` ", names.join(", "))
1855+
}
1856+
[] => unreachable!(),
1857+
};
1858+
err.note(format!(
1859+
"... and other private field{s} {names}that {were} not provided",
1860+
s = pluralize!(remaining_private_fields_len),
1861+
were = pluralize!("was", remaining_private_fields_len),
1862+
));
1863+
}
18611864
err.emit();
18621865
}
18631866

src/test/ui/issues/issue-76077.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: cannot construct `Foo` with struct literal syntax due to private fields
44
LL | foo::Foo {};
55
| ^^^^^^^^
66
|
7-
= note: ... and other private field `you_cant_use_this_field` that were not provided
7+
= note: ... and other private field `you_cant_use_this_field` that was not provided
88

99
error: aborting due to previous error
1010

src/test/ui/privacy/issue-79593.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ error: cannot construct `Pub` with struct literal syntax due to private fields
1616
LL | foo::Pub {};
1717
| ^^^^^^^^
1818
|
19-
= note: ... and other private field `private` that were not provided
19+
= note: ... and other private field `private` that was not provided
2020

2121
error[E0063]: missing field `y` in initializer of `Enum`
2222
--> $DIR/issue-79593.rs:23:5

src/test/ui/typeck/issue-87872-missing-inaccessible-field-literal.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: cannot construct `Foo` with struct literal syntax due to private fields
44
LL | foo::Foo {};
55
| ^^^^^^^^
66
|
7-
= note: ... and other private field `you_cant_use_this_field` that were not provided
7+
= note: ... and other private field `you_cant_use_this_field` that was not provided
88

99
error: aborting due to previous error
1010

0 commit comments

Comments
 (0)