add "was" to pluralize macro and use it
This commit is contained in:
parent
f847261478
commit
eb86daa138
5 changed files with 27 additions and 21 deletions
|
@ -26,6 +26,9 @@ macro_rules! pluralize {
|
||||||
("is", $x:expr) => {
|
("is", $x:expr) => {
|
||||||
if $x == 1 { "is" } else { "are" }
|
if $x == 1 { "is" } else { "are" }
|
||||||
};
|
};
|
||||||
|
("was", $x:expr) => {
|
||||||
|
if $x == 1 { "was" } else { "were" }
|
||||||
|
};
|
||||||
("this", $x:expr) => {
|
("this", $x:expr) => {
|
||||||
if $x == 1 { "this" } else { "these" }
|
if $x == 1 { "this" } else { "these" }
|
||||||
};
|
};
|
||||||
|
|
|
@ -1839,25 +1839,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.partition(|field| field.2);
|
.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.span_labels(used_private_fields.iter().map(|(_, span, _)| *span), "private field");
|
||||||
err.note(format!(
|
if !remaining_private_fields.is_empty() {
|
||||||
"... and other private field{s} {names}that were not provided",
|
let remaining_private_fields_len = remaining_private_fields.len();
|
||||||
s = pluralize!(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();
|
err.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ error: cannot construct `Foo` with struct literal syntax due to private fields
|
||||||
LL | foo::Foo {};
|
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
|
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 {};
|
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`
|
error[E0063]: missing field `y` in initializer of `Enum`
|
||||||
--> $DIR/issue-79593.rs:23:5
|
--> $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 {};
|
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
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue