]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #107446 - clubby789:rustc-parse-diag-migrate, r=compiler-errors
authorMatthias Krüger <matthias.krueger@famsik.de>
Thu, 9 Feb 2023 10:21:57 +0000 (11:21 +0100)
committerGitHub <noreply@github.com>
Thu, 9 Feb 2023 10:21:57 +0000 (11:21 +0100)
Migrate some of `rustc_parse` to derive diagnostics

`@rustbot` label +A-translation
r? rust-lang/diagnostics
cc #100717

1  2 
compiler/rustc_error_messages/locales/en-US/parse.ftl
compiler/rustc_parse/src/errors.rs

index 581bb9a766e20640b50b5a279712f27fe4d2b35c,45f84ac4c625beac721dbba83afbad509d99c6f9..c9cf7b62071fe0daa003562de45d31585f40b3dd
@@@ -475,9 -475,6 +475,9 @@@ parse_unexpected_token_after_struct_nam
  parse_unexpected_self_in_generic_parameters = unexpected keyword `Self` in generic parameters
      .note = you cannot use `Self` as a generic parameter because it is reserved for associated items
  
 +parse_unexpected_default_value_for_lifetime_in_generic_parameters = unexpected default lifetime parameter
 +    .label = lifetime parameters cannot have default values
 +
  parse_multiple_where_clauses = cannot define duplicate `where` clauses on an item
      .label = previous `where` clause starts here
      .suggestion = consider joining the two `where` clauses into one
@@@ -585,3 -582,118 +585,118 @@@ parse_negative_bounds_not_supported = n
  parse_help_set_edition_cargo = set `edition = "{$edition}"` in `Cargo.toml`
  parse_help_set_edition_standalone = pass `--edition {$edition}` to `rustc`
  parse_note_edition_guide = for more on editions, read https://doc.rust-lang.org/edition-guide
