Pluralize error messages.

This commit pluralizes error messages when more than a single trailing
`>` character is present.
This commit is contained in:
David Wood 2019-01-21 21:16:46 +01:00
parent 6c399d155c
commit 3f0fc9b035
No known key found for this signature in database
GPG key ID: 01760B4F9F53F154
2 changed files with 15 additions and 8 deletions

View file

@ -2869,11 +2869,18 @@ impl<'a> Parser<'a> {
self.eat_to_tokens(&[&token::OpenDelim(token::Paren)]);
let span = lo.until(self.span);
// We needn't check `encountered_gt` to determine if we should pluralize "bracket".
// `encountered_gt` can only represent a single `>` character, if `number_of_shr >= 1`
// then there is either `>>` or `>>>` - in either case a plural is warranted.
let plural = number_of_shr >= 1;
self.diagnostic()
.struct_span_err(span, "unmatched angle bracket")
.struct_span_err(
span,
&format!("unmatched angle bracket{}", if plural { "s" } else { "" }),
)
.span_suggestion_with_applicability(
span,
"remove extra angle bracket",
&format!("remove extra angle bracket{}", if plural { "s" } else { "" }),
String::new(),
Applicability::MachineApplicable,
)