mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-09 13:33:43 +00:00
add "was" to pluralize macro and use it
This commit is contained in:
parent
f847261478
commit
eb86daa138
@ -26,6 +26,9 @@ macro_rules! pluralize {
|
||||
("is", $x:expr) => {
|
||||
if $x == 1 { "is" } else { "are" }
|
||||
};
|
||||
("was", $x:expr) => {
|
||||
if $x == 1 { "was" } else { "were" }
|
||||
};
|
||||
("this", $x:expr) => {
|
||||
if $x == 1 { "this" } else { "these" }
|
||||
};
|
||||
|
@ -1839,25 +1839,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
}
|
||||
})
|
||||
.partition(|field| field.2);
|
||||
let remaining_private_fields_len = remaining_private_fields.len();
|
||||
let names = match &remaining_private_fields
|
||||
.iter()
|
||||
.map(|(name, _, _)| name.to_string())
|
||||
.collect::<Vec<_>>()[..]
|
||||
{
|
||||
_ if remaining_private_fields_len > 6 => String::new(),
|
||||
[name] => format!("`{name}` "),
|
||||
[names @ .., last] => {
|
||||
let names = names.iter().map(|name| format!("`{name}`")).collect::<Vec<_>>();
|
||||
format!("{} and `{last}` ", names.join(", "))
|
||||
}
|
||||
[] => unreachable!(),
|
||||
};
|
||||
err.span_labels(used_private_fields.iter().map(|(_, span, _)| *span), "private field");
|
||||
err.note(format!(
|
||||
"... and other private field{s} {names}that were not provided",
|
||||
s = pluralize!(remaining_private_fields_len),
|
||||
));
|
||||
if !remaining_private_fields.is_empty() {
|
||||
let remaining_private_fields_len = remaining_private_fields.len();
|
||||
let names = match &remaining_private_fields
|
||||
.iter()
|
||||
.map(|(name, _, _)| name.to_string())
|
||||
.collect::<Vec<_>>()[..]
|
||||
{
|
||||
_ if remaining_private_fields_len > 6 => String::new(),
|
||||
[name] => format!("`{name}` "),
|
||||
[names @ .., last] => {
|
||||
let names = names.iter().map(|name| format!("`{name}`")).collect::<Vec<_>>();
|
||||
format!("{} and `{last}` ", names.join(", "))
|
||||
}
|
||||
[] => unreachable!(),
|
||||
};
|
||||
err.note(format!(
|
||||
"... and other private field{s} {names}that {were} not provided",
|
||||
s = pluralize!(remaining_private_fields_len),
|
||||
were = pluralize!("was", remaining_private_fields_len),
|
||||
));
|
||||
}
|
||||
err.emit();
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ error: cannot construct `Foo` with struct literal syntax due to private fields
|
||||
LL | foo::Foo {};
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= note: ... and other private field `you_cant_use_this_field` that were not provided
|
||||
= note: ... and other private field `you_cant_use_this_field` that was not provided
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -16,7 +16,7 @@ error: cannot construct `Pub` with struct literal syntax due to private fields
|
||||
LL | foo::Pub {};
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= note: ... and other private field `private` that were not provided
|
||||
= note: ... and other private field `private` that was not provided
|
||||
|
||||
error[E0063]: missing field `y` in initializer of `Enum`
|
||||
--> $DIR/issue-79593.rs:23:5
|
||||
|
@ -4,7 +4,7 @@ error: cannot construct `Foo` with struct literal syntax due to private fields
|
||||
LL | foo::Foo {};
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= note: ... and other private field `you_cant_use_this_field` that were not provided
|
||||
= note: ... and other private field `you_cant_use_this_field` that was not provided
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user