+ parse_unexpected_token_after_dot = unexpected token: `{$actual}`
+ parse_cannot_be_raw_ident = `{$ident}` cannot be a raw identifier
+ parse_cr_doc_comment = bare CR not allowed in {$block ->
+     [true] block doc-comment
+     *[false] doc-comment
+ }
+ parse_no_digits_literal = no valid digits found for number
+ parse_invalid_digit_literal = invalid digit for a base {$base} literal
+ parse_empty_exponent_float = expected at least one digit in exponent
+ parse_float_literal_unsupported_base = {$base} float literal is not supported
+ parse_more_than_one_char = character literal may only contain one codepoint
+     .followed_by = this `{$chr}` is followed by the combining {$len ->
+         [one] mark
+         *[other] marks
+         } `{$escaped_marks}`
+     .non_printing = there are non-printing characters, the full sequence is `{$escaped}`
+     .consider_normalized = consider using the normalized form `{$ch}` of this character
+     .remove_non = consider removing the non-printing characters
+     .use_double_quotes = if you meant to write a {$is_byte ->
+         [true] byte string
+         *[false] `str`
+         } literal, use double quotes
+ parse_no_brace_unicode_escape = incorrect unicode escape sequence
+     .label = {parse_no_brace_unicode_escape}
+     .use_braces = format of unicode escape sequences uses braces
+     .format_of_unicode = format of unicode escape sequences is `\u{"{...}"}`
+ parse_invalid_unicode_escape = invalid unicode character escape
+     .label = invalid escape
+     .help = unicode escape must {$surrogate ->
+     [true] not be a surrogate
+     *[false] be at most 10FFFF
+     }
+ parse_escape_only_char = {$byte ->
+     [true] byte
+     *[false] character
+     } constant must be escaped: `{$escaped_msg}`
+     .escape = escape the character
+ parse_bare_cr = {$double_quotes ->
+     [true] bare CR not allowed in string, use `\r` instead
+     *[false] character constant must be escaped: `\r`
+     }
+     .escape = escape the character
+ parse_bare_cr_in_raw_string = bare CR not allowed in raw string
+ parse_too_short_hex_escape = numeric character escape is too short
+ parse_invalid_char_in_escape = {parse_invalid_char_in_escape_msg}: `{$ch}`
+     .label = {parse_invalid_char_in_escape_msg}
+ parse_invalid_char_in_escape_msg = invalid character in {$is_hex ->
+     [true] numeric character
+     *[false] unicode
+     } escape
+ parse_out_of_range_hex_escape = out of range hex escape
+     .label = must be a character in the range [\x00-\x7f]
+ parse_leading_underscore_unicode_escape = {parse_leading_underscore_unicode_escape_label}: `_`
+ parse_leading_underscore_unicode_escape_label = invalid start of unicode escape
+ parse_overlong_unicode_escape = overlong unicode escape
+     .label = must have at most 6 hex digits
+ parse_unclosed_unicode_escape = unterminated unicode escape
+     .label = missing a closing `{"}"}`
+     .terminate = terminate the unicode escape
+ parse_unicode_escape_in_byte = unicode escape in byte string
+     .label = {parse_unicode_escape_in_byte}
+     .help = unicode escape sequences cannot be used as a byte or in a byte string
+ parse_empty_unicode_escape = empty unicode escape
+     .label = this escape must have at least 1 hex digit
+ parse_zero_chars = empty character literal
+     .label = {parse_zero_chars}
+ parse_lone_slash = invalid trailing slash in literal
+     .label = {parse_lone_slash}
+ parse_unskipped_whitespace = non-ASCII whitespace symbol '{$ch}' is not skipped
+     .label = {parse_unskipped_whitespace}
+ parse_multiple_skipped_lines = multiple lines skipped by escaped newline
+     .label = skipping everything up to and including this point
+ parse_unknown_prefix = prefix `{$prefix}` is unknown
+     .label = unknown prefix
+     .note =  prefixed identifiers and literals are reserved since Rust 2021
+     .suggestion_br = use `br` for a raw byte string
+     .suggestion_whitespace = consider inserting whitespace here
+ parse_too_many_hashes = too many `#` symbols: raw strings may be delimited by up to 255 `#` symbols, but found {$num}
+ parse_unknown_start_of_token = unknown start of token: {$escaped}
+     .sugg_quotes = Unicode characters '“' (Left Double Quotation Mark) and '”' (Right Double Quotation Mark) look like '{$ascii_str}' ({$ascii_name}), but are not
+     .sugg_other = Unicode character '{$ch}' ({$u_name}) looks like '{$ascii_str}' ({$ascii_name}), but it is not
+     .help_null = source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used
+     .note_repeats = character appears {$repeats ->
+         [one] once more
+         *[other] {$repeats} more times
+     }
index 0c11e0026900e4c2f5b5c6abb931ca3a460f8cc4,81a727182cd89a243384d33662016c04c5fa9b3a..63bf864f2a812f8fc8de2159bbd3d677c8ff1223
@@@ -1368,6 -1368,14 +1368,14 @@@ pub(crate) struct SelfArgumentPointer 
      pub span: Span,
  }
  
+ #[derive(Diagnostic)]
+ #[diag(parse_unexpected_token_after_dot)]
+ pub struct UnexpectedTokenAfterDot<'a> {
+     #[primary_span]
+     pub span: Span,
+     pub actual: Cow<'a, str>,
+ }
  #[derive(Diagnostic)]
  #[diag(parse_visibility_not_followed_by_item)]
  #[help]
@@@ -1601,14 -1609,6 +1609,14 @@@ pub(crate) struct UnexpectedSelfInGener
      pub span: Span,
  }
  
 +#[derive(Diagnostic)]
 +#[diag(parse_unexpected_default_value_for_lifetime_in_generic_parameters)]
 +pub(crate) struct UnexpectedDefaultValueForLifetimeInGenericParameters {
 +    #[primary_span]
 +    #[label]
 +    pub span: Span,
 +}
 +
  #[derive(Diagnostic)]
  #[diag(parse_multiple_where_clauses)]
  pub(crate) struct MultipleWhereClauses {
@@@ -1658,6 -1658,310 +1666,310 @@@ pub(crate) enum TopLevelOrPatternNotAll
      },
  }
  
+ #[derive(Diagnostic)]
+ #[diag(parse_cannot_be_raw_ident)]
+ pub struct CannotBeRawIdent {
+     #[primary_span]
+     pub span: Span,
+     pub ident: Symbol,
+ }
+ #[derive(Diagnostic)]
+ #[diag(parse_cr_doc_comment)]
+ pub struct CrDocComment {
+     #[primary_span]
+     pub span: Span,
+     pub block: bool,
+ }
+ #[derive(Diagnostic)]
+ #[diag(parse_no_digits_literal, code = "E0768")]
+ pub struct NoDigitsLiteral {
+     #[primary_span]
+     pub span: Span,
+ }
+ #[derive(Diagnostic)]
+ #[diag(parse_invalid_digit_literal)]
+ pub struct InvalidDigitLiteral {
+     #[primary_span]
+     pub span: Span,
+     pub base: u32,
+ }
+ #[derive(Diagnostic)]
+ #[diag(parse_empty_exponent_float)]
+ pub struct EmptyExponentFloat {
+     #[primary_span]
+     pub span: Span,
+ }
+ #[derive(Diagnostic)]
+ #[diag(parse_float_literal_unsupported_base)]
+ pub struct FloatLiteralUnsupportedBase {
+     #[primary_span]
+     pub span: Span,
+     pub base: &'static str,
+ }
+ #[derive(Diagnostic)]
+ #[diag(parse_unknown_prefix)]
+ #[note]
+ pub struct UnknownPrefix<'a> {
+     #[primary_span]
+     #[label]
+     pub span: Span,
+     pub prefix: &'a str,
+     #[subdiagnostic]
+     pub sugg: Option<UnknownPrefixSugg>,
+ }
+ #[derive(Subdiagnostic)]
+ pub enum UnknownPrefixSugg {
+     #[suggestion(suggestion_br, code = "br", applicability = "maybe-incorrect", style = "verbose")]
+     UseBr(#[primary_span] Span),
+     #[suggestion(
+         suggestion_whitespace,
+         code = " ",
+         applicability = "maybe-incorrect",
+         style = "verbose"
+     )]
+     Whitespace(#[primary_span] Span),
+ }
+ #[derive(Diagnostic)]
+ #[diag(parse_too_many_hashes)]
+ pub struct TooManyHashes {
+     #[primary_span]
+     pub span: Span,
+     pub num: u32,
+ }
+ #[derive(Diagnostic)]
+ #[diag(parse_unknown_start_of_token)]
+ pub struct UnknownTokenStart {
+     #[primary_span]
+     pub span: Span,
+     pub escaped: String,
+     #[subdiagnostic]
+     pub sugg: Option<TokenSubstitution>,
+     #[subdiagnostic]
+     pub null: Option<UnknownTokenNull>,
+     #[subdiagnostic]
+     pub repeat: Option<UnknownTokenRepeat>,
+ }
+ #[derive(Subdiagnostic)]
+ pub enum TokenSubstitution {
+     #[suggestion(sugg_quotes, code = "{suggestion}", applicability = "maybe-incorrect")]
+     DirectedQuotes {
+         #[primary_span]
+         span: Span,
+         suggestion: String,
+         ascii_str: &'static str,
+         ascii_name: &'static str,
+     },
+     #[suggestion(sugg_other, code = "{suggestion}", applicability = "maybe-incorrect")]
+     Other {
+         #[primary_span]
+         span: Span,
+         suggestion: String,
+         ch: String,
+         u_name: &'static str,
+         ascii_str: &'static str,
+         ascii_name: &'static str,
+     },
+ }
+ #[derive(Subdiagnostic)]
+ #[note(note_repeats)]
+ pub struct UnknownTokenRepeat {
+     pub repeats: usize,
+ }
+ #[derive(Subdiagnostic)]
+ #[help(help_null)]
+ pub struct UnknownTokenNull;
+ #[derive(Diagnostic)]
+ pub enum UnescapeError {
+     #[diag(parse_invalid_unicode_escape)]
+     #[help]
+     InvalidUnicodeEscape {
+         #[primary_span]
+         #[label]
+         span: Span,
+         surrogate: bool,
+     },
+     #[diag(parse_escape_only_char)]
+     EscapeOnlyChar {
+         #[primary_span]
+         span: Span,
+         #[suggestion(escape, applicability = "machine-applicable", code = "{escaped_sugg}")]
+         char_span: Span,
+         escaped_sugg: String,
+         escaped_msg: String,
+         byte: bool,
+     },
+     #[diag(parse_bare_cr)]
+     BareCr {
+         #[primary_span]
+         #[suggestion(escape, applicability = "machine-applicable", code = "\\r")]
+         span: Span,
+         double_quotes: bool,
+     },
+     #[diag(parse_bare_cr_in_raw_string)]
+     BareCrRawString(#[primary_span] Span),
+     #[diag(parse_too_short_hex_escape)]
+     TooShortHexEscape(#[primary_span] Span),
+     #[diag(parse_invalid_char_in_escape)]
+     InvalidCharInEscape {
+         #[primary_span]
+         #[label]
+         span: Span,
+         is_hex: bool,
+         ch: String,
+     },
+     #[diag(parse_out_of_range_hex_escape)]
+     OutOfRangeHexEscape(
+         #[primary_span]
+         #[label]
+         Span,
+     ),
+     #[diag(parse_leading_underscore_unicode_escape)]
+     LeadingUnderscoreUnicodeEscape {
+         #[primary_span]
+         #[label(parse_leading_underscore_unicode_escape_label)]
+         span: Span,
+         ch: String,
+     },
+     #[diag(parse_overlong_unicode_escape)]
+     OverlongUnicodeEscape(
+         #[primary_span]
+         #[label]
+         Span,
+     ),
+     #[diag(parse_unclosed_unicode_escape)]
+     UnclosedUnicodeEscape(
+         #[primary_span]
+         #[label]
+         Span,
+         #[suggestion(terminate, code = "}}", applicability = "maybe-incorrect", style = "verbose")]
+         Span,
+     ),
+     #[diag(parse_no_brace_unicode_escape)]
+     NoBraceInUnicodeEscape {
+         #[primary_span]
+         span: Span,
+         #[label]
+         label: Option<Span>,
+         #[subdiagnostic]
+         sub: NoBraceUnicodeSub,
+     },
+     #[diag(parse_unicode_escape_in_byte)]
+     #[help]
+     UnicodeEscapeInByte(
+         #[primary_span]
+         #[label]
+         Span,
+     ),
+     #[diag(parse_empty_unicode_escape)]
+     EmptyUnicodeEscape(
+         #[primary_span]
+         #[label]
+         Span,
+     ),
+     #[diag(parse_zero_chars)]
+     ZeroChars(
+         #[primary_span]
+         #[label]
+         Span,
+     ),
+     #[diag(parse_lone_slash)]
+     LoneSlash(
+         #[primary_span]
+         #[label]
+         Span,
+     ),
+     #[diag(parse_unskipped_whitespace)]
+     UnskippedWhitespace {
+         #[primary_span]
+         span: Span,
+         #[label]
+         char_span: Span,
+         ch: String,
+     },
+     #[diag(parse_multiple_skipped_lines)]
+     MultipleSkippedLinesWarning(
+         #[primary_span]
+         #[label]
+         Span,
+     ),
+     #[diag(parse_more_than_one_char)]
+     MoreThanOneChar {
+         #[primary_span]
+         span: Span,
+         #[subdiagnostic]
+         note: Option<MoreThanOneCharNote>,
+         #[subdiagnostic]
+         suggestion: MoreThanOneCharSugg,
+     },
+ }
+ #[derive(Subdiagnostic)]
+ pub enum MoreThanOneCharSugg {
+     #[suggestion(consider_normalized, code = "{normalized}", applicability = "machine-applicable")]
+     NormalizedForm {
+         #[primary_span]
+         span: Span,
+         ch: String,
+         normalized: String,
+     },
+     #[suggestion(remove_non, code = "{ch}", applicability = "maybe-incorrect")]
+     RemoveNonPrinting {
+         #[primary_span]
+         span: Span,
+         ch: String,
+     },
+     #[suggestion(use_double_quotes, code = "{sugg}", applicability = "machine-applicable")]
+     Quotes {
+         #[primary_span]
+         span: Span,
+         is_byte: bool,
+         sugg: String,
+     },
+ }
+ #[derive(Subdiagnostic)]
+ pub enum MoreThanOneCharNote {
+     #[note(followed_by)]
+     AllCombining {
+         #[primary_span]
+         span: Span,
+         chr: String,
+         len: usize,
+         escaped_marks: String,
+     },
+     #[note(non_printing)]
+     NonPrinting {
+         #[primary_span]
+         span: Span,
+         escaped: String,
+     },
+ }
+ #[derive(Subdiagnostic)]
+ pub enum NoBraceUnicodeSub {
+     #[suggestion(use_braces, code = "{suggestion}", applicability = "maybe-incorrect")]
+     Suggestion {
+         #[primary_span]
+         span: Span,
+         suggestion: String,
+     },
+     #[help(format_of_unicode)]
+     Help,
+ }
  #[derive(Subdiagnostic)]
  pub(crate) enum TopLevelOrPatternNotAllowedSugg {
      #[suggestion(