Rollup merge of #152235 - JonathanBrouwer:convert_parse, r=JonathanBrouwer

Convert to inline diagnostics in `rustc_parse`

This was the most annoying one by far, had to make a few changes to the representation of two errors (no user-facing changes tho), these changes are in separate commits for clarity :)

For https://github.com/rust-lang/rust/issues/151366
r? @jdonszelmann
This commit is contained in:
Jonathan Brouwer
2026-02-07 13:06:34 +01:00
committed by GitHub
18 changed files with 1448 additions and 1796 deletions
-1
View File
@@ -4381,7 +4381,6 @@ dependencies = [
"rustc_data_structures",
"rustc_errors",
"rustc_feature",
"rustc_fluent_macro",
"rustc_index",
"rustc_lexer",
"rustc_macros",
-1
View File
@@ -114,7 +114,6 @@ pub fn default_translator() -> Translator {
pub static DEFAULT_LOCALE_RESOURCES: &[&str] = &[
// tidy-alphabetical-start
rustc_lint::DEFAULT_LOCALE_RESOURCE,
rustc_parse::DEFAULT_LOCALE_RESOURCE,
// tidy-alphabetical-end
];
+6 -8
View File
@@ -53,10 +53,9 @@ pub struct Compiler {
pub(crate) fn parse_cfg(dcx: DiagCtxtHandle<'_>, cfgs: Vec<String>) -> Cfg {
cfgs.into_iter()
.map(|s| {
let psess = ParseSess::emitter_with_note(
vec![rustc_parse::DEFAULT_LOCALE_RESOURCE],
format!("this occurred on the command line: `--cfg={s}`"),
);
let psess = ParseSess::emitter_with_note(format!(
"this occurred on the command line: `--cfg={s}`"
));
let filename = FileName::cfg_spec_source_code(&s);
macro_rules! error {
@@ -125,10 +124,9 @@ pub(crate) fn parse_check_cfg(dcx: DiagCtxtHandle<'_>, specs: Vec<String>) -> Ch
let mut check_cfg = CheckCfg { exhaustive_names, exhaustive_values, ..CheckCfg::default() };
for s in specs {
let psess = ParseSess::emitter_with_note(
vec![rustc_parse::DEFAULT_LOCALE_RESOURCE],
format!("this occurred on the command line: `--check-cfg={s}`"),
);
let psess = ParseSess::emitter_with_note(format!(
"this occurred on the command line: `--check-cfg={s}`"
));
let filename = FileName::cfg_spec_source_code(&s);
const VISIT: &str =
@@ -3,6 +3,7 @@
use proc_macro2::{Span, TokenStream};
use quote::quote;
use syn::Path;
use syn::ext::IdentExt;
use synstructure::{Structure, VariantInfo};
use crate::diagnostics::error::span_err;
@@ -100,7 +101,7 @@ fn verify_fluent_message(msg_span: Span, message_str: &str, variant: Option<&Var
.bindings()
.iter()
.flat_map(|b| b.ast().ident.as_ref())
.map(|id| id.to_string())
.map(|id| id.unraw().to_string())
.collect();
for variable in variable_references(&message) {
if !fields.iter().any(|f| f == variable) {
@@ -155,6 +156,8 @@ fn variable_references<'a>(msg: &fluent_syntax::ast::Message<&'a str>) -> Vec<&'
"MIR",
"NaNs",
"OK",
"Rust",
"Unicode",
"VS",
// tidy-alphabetical-end
];
-1
View File
@@ -12,7 +12,6 @@ rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
rustc_feature = { path = "../rustc_feature" }
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
rustc_index = { path = "../rustc_index" }
rustc_lexer = { path = "../rustc_lexer" }
rustc_macros = { path = "../rustc_macros" }
-1043
View File
@@ -1,1043 +0,0 @@
parse_add_paren = try adding parentheses
parse_ambiguous_range_pattern = the range pattern here has ambiguous interpretation
parse_ambiguous_range_pattern_suggestion = add parentheses to clarify the precedence
parse_array_brackets_instead_of_braces = this is a block expression, not an array
.suggestion = to make an array, use square brackets instead of curly braces
parse_array_index_offset_of = array indexing not supported in offset_of
parse_asm_expected_comma = expected token: `,`
.label = expected `,`
parse_asm_expected_other = expected operand, {$is_inline_asm ->
[false] options
*[true] clobber_abi, options
}, or additional template string
parse_asm_expected_register_class_or_explicit_register = expected register class or explicit register
parse_asm_expected_string_literal = expected string literal
.label = not a string literal
parse_asm_non_abi = at least one abi must be provided as an argument to `clobber_abi`
parse_asm_requires_template = requires at least a template string argument
parse_asm_sym_no_path = expected a path for argument to `sym`
parse_asm_underscore_input = _ cannot be used for input operands
parse_asm_unsupported_operand = the `{$symbol}` operand cannot be used with `{$macro_name}!`
.label = the `{$symbol}` operand is not meaningful for global-scoped inline assembly, remove it
parse_assignment_else_not_allowed = <assignment> ... else {"{"} ... {"}"} is not allowed
parse_associated_static_item_not_allowed = associated `static` items are not allowed
parse_async_block_in_2015 = `async` blocks are only allowed in Rust 2018 or later
parse_async_bound_modifier_in_2015 = `async` trait bounds are only allowed in Rust 2018 or later
parse_async_fn_in_2015 = `async fn` is not permitted in Rust 2015
.label = to use `async fn`, switch to Rust 2018 or later
parse_async_impl = `async` trait implementations are unsupported
parse_async_move_block_in_2015 = `async move` blocks are only allowed in Rust 2018 or later
parse_async_move_order_incorrect = the order of `move` and `async` is incorrect
.suggestion = try switching the order
parse_async_use_block_in_2015 = `async use` blocks are only allowed in Rust 2018 or later
parse_async_use_order_incorrect = the order of `use` and `async` is incorrect
.suggestion = try switching the order
parse_at_dot_dot_in_struct_pattern = `@ ..` is not supported in struct patterns
.suggestion = bind to each field separately or, if you don't need them, just remove `{$ident} @`
parse_at_in_struct_pattern = unexpected `@` in struct pattern
.note = struct patterns use `field: pattern` syntax to bind to fields
.help = consider replacing `new_name @ field_name` with `field_name: new_name` if that is what you intended
parse_attr_after_generic = trailing attribute after generic parameter
.label = attributes must go before parameters
parse_attr_without_generics = attribute without generic parameters
.label = attributes are only permitted when preceding parameters
parse_attribute_on_empty_type = attributes cannot be applied here
.label = attributes are not allowed here
parse_attribute_on_generic_arg = attributes cannot be applied to generic arguments
.label = attributes are not allowed here
.suggestion = remove attribute from here
parse_attribute_on_param_type = attributes cannot be applied to a function parameter's type
.label = attributes are not allowed here
parse_attribute_on_type = attributes cannot be applied to types
.label = attributes are not allowed here
.suggestion = remove attribute from here
parse_bad_assoc_type_bounds = bounds on associated types do not belong here
.label = belongs in `where` clause
parse_bad_item_kind = {$descr} is not supported in {$ctx}
.help = consider moving the {$descr} out to a nearby module scope
parse_bad_return_type_notation_output =
return type not allowed with return type notation
.suggestion = remove the return type
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_frontmatter = bare CR not allowed in frontmatter
parse_bare_cr_in_raw_string = bare CR not allowed in raw string
parse_binder_and_polarity = `for<...>` binder not allowed with `{$polarity}` trait polarity modifier
.label = there is not a well-defined meaning for a higher-ranked `{$polarity}` trait
parse_binder_before_modifiers = `for<...>` binder should be placed before trait bound modifiers
.label = place the `for<...>` binder before any modifiers
parse_bounds_not_allowed_on_trait_aliases = bounds are not allowed on trait aliases
parse_box_not_pat = expected pattern, found {$descr}
.note = `box` is a reserved keyword
.suggestion = escape `box` to use it as an identifier
parse_box_syntax_removed = `box_syntax` has been removed
parse_box_syntax_removed_suggestion = use `Box::new()` instead
parse_cannot_be_raw_ident = `{$ident}` cannot be a raw identifier
parse_cannot_be_raw_lifetime = `{$ident}` cannot be a raw lifetime
parse_catch_after_try = keyword `catch` cannot follow a `try` block
.help = try using `match` on the result of the `try` block instead
parse_colon_as_semi = statements are terminated with a semicolon
.suggestion = use a semicolon instead
parse_comma_after_base_struct = cannot use a comma after the base struct
.note = the base struct must always be the last field
.suggestion = remove this comma
parse_comparison_interpreted_as_generic =
`<` is interpreted as a start of generic arguments for `{$type}`, not a comparison
.label_args = interpreted as generic arguments
.label_comparison = not interpreted as comparison
.suggestion = try comparing the cast value
parse_comparison_operators_cannot_be_chained = comparison operators cannot be chained
.sugg_parentheses_for_function_args = or use `(...)` if you meant to specify fn arguments
.sugg_split_comparison = split the comparison into two
.sugg_parenthesize = parenthesize the comparison
parse_compound_assignment_expression_in_let = can't reassign to an uninitialized variable
.suggestion = initialize the variable
.help = if you meant to overwrite, remove the `let` binding
parse_const_generic_without_braces = expressions must be enclosed in braces to be used as const generic arguments
.suggestion = enclose the `const` expression in braces
parse_const_global_cannot_be_mutable = const globals cannot be mutable
.label = cannot be mutable
.suggestion = you might want to declare a static instead
parse_const_let_mutually_exclusive = `const` and `let` are mutually exclusive
.suggestion = remove `let`
parse_cr_doc_comment = bare CR not allowed in {$block ->
[true] block doc-comment
*[false] doc-comment
}
parse_default_not_followed_by_item = `default` is not followed by an item
.label = the `default` qualifier
.note = only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`
parse_delegation_non_trait_impl_reuse = only trait impls can be reused
parse_do_catch_syntax_removed = found removed `do catch` syntax
.note = following RFC #2388, the new non-placeholder syntax is `try`
.suggestion = replace with the new syntax
parse_doc_comment_does_not_document_anything = found a documentation comment that doesn't document anything
.help = doc comments must come before what they document, if a comment was intended use `//`
.suggestion = missing comma here
parse_doc_comment_on_param_type = documentation comments cannot be applied to a function parameter's type
.label = doc comments are not allowed here
parse_dot_dot_dot_for_remaining_fields = expected field pattern, found `{$token_str}`
.suggestion = to omit remaining fields, use `..`
parse_dot_dot_dot_range_to_pattern_not_allowed = range-to patterns with `...` are not allowed
.suggestion = use `..=` instead
parse_dot_dot_range_attribute = attributes are not allowed on range expressions starting with `..`
parse_dotdotdot = unexpected token: `...`
.suggest_exclusive_range = use `..` for an exclusive range
.suggest_inclusive_range = or `..=` for an inclusive range
parse_dotdotdot_rest_pattern = unexpected `...`
.label = not a valid pattern
.suggestion = for a rest pattern, use `..` instead of `...`
.note = only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
parse_dotdotdot_rest_type = unexpected `...`
.note = only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
parse_double_colon_in_bound = expected `:` followed by trait or lifetime
.suggestion = use single colon
parse_dyn_after_mut = `mut` must precede `dyn`
.suggestion = place `mut` before `dyn`
parse_empty_exponent_float = expected at least one digit in exponent
parse_empty_unicode_escape = empty unicode escape
.label = this escape must have at least 1 hex digit
parse_enum_pattern_instead_of_identifier = expected identifier, found enum pattern
parse_enum_struct_mutually_exclusive = `enum` and `struct` are mutually exclusive
.suggestion = replace `enum struct` with
parse_eq_field_init = expected `:`, found `=`
.suggestion = replace equals symbol with a colon
parse_escape_only_char = {$byte ->
[true] byte
*[false] character
} constant must be escaped: `{$escaped_msg}`
.escape = escape the character
parse_expect_dotdot_not_dotdotdot = expected `..`, found `...`
.suggestion = use `..` to fill in the rest of the fields
parse_expect_eq_instead_of_eqeq = expected `=`, found `==`
.suggestion = consider using `=` here
parse_expect_label_found_ident = expected a label, found an identifier
.suggestion = labels start with a tick
parse_expect_path = expected a path
parse_expected_binding_left_of_at = left-hand side of `@` must be a binding
.label_lhs = interpreted as a pattern, not a binding
.label_rhs = also a pattern
.note = bindings are `x`, `mut x`, `ref x`, and `ref mut x`
parse_expected_builtin_ident = expected identifier after `builtin #`
parse_expected_comma_after_pattern_field = expected `,`
parse_expected_else_block = expected `{"{"}`, found {$first_tok}
.label = expected an `if` or a block after this `else`
.suggestion = add an `if` if this is the condition of a chained `else if` statement
parse_expected_expression_found_let = expected expression, found `let` statement
.note = only supported directly in conditions of `if` and `while` expressions
.not_supported_or = `||` operators are not supported in let chain expressions
.not_supported_parentheses = `let`s wrapped in parentheses are not supported in a context with let chains
parse_expected_fn_path_found_fn_keyword = expected identifier, found keyword `fn`
.suggestion = use `Fn` to refer to the trait
parse_expected_identifier = expected identifier
parse_expected_identifier_found_doc_comment = expected identifier, found doc comment
parse_expected_identifier_found_doc_comment_str = expected identifier, found doc comment `{$token}`
parse_expected_identifier_found_keyword = expected identifier, found keyword
parse_expected_identifier_found_keyword_str = expected identifier, found keyword `{$token}`
parse_expected_identifier_found_metavar = expected identifier, found metavariable
# This one deliberately doesn't print a token.
parse_expected_identifier_found_metavar_str = expected identifier, found metavariable
parse_expected_identifier_found_reserved_identifier = expected identifier, found reserved identifier
parse_expected_identifier_found_reserved_identifier_str = expected identifier, found reserved identifier `{$token}`
parse_expected_identifier_found_reserved_keyword = expected identifier, found reserved keyword
parse_expected_identifier_found_reserved_keyword_str = expected identifier, found reserved keyword `{$token}`
parse_expected_identifier_found_str = expected identifier, found `{$token}`
parse_expected_mut_or_const_in_raw_pointer_type = expected `mut` or `const` keyword in raw pointer type
.suggestion = add `mut` or `const` here
parse_expected_semi_found_doc_comment_str = expected `;`, found doc comment `{$token}`
parse_expected_semi_found_keyword_str = expected `;`, found keyword `{$token}`
# This one deliberately doesn't print a token.
parse_expected_semi_found_metavar_str = expected `;`, found metavariable
parse_expected_semi_found_reserved_identifier_str = expected `;`, found reserved identifier `{$token}`
parse_expected_semi_found_reserved_keyword_str = expected `;`, found reserved keyword `{$token}`
parse_expected_semi_found_str = expected `;`, found `{$token}`
parse_expected_statement_after_outer_attr = expected statement after outer attribute
parse_expected_struct_field = expected one of `,`, `:`, or `{"}"}`, found `{$token}`
.label = expected one of `,`, `:`, or `{"}"}`
.ident_label = while parsing this struct field
parse_expected_trait_in_trait_impl_found_type = expected a trait, found type
parse_expr_rarrow_call = `->` is not valid syntax for field accesses and method calls
.suggestion = try using `.` instead
.help = the `.` operator will automatically dereference the value, except if the value is a raw pointer
parse_extern_crate_name_with_dashes = crate name using dashes are not valid in `extern crate` statements
.label = dash-separated idents are not valid
.suggestion = if the original crate name uses dashes you need to use underscores in the code
parse_extern_item_cannot_be_const = extern items cannot be `const`
.suggestion = try using a static value
.note = for more information, visit https://doc.rust-lang.org/std/keyword.extern.html
parse_extra_if_in_let_else = remove the `if` if you meant to write a `let...else` statement
parse_extra_impl_keyword_in_trait_impl = unexpected `impl` keyword
.suggestion = remove the extra `impl`
.note = this is parsed as an `impl Trait` type, but a trait is expected at this position
parse_field_expression_with_generic = field expressions cannot have generic arguments
parse_float_literal_requires_integer_part = float literals must have an integer part
.suggestion = must have an integer part
parse_float_literal_unsupported_base = {$base} float literal is not supported
parse_fn_pointer_cannot_be_async = an `fn` pointer type cannot be `async`
.label = `async` because of this
.suggestion = remove the `async` qualifier
.note = allowed qualifiers are: `unsafe` and `extern`
parse_fn_pointer_cannot_be_const = an `fn` pointer type cannot be `const`
.label = `const` because of this
.suggestion = remove the `const` qualifier
.note = allowed qualifiers are: `unsafe` and `extern`
parse_fn_ptr_with_generics = function pointer types may not have generic parameters
.suggestion = consider moving the lifetime {$arity ->
[one] parameter
*[other] parameters
} to {$for_param_list_exists ->
[true] the
*[false] a
} `for` parameter list
parse_fn_trait_missing_paren = `Fn` bounds require arguments in parentheses
.add_paren = add the missing parentheses
parse_forgot_paren = perhaps you forgot parentheses?
parse_found_expr_would_be_stmt = expected expression, found `{$token}`
.label = expected expression
parse_frontmatter_extra_characters_after_close = extra characters after frontmatter close are not allowed
parse_frontmatter_invalid_close_preceding_whitespace = invalid preceding whitespace for frontmatter close
.note = frontmatter close should not be preceded by whitespace
parse_frontmatter_invalid_infostring = invalid infostring for frontmatter
.note = frontmatter infostrings must be a single identifier immediately following the opening
parse_frontmatter_invalid_opening_preceding_whitespace = invalid preceding whitespace for frontmatter opening
.note = frontmatter opening should not be preceded by whitespace
parse_frontmatter_length_mismatch = frontmatter close does not match the opening
.label_opening = the opening here has {$len_opening} dashes...
.label_close = ...while the close has {$len_close} dashes
parse_frontmatter_too_many_dashes = too many `-` symbols: frontmatter openings may be delimited by up to 255 `-` symbols, but found {$len_opening}
parse_frontmatter_unclosed = unclosed frontmatter
.note = frontmatter opening here was not closed
parse_function_body_equals_expr = function body cannot be `= expression;`
.suggestion = surround the expression with `{"{"}` and `{"}"}` instead of `=` and `;`
parse_generic_args_in_pat_require_turbofish_syntax = generic args in patterns require the turbofish syntax
parse_generic_parameters_without_angle_brackets = generic parameters without surrounding angle brackets
.suggestion = surround the type parameters with angle brackets
parse_generics_in_path = unexpected generic arguments in path
parse_help_set_edition_cargo = set `edition = "{$edition}"` in `Cargo.toml`
parse_help_set_edition_standalone = pass `--edition {$edition}` to `rustc`
parse_hidden_unicode_codepoints = unicode codepoint changing visible direction of text present in {$label}
.label = this {$label} contains {$count ->
[one] an invisible
*[other] invisible
} unicode text flow control {$count ->
[one] codepoint
*[other] codepoints
}
.note = these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen
.suggestion_remove = if their presence wasn't intentional, you can remove them
.suggestion_escape = if you want to keep them but make them visible in your source code, you can escape them
.no_suggestion_note_escape = if you want to keep them but make them visible in your source code, you can escape them: {$escaped}
parse_if_expression_missing_condition = missing condition for `if` expression
.condition_label = expected condition here
.block_label = if this block is the condition of the `if` expression, then it must be followed by another block
parse_if_expression_missing_then_block = this `if` expression is missing a block after the condition
.add_then_block = add a block here
.condition_possibly_unfinished = this binary operation is possibly unfinished
parse_in_in_typo =
expected iterable, found keyword `in`
.suggestion = remove the duplicated `in`
parse_inappropriate_default = {$article} {$descr} cannot be `default`
.label = `default` because of this
.note = only associated `fn`, `const`, and `type` items can be `default`
parse_inclusive_range_extra_equals = unexpected `=` after inclusive range
.suggestion_remove_eq = use `..=` instead
.note = inclusive ranges end with a single equals sign (`..=`)
parse_inclusive_range_match_arrow = unexpected `>` after inclusive range
.label = this is parsed as an inclusive range `..=`
.suggestion = add a space between the pattern and `=>`
parse_inclusive_range_no_end = inclusive range with no end
.suggestion_open_range = use `..` instead
.note = inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
parse_incorrect_parens_trait_bounds = incorrect parentheses around trait bounds
parse_incorrect_parens_trait_bounds_sugg = fix the parentheses
parse_incorrect_semicolon =
expected item, found `;`
.suggestion = remove this semicolon
.help = {$name} declarations are not followed by a semicolon
parse_incorrect_type_on_self = type not allowed for shorthand `self` parameter
.suggestion = move the modifiers on `self` to the type
parse_incorrect_use_of_await = incorrect use of `await`
.parentheses_suggestion = `await` is not a method call, remove the parentheses
parse_incorrect_use_of_await_postfix_suggestion = `await` is a postfix operation
parse_incorrect_use_of_use = incorrect use of `use`
.parentheses_suggestion = `use` is not a method call, try removing the parentheses
parse_incorrect_visibility_restriction = incorrect visibility restriction
.help = some possible visibility restrictions are:
`pub(crate)`: visible only on the current crate
`pub(super)`: visible only in the current module's parent
`pub(in path::to::module)`: visible only on the specified path
.suggestion = make this visible only to module `{$inner_str}` with `in`
parse_inner_attr_explanation = inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files
parse_inner_attr_not_permitted = an inner attribute is not permitted in this context
.label_does_not_annotate_this = {parse_label_inner_attr_does_not_annotate_this}
.sugg_change_inner_to_outer = {parse_sugg_change_inner_attr_to_outer}
parse_inner_attr_not_permitted_after_outer_attr = an inner attribute is not permitted following an outer attribute
.label_attr = not permitted following an outer attribute
.label_prev_attr = previous outer attribute
.label_does_not_annotate_this = {parse_label_inner_attr_does_not_annotate_this}
.sugg_change_inner_to_outer = {parse_sugg_change_inner_attr_to_outer}
parse_inner_attr_not_permitted_after_outer_doc_comment = an inner attribute is not permitted following an outer doc comment
.label_attr = not permitted following an outer doc comment
.label_prev_doc_comment = previous doc comment
.label_does_not_annotate_this = {parse_label_inner_attr_does_not_annotate_this}
.sugg_change_inner_to_outer = {parse_sugg_change_inner_attr_to_outer}
parse_inner_doc_comment_not_permitted = expected outer doc comment
.note = inner doc comments like this (starting with `//!` or `/*!`) can only appear before items
.suggestion = you might have meant to write a regular comment
.label_does_not_annotate_this = the inner doc comment doesn't annotate this {$item}
.sugg_change_inner_to_outer = to annotate the {$item}, change the doc comment from inner to outer style
parse_invalid_block_macro_segment = cannot use a `block` macro fragment here
.label = the `block` fragment is within this context
.suggestion = wrap this in another block
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_invalid_comparison_operator = invalid comparison operator `{$invalid}`
.use_instead = `{$invalid}` is not a valid comparison operator, use `{$correct}`
.spaceship_operator_invalid = `<=>` is not a valid comparison operator, use `std::cmp::Ordering`
parse_invalid_curly_in_let_else = right curly brace `{"}"}` before `else` in a `let...else` statement not allowed
parse_invalid_digit_literal = invalid digit for a base {$base} literal
parse_invalid_dyn_keyword = invalid `dyn` keyword
.help = `dyn` is only needed at the start of a trait `+`-separated list
.suggestion = remove this keyword
parse_invalid_expression_in_let_else = a `{$operator}` expression cannot be directly assigned in `let...else`
parse_invalid_identifier_with_leading_number = identifiers cannot start with a number
parse_invalid_literal_suffix_on_tuple_index = suffixes on a tuple index are invalid
.label = invalid suffix `{$suffix}`
parse_invalid_logical_operator = `{$incorrect}` is not a logical operator
.note = unlike in e.g., Python and PHP, `&&` and `||` are used for logical operators
.use_amp_amp_for_conjunction = use `&&` to perform logical conjunction
.use_pipe_pipe_for_disjunction = use `||` to perform logical disjunction
parse_invalid_meta_item = expected unsuffixed literal, found {$descr}
.quote_ident_sugg = surround the identifier with quotation marks to make it into a string literal
parse_invalid_offset_of = offset_of expects dot-separated field and variant names
parse_invalid_path_sep_in_fn_definition = invalid path separator in function definition
.suggestion = remove invalid path separator
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_invalid_variable_declaration =
invalid variable declaration
parse_keyword_label = labels cannot use keyword names
parse_keyword_lifetime =
lifetimes cannot use keyword names
parse_kw_bad_case = keyword `{$kw}` is written in the wrong case
.suggestion = write it in {$case}
parse_label_inner_attr_does_not_annotate_this = the inner attribute doesn't annotate this {$item}
parse_label_unexpected_token = unexpected token
parse_label_while_parsing_or_pattern_here = while parsing this or-pattern starting here
parse_labeled_loop_in_break = parentheses are required around this expression to avoid confusion with a labeled break expression
parse_leading_plus_not_supported = leading `+` is not supported
.label = unexpected `+`
.suggestion_remove_plus = try removing the `+`
parse_leading_underscore_unicode_escape = {parse_leading_underscore_unicode_escape_label}: `_`
parse_leading_underscore_unicode_escape_label = invalid start of unicode escape
parse_left_arrow_operator = unexpected token: `<-`
.suggestion = if you meant to write a comparison against a negative value, add a space in between `<` and `-`
parse_let_chain_pre_2024 = let chains are only allowed in Rust 2024 or later
parse_lifetime_after_mut = lifetime must precede `mut`
.suggestion = place the lifetime before `mut`
parse_lifetime_in_borrow_expression = borrow expressions cannot be annotated with lifetimes
.suggestion = remove the lifetime annotation
.label = annotated with lifetime here
parse_lifetime_in_eq_constraint = lifetimes are not permitted in this context
.label = lifetime is not allowed here
.context_label = this introduces an associated item binding
.help = if you meant to specify a trait object, write `dyn /* Trait */ + {$lifetime}`
.colon_sugg = you might have meant to write a bound here
parse_lone_slash = invalid trailing slash in literal
.label = {parse_lone_slash}
parse_loop_else = `{$loop_kind}...else` loops are not supported
.note = consider moving this `else` clause to a separate `if` statement and use a `bool` variable to control if it should run
.loop_keyword = `else` is attached to this loop
parse_macro_expands_to_adt_field = macros cannot expand to {$adt_ty} fields
parse_macro_expands_to_enum_variant = macros cannot expand to enum variants
parse_macro_invocation_visibility = can't qualify macro invocation with `pub`
.suggestion = remove the visibility
.help = try adjusting the macro to put `{$vis}` inside the invocation
parse_macro_invocation_with_qualified_path = macros cannot use qualified paths
parse_macro_name_remove_bang = macro names aren't followed by a `!`
.suggestion = remove the `!`
parse_macro_rules_missing_bang = expected `!` after `macro_rules`
.suggestion = add a `!`
parse_macro_rules_visibility = can't qualify macro_rules invocation with `{$vis}`
.suggestion = try exporting the macro
parse_malformed_loop_label = malformed loop label
.suggestion = use the correct loop label format
parse_match_arm_body_without_braces = `match` arm body without braces
.label_statements = {$num_statements ->
[one] this statement is not surrounded by a body
*[other] these statements are not surrounded by a body
}
.label_arrow = while parsing the `match` arm starting here
.suggestion_add_braces = surround the {$num_statements ->
[one] statement
*[other] statements
} with a body
.suggestion_use_comma_not_semicolon = replace `;` with `,` to end a `match` arm expression
parse_maybe_comparison = you might have meant to compare for equality
parse_maybe_fn_typo_with_impl = you might have meant to write `impl` instead of `fn`
.suggestion = replace `fn` with `impl` here
parse_maybe_missing_let = you might have meant to continue the let-chain
parse_maybe_recover_from_bad_qpath_stage_2 =
missing angle brackets in associated item path
.suggestion = types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
parse_maybe_recover_from_bad_type_plus =
expected a path on the left-hand side of `+`
parse_maybe_report_ambiguous_plus =
ambiguous `+` in a type
.suggestion = use parentheses to disambiguate
parse_mismatched_closing_delimiter = mismatched closing delimiter: `{$delimiter}`
.label_unmatched = mismatched closing delimiter
.label_opening_candidate = closing delimiter possibly meant for this
.label_unclosed = unclosed delimiter
parse_misplaced_return_type = place the return type after the function parameters
parse_missing_comma_after_match_arm = expected `,` following `match` arm
.suggestion = missing a comma here to end this `match` arm
parse_missing_const_type = missing type for `{$kind}` item
.suggestion = provide a type for the item
parse_missing_enum_for_enum_definition = missing `enum` for enum definition
.suggestion = add `enum` here to parse `{$ident}` as an enum
parse_missing_enum_or_struct_for_item_definition = missing `enum` or `struct` for enum or struct definition
parse_missing_expression_in_for_loop = missing expression to iterate on in `for` loop
.suggestion = try adding an expression to the `for` loop
parse_missing_fn_for_function_definition = missing `fn` for function definition
.suggestion = add `fn` here to parse `{$ident}` as a function
parse_missing_fn_for_method_definition = missing `fn` for method definition
.suggestion = add `fn` here to parse `{$ident}` as a method
parse_missing_fn_or_struct_for_item_definition = missing `fn` or `struct` for function or struct definition
.suggestion = if you meant to call a macro, try
.help = if you meant to call a macro, remove the `pub` and add a trailing `!` after the identifier
parse_missing_fn_params = missing parameters for function definition
.suggestion = add a parameter list
parse_missing_for_in_trait_impl = missing `for` in a trait impl
.suggestion = add `for` here
parse_missing_in_in_for_loop = missing `in` in `for` loop
.use_in = try using `in` here instead
.add_in = try adding `in` here
parse_missing_let_before_mut = missing keyword
parse_missing_plus_in_bounds = expected `+` between lifetime and {$sym}
.suggestion = add `+`
parse_missing_semicolon_before_array = expected `;`, found `[`
.suggestion = consider adding `;` here
parse_missing_struct_for_struct_definition = missing `struct` for struct definition
.suggestion = add `struct` here to parse `{$ident}` as a struct
parse_missing_trait_in_trait_impl = missing trait in a trait impl
.suggestion_add_trait = add a trait here
.suggestion_remove_for = for an inherent impl, drop this `for`
parse_misspelled_kw = {$is_incorrect_case ->
[true] write keyword `{$similar_kw}` in lowercase
*[false] there is a keyword `{$similar_kw}` with a similar name
}
parse_modifier_lifetime = `{$modifier}` may only modify trait bounds, not lifetime bounds
.suggestion = remove the `{$modifier}`
parse_modifiers_and_polarity = `{$modifiers_concatenated}` trait not allowed with `{$polarity}` trait polarity modifier
.label = there is not a well-defined meaning for a `{$modifiers_concatenated} {$polarity}` trait
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] string
} literal, use double quotes
parse_multiple_skipped_lines = multiple lines skipped by escaped newline
.label = skipping everything up to and including this point
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
parse_mut_on_nested_ident_pattern = `mut` must be attached to each individual binding
.suggestion = add `mut` to each binding
parse_mut_on_non_ident_pattern = `mut` must be followed by a named binding
.suggestion = remove the `mut` prefix
parse_need_plus_after_trait_object_lifetime = lifetimes must be followed by `+` to form a trait object type
.suggestion = consider adding a trait bound after the potential lifetime bound
parse_nested_adt = `{$kw_str}` definition cannot be nested inside `{$keyword}`
.suggestion = consider creating a new `{$kw_str}` definition instead of nesting
parse_nested_c_variadic_type = C-variadic type `...` may not be nested inside another type
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_no_digits_literal = no valid digits found for number
parse_non_string_abi_literal = non-string ABI literal
.suggestion = specify the ABI with a string literal
parse_nonterminal_expected_ident = expected ident, found `{$token}`
parse_nonterminal_expected_item_keyword = expected an item keyword
parse_nonterminal_expected_lifetime = expected a lifetime, found `{$token}`
parse_nonterminal_expected_statement = expected a statement
parse_note_edition_guide = for more on editions, read https://doc.rust-lang.org/edition-guide
parse_note_mut_pattern_usage = `mut` may be followed by `variable` and `variable @ pattern`
parse_note_pattern_alternatives_use_single_vert = alternatives in or-patterns are separated with `|`, not `||`
parse_nul_in_c_str = null characters in C string literals are not supported
parse_or_in_let_chain = `||` operators are not supported in let chain conditions
parse_or_pattern_not_allowed_in_fn_parameters = function parameters require top-level or-patterns in parentheses
parse_or_pattern_not_allowed_in_let_binding = `let` bindings require top-level or-patterns in parentheses
parse_outer_attr_explanation = outer attributes, like `#[test]`, annotate the item following them
parse_outer_attribute_not_allowed_on_if_else = outer attributes are not allowed on `if` and `else` branches
.branch_label = the attributes are attached to this branch
.ctx_label = the branch belongs to this `{$ctx}`
.suggestion = remove the attributes
parse_overlong_unicode_escape = overlong unicode escape
.label = must have at most 6 hex digits
parse_parentheses_with_struct_fields = invalid `struct` delimiters or `fn` call arguments
.suggestion_braces_for_struct = if `{$type}` is a struct, use braces as delimiters
.suggestion_no_fields_for_fn = if `{$type}` is a function, use the arguments directly
parse_path_double_colon = path separator must be a double colon
.suggestion = use a double colon instead
parse_path_found_attribute_in_params = `Trait(...)` syntax does not support attributes in parameters
.suggestion = remove the attributes
parse_path_found_c_variadic_params = `Trait(...)` syntax does not support c_variadic parameters
.suggestion = remove the `...`
parse_path_found_named_params = `Trait(...)` syntax does not support named parameters
.suggestion = remove the parameter name
parse_pattern_method_param_without_body = patterns aren't allowed in methods without bodies
.suggestion = give this argument a name or use an underscore to ignore it
parse_pattern_on_wrong_side_of_at = pattern on wrong side of `@`
.label_pattern = pattern on the left, should be on the right
.label_binding = binding on the right, should be on the left
.suggestion = switch the order
parse_question_mark_in_type = invalid `?` in type
.label = `?` is only allowed on expressions, not types
.suggestion = if you meant to express that the type might not contain a value, use the `Option` wrapper type
parse_recover_import_as_use = expected item, found {$token_name}
.suggestion = items are imported using the `use` keyword
parse_remove_let = expected pattern, found `let`
.suggestion = remove the unnecessary `let` keyword
parse_repeated_mut_in_pattern = `mut` on a binding may not be repeated
.suggestion = remove the additional `mut`s
parse_require_colon_after_labeled_expression = labeled expression must be followed by `:`
.note = labels are used before loops and blocks, allowing e.g., `break 'label` to them
.label = the label
.suggestion = add `:` after the label
parse_reserved_multihash = reserved multi-hash token is forbidden
.note = sequences of two or more # are reserved for future use since Rust 2024
.suggestion_whitespace = consider inserting whitespace here
parse_reserved_string = invalid string literal
.note = unprefixed guarded string literals are reserved for future use since Rust 2024
.suggestion_whitespace = consider inserting whitespace here
parse_return_types_use_thin_arrow = return types are denoted using `->`
.suggestion = use `->` instead
parse_self_argument_pointer = cannot pass `self` by raw pointer
.label = cannot pass `self` by raw pointer
parse_self_param_not_first = unexpected `self` parameter in function
.label = must be the first parameter of an associated function
parse_shift_interpreted_as_generic =
`<<` is interpreted as a start of generic arguments for `{$type}`, not a shift
.label_args = interpreted as generic arguments
.label_comparison = not interpreted as shift
.suggestion = try shifting the cast value
parse_single_colon_import_path = expected `::`, found `:`
.suggestion = use double colon
.note = import paths are delimited using `::`
parse_static_with_generics = static items may not have generic parameters
parse_struct_literal_body_without_path =
struct literal body without path
.suggestion = you might have forgotten to add the struct literal inside the block
parse_struct_literal_body_without_path_late =
struct literal body without path
.label = struct name missing for struct literal
.suggestion = add the correct type
parse_struct_literal_not_allowed_here = struct literals are not allowed here
.suggestion = surround the struct literal with parentheses
parse_struct_literal_placeholder_path =
placeholder `_` is not allowed for the path in struct literals
.label = not allowed in struct literals
.suggestion = replace it with the correct type
parse_suffixed_literal_in_attribute = suffixed literals are not allowed in attributes
.help = instead of using a suffixed literal (`1u8`, `1.0f32`, etc.), use an unsuffixed version (`1`, `1.0`, etc.)
parse_sugg_add_let_for_stmt = you might have meant to introduce a new binding
parse_sugg_add_semi = add `;` here
parse_sugg_change_inner_attr_to_outer = to annotate the {$item}, change the attribute from inner to outer style
parse_sugg_change_this_to_semi = change this to `;`
parse_sugg_escape_identifier = escape `{$ident_name}` to use it as an identifier
parse_sugg_remove_comma = remove this comma
parse_sugg_remove_leading_vert_in_pattern = remove the `|`
parse_sugg_turbofish_syntax = use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments
parse_sugg_wrap_expression_in_parentheses = wrap the expression in parentheses
parse_sugg_wrap_macro_in_parentheses = use parentheses instead of braces for this macro
parse_sugg_wrap_pattern_in_parens = wrap the pattern in parentheses
parse_switch_mut_let_order =
switch the order of `mut` and `let`
parse_switch_ref_box_order = switch the order of `ref` and `box`
.suggestion = swap them
parse_ternary_operator = Rust has no ternary operator
parse_tilde_is_not_unary_operator = `~` cannot be used as a unary operator
.suggestion = use `!` to perform bitwise not
parse_too_many_hashes = too many `#` symbols: raw strings may be delimited by up to 255 `#` symbols, but found {$num}
parse_too_short_hex_escape = numeric character escape is too short
parse_trailing_vert_not_allowed = a trailing `{$token}` is not allowed in an or-pattern
parse_trait_alias_cannot_be_auto = trait aliases cannot be `auto`
parse_trait_alias_cannot_be_unsafe = trait aliases cannot be `unsafe`
parse_trait_impl_modifier_in_inherent_impl = inherent impls cannot be {$modifier_name}
.because = {$modifier_name} because of this
.type = inherent impl for this type
.note = only trait implementations may be annotated with `{$modifier}`
parse_transpose_dyn_or_impl = `for<...>` expected after `{$kw}`, not before
.suggestion = move `{$kw}` before the `for<...>`
parse_unclosed_unicode_escape = unterminated unicode escape
.label = missing a closing `{"}"}`
.terminate = terminate the unicode escape
parse_underscore_literal_suffix = underscore literal suffix is not allowed
parse_unexpected_const_in_generic_param = expected lifetime, type, or constant, found keyword `const`
.suggestion = the `const` keyword is only needed in the definition of the type
parse_unexpected_const_param_declaration = unexpected `const` parameter declaration
.label = expected a `const` expression, not a parameter declaration
.suggestion = `const` parameters must be declared for the `impl`
parse_unexpected_default_value_for_lifetime_in_generic_parameters = unexpected default lifetime parameter
.label = lifetime parameters cannot have default values
parse_unexpected_expr_in_pat =
expected {$is_bound ->
[true] a pattern range bound
*[false] a pattern
}, found an expression
.label = not a pattern
.note = arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch19-00-patterns.html>
parse_unexpected_expr_in_pat_const_sugg = consider extracting the expression into a `const`
parse_unexpected_expr_in_pat_create_guard_sugg = consider moving the expression to a match arm guard
parse_unexpected_expr_in_pat_update_guard_sugg = consider moving the expression to the match arm guard
parse_unexpected_if_with_if = unexpected `if` in the condition expression
.suggestion = remove the `if`
parse_unexpected_lifetime_in_pattern = unexpected lifetime `{$symbol}` in pattern
.suggestion = remove the lifetime
parse_unexpected_paren_in_range_pat = range pattern bounds cannot have parentheses
parse_unexpected_paren_in_range_pat_sugg = remove these parentheses
parse_unexpected_parentheses_in_for_head = unexpected parentheses surrounding `for` loop head
.suggestion = remove parentheses in `for` loop
parse_unexpected_parentheses_in_match_arm_pattern = unexpected parentheses surrounding `match` arm pattern
.suggestion = remove parentheses surrounding the pattern
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_token_after_dot = unexpected token: {$actual}
parse_unexpected_token_after_label = expected `while`, `for`, `loop` or `{"{"}` after a label
.suggestion_remove_label = consider removing the label
.suggestion_enclose_in_block = consider enclosing expression in a block
parse_unexpected_token_after_not = unexpected {$negated_desc} after identifier
parse_unexpected_token_after_not_bitwise = use `!` to perform bitwise not
parse_unexpected_token_after_not_default = use `!` to perform logical negation or bitwise not
parse_unexpected_token_after_not_logical = use `!` to perform logical negation
parse_unexpected_token_after_struct_name = expected `where`, `{"{"}`, `(`, or `;` after struct name
parse_unexpected_token_after_struct_name_found_doc_comment = expected `where`, `{"{"}`, `(`, or `;` after struct name, found doc comment `{$token}`
parse_unexpected_token_after_struct_name_found_keyword = expected `where`, `{"{"}`, `(`, or `;` after struct name, found keyword `{$token}`
# This one deliberately doesn't print a token.
parse_unexpected_token_after_struct_name_found_metavar = expected `where`, `{"{"}`, `(`, or `;` after struct name, found metavar
parse_unexpected_token_after_struct_name_found_other = expected `where`, `{"{"}`, `(`, or `;` after struct name, found `{$token}`
parse_unexpected_token_after_struct_name_found_reserved_identifier = expected `where`, `{"{"}`, `(`, or `;` after struct name, found reserved identifier `{$token}`
parse_unexpected_token_after_struct_name_found_reserved_keyword = expected `where`, `{"{"}`, `(`, or `;` after struct name, found reserved keyword `{$token}`
parse_unexpected_vert_vert_before_function_parameter = unexpected `||` before function parameter
.suggestion = remove the `||`
parse_unexpected_vert_vert_in_pattern = unexpected token `||` in pattern
.suggestion = use a single `|` to separate multiple alternative patterns
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_unknown_builtin_construct = unknown `builtin #` construct `{$name}`
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_cr = use `cr` for a raw C-string
.suggestion_str = if you meant to write a string literal, use double quotes
.suggestion_whitespace = consider inserting whitespace here
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
.help_invisible_char = invisible characters like '{$escaped}' are not usually visible in text editors
.note_repeats = character appears {$repeats ->
[one] once more
*[other] {$repeats} more times
}
parse_unmatched_angle = unmatched angle {$plural ->
[true] brackets
*[false] bracket
}
.suggestion = remove extra angle {$plural ->
[true] brackets
*[false] bracket
}
parse_unmatched_angle_brackets = {$num_extra_brackets ->
[one] unmatched angle bracket
*[other] unmatched angle brackets
}
.suggestion = {$num_extra_brackets ->
[one] remove extra angle bracket
*[other] remove extra angle brackets
}
parse_unskipped_whitespace = whitespace symbol '{$ch}' is not skipped
.label = {parse_unskipped_whitespace}
parse_use_empty_block_not_semi = expected { "`{}`" }, found `;`
.suggestion = try using { "`{}`" } instead
parse_use_eq_instead = unexpected `==`
.suggestion = try using `=` instead
parse_use_if_else = use an `if-else` expression instead
parse_use_let_not_auto = write `let` instead of `auto` to introduce a new variable
parse_use_let_not_var = write `let` instead of `var` to introduce a new variable
parse_varargs_without_pattern = missing pattern for `...` argument
.suggestion = name the argument, or use `_` to continue ignoring it
parse_visibility_not_followed_by_item = visibility `{$vis}` is not followed by an item
.label = the visibility
.help = you likely meant to define an item, e.g., `{$vis} fn foo() {"{}"}`
parse_where_clause_before_const_body = where clauses are not allowed before const item bodies
.label = unexpected where clause
.name_label = while parsing this const item
.body_label = the item body
.suggestion = move the body before the where clause
parse_where_clause_before_tuple_struct_body = where clauses are not allowed before tuple struct bodies
.label = unexpected where clause
.name_label = while parsing this tuple struct
.body_label = the struct body
.suggestion = move the body before the where clause
parse_where_generics = generic parameters on `where` clauses are reserved for future use
.label = currently unsupported
parse_zero_chars = empty character literal
.label = {parse_zero_chars}
+1357 -688
View File
@@ -9,17 +9,15 @@
use rustc_errors::codes::*;
use rustc_errors::{
Applicability, Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, IntoDiagArg,
Level, Subdiagnostic, SuggestionStyle,
Level, Subdiagnostic, SuggestionStyle, inline_fluent,
};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_session::errors::ExprParenthesesNeeded;
use rustc_span::edition::{Edition, LATEST_STABLE_EDITION};
use rustc_span::{Ident, Span, Symbol};
use crate::fluent_generated as fluent;
#[derive(Diagnostic)]
#[diag(parse_maybe_report_ambiguous_plus)]
#[diag("ambiguous `+` in a type")]
pub(crate) struct AmbiguousPlus {
#[primary_span]
pub span: Span,
@@ -28,7 +26,7 @@ pub(crate) struct AmbiguousPlus {
}
#[derive(Diagnostic)]
#[diag(parse_maybe_recover_from_bad_type_plus, code = E0178)]
#[diag("expected a path on the left-hand side of `+`", code = E0178)]
pub(crate) struct BadTypePlus {
#[primary_span]
pub span: Span,
@@ -37,7 +35,7 @@ pub(crate) struct BadTypePlus {
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(parse_add_paren, applicability = "machine-applicable")]
#[multipart_suggestion("try adding parentheses", applicability = "machine-applicable")]
pub(crate) struct AddParen {
#[suggestion_part(code = "(")]
pub lo: Span,
@@ -51,12 +49,12 @@ pub(crate) enum BadTypePlusSub {
#[subdiagnostic]
suggestion: AddParen,
},
#[label(parse_forgot_paren)]
#[label("perhaps you forgot parentheses?")]
ForgotParen {
#[primary_span]
span: Span,
},
#[label(parse_expect_path)]
#[label("expected a path")]
ExpectPath {
#[primary_span]
span: Span,
@@ -64,7 +62,7 @@ pub(crate) enum BadTypePlusSub {
}
#[derive(Diagnostic)]
#[diag(parse_maybe_recover_from_bad_qpath_stage_2)]
#[diag("missing angle brackets in associated item path")]
pub(crate) struct BadQPathStage2 {
#[primary_span]
pub span: Span,
@@ -73,21 +71,24 @@ pub(crate) struct BadQPathStage2 {
}
#[derive(Diagnostic)]
#[diag(parse_trait_impl_modifier_in_inherent_impl)]
#[note]
#[diag("inherent impls cannot be {$modifier_name}")]
#[note("only trait implementations may be annotated with `{$modifier}`")]
pub(crate) struct TraitImplModifierInInherentImpl {
#[primary_span]
pub span: Span,
pub modifier: &'static str,
pub modifier_name: &'static str,
#[label(parse_because)]
#[label("{$modifier_name} because of this")]
pub modifier_span: Span,
#[label(parse_type)]
#[label("inherent impl for this type")]
pub self_ty: Span,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(parse_suggestion, applicability = "machine-applicable")]
#[multipart_suggestion(
"types that don't start with an identifier need to be surrounded with angle brackets in qualified paths",
applicability = "machine-applicable"
)]
pub(crate) struct WrapType {
#[suggestion_part(code = "<")]
pub lo: Span,
@@ -96,22 +97,27 @@ pub(crate) struct WrapType {
}
#[derive(Diagnostic)]
#[diag(parse_incorrect_semicolon)]
#[diag("expected item, found `;`")]
pub(crate) struct IncorrectSemicolon<'a> {
#[primary_span]
#[suggestion(style = "verbose", code = "", applicability = "machine-applicable")]
#[suggestion(
"remove this semicolon",
style = "verbose",
code = "",
applicability = "machine-applicable"
)]
pub span: Span,
#[help]
#[help("{$name} declarations are not followed by a semicolon")]
pub show_help: bool,
pub name: &'a str,
}
#[derive(Diagnostic)]
#[diag(parse_incorrect_use_of_await)]
#[diag("incorrect use of `await`")]
pub(crate) struct IncorrectUseOfAwait {
#[primary_span]
#[suggestion(
parse_parentheses_suggestion,
"`await` is not a method call, remove the parentheses",
style = "verbose",
code = "",
applicability = "machine-applicable"
@@ -120,11 +126,11 @@ pub(crate) struct IncorrectUseOfAwait {
}
#[derive(Diagnostic)]
#[diag(parse_incorrect_use_of_use)]
#[diag("incorrect use of `use`")]
pub(crate) struct IncorrectUseOfUse {
#[primary_span]
#[suggestion(
parse_parentheses_suggestion,
"`use` is not a method call, try removing the parentheses",
style = "verbose",
code = "",
applicability = "machine-applicable"
@@ -133,10 +139,7 @@ pub(crate) struct IncorrectUseOfUse {
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(
parse_incorrect_use_of_await_postfix_suggestion,
applicability = "machine-applicable"
)]
#[multipart_suggestion("`await` is a postfix operation", applicability = "machine-applicable")]
pub(crate) struct AwaitSuggestion {
#[suggestion_part(code = "")]
pub removal: Span,
@@ -146,7 +149,7 @@ pub(crate) struct AwaitSuggestion {
}
#[derive(Diagnostic)]
#[diag(parse_incorrect_use_of_await)]
#[diag("incorrect use of `await`")]
pub(crate) struct IncorrectAwait {
#[primary_span]
pub span: Span,
@@ -155,16 +158,21 @@ pub(crate) struct IncorrectAwait {
}
#[derive(Diagnostic)]
#[diag(parse_in_in_typo)]
#[diag("expected iterable, found keyword `in`")]
pub(crate) struct InInTypo {
#[primary_span]
pub span: Span,
#[suggestion(code = "", style = "verbose", applicability = "machine-applicable")]
#[suggestion(
"remove the duplicated `in`",
code = "",
style = "verbose",
applicability = "machine-applicable"
)]
pub sugg_span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_invalid_variable_declaration)]
#[diag("invalid variable declaration")]
pub(crate) struct InvalidVariableDeclaration {
#[primary_span]
pub span: Span,
@@ -175,28 +183,28 @@ pub(crate) struct InvalidVariableDeclaration {
#[derive(Subdiagnostic)]
pub(crate) enum InvalidVariableDeclarationSub {
#[suggestion(
parse_switch_mut_let_order,
"switch the order of `mut` and `let`",
style = "verbose",
applicability = "maybe-incorrect",
code = "let mut"
)]
SwitchMutLetOrder(#[primary_span] Span),
#[suggestion(
parse_missing_let_before_mut,
"missing keyword",
applicability = "machine-applicable",
style = "verbose",
code = "let mut"
)]
MissingLet(#[primary_span] Span),
#[suggestion(
parse_use_let_not_auto,
"write `let` instead of `auto` to introduce a new variable",
style = "verbose",
applicability = "machine-applicable",
code = "let"
)]
UseLetNotAuto(#[primary_span] Span),
#[suggestion(
parse_use_let_not_var,
"write `let` instead of `var` to introduce a new variable",
style = "verbose",
applicability = "machine-applicable",
code = "let"
@@ -205,15 +213,20 @@ pub(crate) enum InvalidVariableDeclarationSub {
}
#[derive(Diagnostic)]
#[diag(parse_switch_ref_box_order)]
#[diag("switch the order of `ref` and `box`")]
pub(crate) struct SwitchRefBoxOrder {
#[primary_span]
#[suggestion(applicability = "machine-applicable", style = "verbose", code = "box ref")]
#[suggestion(
"swap them",
applicability = "machine-applicable",
style = "verbose",
code = "box ref"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_invalid_comparison_operator)]
#[diag("invalid comparison operator `{$invalid}`")]
pub(crate) struct InvalidComparisonOperator {
#[primary_span]
pub span: Span,
@@ -225,7 +238,7 @@ pub(crate) struct InvalidComparisonOperator {
#[derive(Subdiagnostic)]
pub(crate) enum InvalidComparisonOperatorSub {
#[suggestion(
parse_use_instead,
"`{$invalid}` is not a valid comparison operator, use `{$correct}`",
style = "verbose",
applicability = "machine-applicable",
code = "{correct}"
@@ -236,13 +249,13 @@ pub(crate) enum InvalidComparisonOperatorSub {
invalid: String,
correct: String,
},
#[label(parse_spaceship_operator_invalid)]
#[label("`<=>` is not a valid comparison operator, use `std::cmp::Ordering`")]
Spaceship(#[primary_span] Span),
}
#[derive(Diagnostic)]
#[diag(parse_invalid_logical_operator)]
#[note]
#[diag("`{$incorrect}` is not a logical operator")]
#[note("unlike in e.g., Python and PHP, `&&` and `||` are used for logical operators")]
pub(crate) struct InvalidLogicalOperator {
#[primary_span]
pub span: Span,
@@ -254,14 +267,14 @@ pub(crate) struct InvalidLogicalOperator {
#[derive(Subdiagnostic)]
pub(crate) enum InvalidLogicalOperatorSub {
#[suggestion(
parse_use_amp_amp_for_conjunction,
"use `&&` to perform logical conjunction",
style = "verbose",
applicability = "machine-applicable",
code = "&&"
)]
Conjunction(#[primary_span] Span),
#[suggestion(
parse_use_pipe_pipe_for_disjunction,
"use `||` to perform logical disjunction",
style = "verbose",
applicability = "machine-applicable",
code = "||"
@@ -270,15 +283,20 @@ pub(crate) enum InvalidLogicalOperatorSub {
}
#[derive(Diagnostic)]
#[diag(parse_tilde_is_not_unary_operator)]
#[diag("`~` cannot be used as a unary operator")]
pub(crate) struct TildeAsUnaryOperator(
#[primary_span]
#[suggestion(style = "verbose", applicability = "machine-applicable", code = "!")]
#[suggestion(
"use `!` to perform bitwise not",
style = "verbose",
applicability = "machine-applicable",
code = "!"
)]
pub Span,
);
#[derive(Diagnostic)]
#[diag(parse_unexpected_token_after_not)]
#[diag("unexpected {$negated_desc} after identifier")]
pub(crate) struct NotAsNegationOperator {
#[primary_span]
pub negated: Span,
@@ -290,7 +308,7 @@ pub(crate) struct NotAsNegationOperator {
#[derive(Subdiagnostic)]
pub(crate) enum NotAsNegationOperatorSub {
#[suggestion(
parse_unexpected_token_after_not_default,
"use `!` to perform logical negation or bitwise not",
style = "verbose",
applicability = "machine-applicable",
code = "!"
@@ -298,7 +316,7 @@ pub(crate) enum NotAsNegationOperatorSub {
SuggestNotDefault(#[primary_span] Span),
#[suggestion(
parse_unexpected_token_after_not_bitwise,
"use `!` to perform bitwise not",
style = "verbose",
applicability = "machine-applicable",
code = "!"
@@ -306,7 +324,7 @@ pub(crate) enum NotAsNegationOperatorSub {
SuggestNotBitwise(#[primary_span] Span),
#[suggestion(
parse_unexpected_token_after_not_logical,
"use `!` to perform logical negation",
style = "verbose",
applicability = "machine-applicable",
code = "!"
@@ -315,46 +333,59 @@ pub(crate) enum NotAsNegationOperatorSub {
}
#[derive(Diagnostic)]
#[diag(parse_malformed_loop_label)]
#[diag("malformed loop label")]
pub(crate) struct MalformedLoopLabel {
#[primary_span]
pub span: Span,
#[suggestion(applicability = "machine-applicable", code = "'", style = "verbose")]
#[suggestion(
"use the correct loop label format",
applicability = "machine-applicable",
code = "'",
style = "verbose"
)]
pub suggestion: Span,
}
#[derive(Diagnostic)]
#[diag(parse_lifetime_in_borrow_expression)]
#[diag("borrow expressions cannot be annotated with lifetimes")]
pub(crate) struct LifetimeInBorrowExpression {
#[primary_span]
pub span: Span,
#[suggestion(applicability = "machine-applicable", code = "", style = "verbose")]
#[label]
#[suggestion(
"remove the lifetime annotation",
applicability = "machine-applicable",
code = "",
style = "verbose"
)]
#[label("annotated with lifetime here")]
pub lifetime_span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_field_expression_with_generic)]
#[diag("field expressions cannot have generic arguments")]
pub(crate) struct FieldExpressionWithGeneric(#[primary_span] pub Span);
#[derive(Diagnostic)]
#[diag(parse_macro_invocation_with_qualified_path)]
#[diag("macros cannot use qualified paths")]
pub(crate) struct MacroInvocationWithQualifiedPath(#[primary_span] pub Span);
#[derive(Diagnostic)]
#[diag(parse_unexpected_token_after_label)]
#[diag("expected `while`, `for`, `loop` or `{\"{\"}` after a label")]
pub(crate) struct UnexpectedTokenAfterLabel {
#[primary_span]
#[label(parse_unexpected_token_after_label)]
#[label("expected `while`, `for`, `loop` or `{\"{\"}` after a label")]
pub span: Span,
#[suggestion(parse_suggestion_remove_label, style = "verbose", code = "")]
#[suggestion("consider removing the label", style = "verbose", code = "")]
pub remove_label: Option<Span>,
#[subdiagnostic]
pub enclose_in_block: Option<UnexpectedTokenAfterLabelSugg>,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(parse_suggestion_enclose_in_block, applicability = "machine-applicable")]
#[multipart_suggestion(
"consider enclosing expression in a block",
applicability = "machine-applicable"
)]
pub(crate) struct UnexpectedTokenAfterLabelSugg {
#[suggestion_part(code = "{{ ")]
pub left: Span,
@@ -363,66 +394,91 @@ pub(crate) struct UnexpectedTokenAfterLabelSugg {
}
#[derive(Diagnostic)]
#[diag(parse_require_colon_after_labeled_expression)]
#[note]
#[diag("labeled expression must be followed by `:`")]
#[note("labels are used before loops and blocks, allowing e.g., `break 'label` to them")]
pub(crate) struct RequireColonAfterLabeledExpression {
#[primary_span]
pub span: Span,
#[label]
#[label("the label")]
pub label: Span,
#[suggestion(style = "verbose", applicability = "machine-applicable", code = ": ")]
#[suggestion(
"add `:` after the label",
style = "verbose",
applicability = "machine-applicable",
code = ": "
)]
pub label_end: Span,
}
#[derive(Diagnostic)]
#[diag(parse_do_catch_syntax_removed)]
#[note]
#[diag("found removed `do catch` syntax")]
#[note("following RFC #2388, the new non-placeholder syntax is `try`")]
pub(crate) struct DoCatchSyntaxRemoved {
#[primary_span]
#[suggestion(applicability = "machine-applicable", code = "try", style = "verbose")]
#[suggestion(
"replace with the new syntax",
applicability = "machine-applicable",
code = "try",
style = "verbose"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_float_literal_requires_integer_part)]
#[diag("float literals must have an integer part")]
pub(crate) struct FloatLiteralRequiresIntegerPart {
#[primary_span]
pub span: Span,
#[suggestion(applicability = "machine-applicable", code = "0", style = "verbose")]
#[suggestion(
"must have an integer part",
applicability = "machine-applicable",
code = "0",
style = "verbose"
)]
pub suggestion: Span,
}
#[derive(Diagnostic)]
#[diag(parse_missing_semicolon_before_array)]
#[diag("expected `;`, found `[`")]
pub(crate) struct MissingSemicolonBeforeArray {
#[primary_span]
pub open_delim: Span,
#[suggestion(style = "verbose", applicability = "maybe-incorrect", code = ";")]
#[suggestion(
"consider adding `;` here",
style = "verbose",
applicability = "maybe-incorrect",
code = ";"
)]
pub semicolon: Span,
}
#[derive(Diagnostic)]
#[diag(parse_expect_dotdot_not_dotdotdot)]
#[diag("expected `..`, found `...`")]
pub(crate) struct MissingDotDot {
#[primary_span]
pub token_span: Span,
#[suggestion(applicability = "maybe-incorrect", code = "..", style = "verbose")]
#[suggestion(
"use `..` to fill in the rest of the fields",
applicability = "maybe-incorrect",
code = "..",
style = "verbose"
)]
pub sugg_span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_invalid_block_macro_segment)]
#[diag("cannot use a `block` macro fragment here")]
pub(crate) struct InvalidBlockMacroSegment {
#[primary_span]
pub span: Span,
#[label]
#[label("the `block` fragment is within this context")]
pub context: Span,
#[subdiagnostic]
pub wrap: WrapInExplicitBlock,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(parse_suggestion, applicability = "machine-applicable")]
#[multipart_suggestion("wrap this in another block", applicability = "machine-applicable")]
pub(crate) struct WrapInExplicitBlock {
#[suggestion_part(code = "{{ ")]
pub lo: Span,
@@ -431,7 +487,7 @@ pub(crate) struct WrapInExplicitBlock {
}
#[derive(Diagnostic)]
#[diag(parse_if_expression_missing_then_block)]
#[diag("this `if` expression is missing a block after the condition")]
pub(crate) struct IfExpressionMissingThenBlock {
#[primary_span]
pub if_span: Span,
@@ -443,14 +499,14 @@ pub(crate) struct IfExpressionMissingThenBlock {
#[derive(Subdiagnostic)]
pub(crate) enum IfExpressionMissingThenBlockSub {
#[help(parse_condition_possibly_unfinished)]
#[help("this binary operation is possibly unfinished")]
UnfinishedCondition(#[primary_span] Span),
#[help(parse_add_then_block)]
#[help("add a block here")]
AddThenBlock(#[primary_span] Span),
}
#[derive(Diagnostic)]
#[diag(parse_ternary_operator)]
#[diag("Rust has no ternary operator")]
pub(crate) struct TernaryOperator {
#[primary_span]
pub span: Span,
@@ -458,12 +514,16 @@ pub(crate) struct TernaryOperator {
#[subdiagnostic]
pub sugg: Option<TernaryOperatorSuggestion>,
/// Otherwise, just print the suggestion message
#[help(parse_use_if_else)]
#[help("use an `if-else` expression instead")]
pub no_sugg: bool,
}
#[derive(Subdiagnostic, Copy, Clone)]
#[multipart_suggestion(parse_use_if_else, applicability = "maybe-incorrect", style = "verbose")]
#[multipart_suggestion(
"use an `if-else` expression instead",
applicability = "maybe-incorrect",
style = "verbose"
)]
pub(crate) struct TernaryOperatorSuggestion {
#[suggestion_part(code = "if ")]
pub before_cond: Span,
@@ -477,7 +537,7 @@ pub(crate) struct TernaryOperatorSuggestion {
#[derive(Subdiagnostic)]
#[suggestion(
parse_extra_if_in_let_else,
"remove the `if` if you meant to write a `let...else` statement",
applicability = "maybe-incorrect",
code = "",
style = "verbose"
@@ -488,18 +548,20 @@ pub(crate) struct IfExpressionLetSomeSub {
}
#[derive(Diagnostic)]
#[diag(parse_if_expression_missing_condition)]
#[diag("missing condition for `if` expression")]
pub(crate) struct IfExpressionMissingCondition {
#[primary_span]
#[label(parse_condition_label)]
#[label("expected condition here")]
pub if_span: Span,
#[label(parse_block_label)]
#[label(
"if this block is the condition of the `if` expression, then it must be followed by another block"
)]
pub block_span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_expected_expression_found_let)]
#[note]
#[diag("expected expression, found `let` statement")]
#[note("only supported directly in conditions of `if` and `while` expressions")]
pub(crate) struct ExpectedExpressionFoundLet {
#[primary_span]
pub span: Span,
@@ -512,7 +574,7 @@ pub(crate) struct ExpectedExpressionFoundLet {
}
#[derive(Diagnostic)]
#[diag(parse_or_in_let_chain)]
#[diag("`||` operators are not supported in let chain conditions")]
pub(crate) struct OrInLetChain {
#[primary_span]
pub span: Span,
@@ -520,7 +582,7 @@ pub(crate) struct OrInLetChain {
#[derive(Subdiagnostic, Clone, Copy)]
#[multipart_suggestion(
parse_maybe_missing_let,
"you might have meant to continue the let-chain",
applicability = "maybe-incorrect",
style = "verbose"
)]
@@ -531,7 +593,7 @@ pub(crate) struct MaybeMissingLet {
#[derive(Subdiagnostic, Clone, Copy)]
#[multipart_suggestion(
parse_maybe_comparison,
"you might have meant to compare for equality",
applicability = "maybe-incorrect",
style = "verbose"
)]
@@ -541,56 +603,71 @@ pub(crate) struct MaybeComparison {
}
#[derive(Diagnostic)]
#[diag(parse_expect_eq_instead_of_eqeq)]
#[diag("expected `=`, found `==`")]
pub(crate) struct ExpectedEqForLetExpr {
#[primary_span]
pub span: Span,
#[suggestion(applicability = "maybe-incorrect", code = "=", style = "verbose")]
#[suggestion(
"consider using `=` here",
applicability = "maybe-incorrect",
code = "=",
style = "verbose"
)]
pub sugg_span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_expected_else_block)]
#[diag("expected `{\"{\"}`, found {$first_tok}")]
pub(crate) struct ExpectedElseBlock {
#[primary_span]
pub first_tok_span: Span,
pub first_tok: String,
#[label]
#[label("expected an `if` or a block after this `else`")]
pub else_span: Span,
#[suggestion(applicability = "maybe-incorrect", code = "if ", style = "verbose")]
#[suggestion(
"add an `if` if this is the condition of a chained `else if` statement",
applicability = "maybe-incorrect",
code = "if ",
style = "verbose"
)]
pub condition_start: Span,
}
#[derive(Diagnostic)]
#[diag(parse_expected_struct_field)]
#[diag("expected one of `,`, `:`, or `{\"}\"}`, found `{$token}`")]
pub(crate) struct ExpectedStructField {
#[primary_span]
#[label]
#[label("expected one of `,`, `:`, or `{\"}\"}`")]
pub span: Span,
pub token: Token,
#[label(parse_ident_label)]
#[label("while parsing this struct field")]
pub ident_span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_outer_attribute_not_allowed_on_if_else)]
#[diag("outer attributes are not allowed on `if` and `else` branches")]
pub(crate) struct OuterAttributeNotAllowedOnIfElse {
#[primary_span]
pub last: Span,
#[label(parse_branch_label)]
#[label("the attributes are attached to this branch")]
pub branch_span: Span,
#[label(parse_ctx_label)]
#[label("the branch belongs to this `{$ctx}`")]
pub ctx_span: Span,
pub ctx: String,
#[suggestion(applicability = "machine-applicable", code = "", style = "verbose")]
#[suggestion(
"remove the attributes",
applicability = "machine-applicable",
code = "",
style = "verbose"
)]
pub attributes: Span,
}
#[derive(Diagnostic)]
#[diag(parse_missing_in_in_for_loop)]
#[diag("missing `in` in `for` loop")]
pub(crate) struct MissingInInForLoop {
#[primary_span]
pub span: Span,
@@ -602,20 +679,36 @@ pub(crate) struct MissingInInForLoop {
pub(crate) enum MissingInInForLoopSub {
// User wrote `for pat of expr {}`
// Has been misleading, at least in the past (closed Issue #48492), thus maybe-incorrect
#[suggestion(parse_use_in, style = "verbose", applicability = "maybe-incorrect", code = "in")]
#[suggestion(
"try using `in` here instead",
style = "verbose",
applicability = "maybe-incorrect",
code = "in"
)]
InNotOf(#[primary_span] Span),
// User wrote `for pat = expr {}`
#[suggestion(parse_use_in, style = "verbose", applicability = "maybe-incorrect", code = "in")]
#[suggestion(
"try using `in` here instead",
style = "verbose",
applicability = "maybe-incorrect",
code = "in"
)]
InNotEq(#[primary_span] Span),
#[suggestion(parse_add_in, style = "verbose", applicability = "maybe-incorrect", code = " in ")]
#[suggestion(
"try adding `in` here",
style = "verbose",
applicability = "maybe-incorrect",
code = " in "
)]
AddIn(#[primary_span] Span),
}
#[derive(Diagnostic)]
#[diag(parse_missing_expression_in_for_loop)]
#[diag("missing expression to iterate on in `for` loop")]
pub(crate) struct MissingExpressionInForLoop {
#[primary_span]
#[suggestion(
"try adding an expression to the `for` loop",
code = "/* expression */ ",
applicability = "has-placeholders",
style = "verbose"
@@ -624,63 +717,80 @@ pub(crate) struct MissingExpressionInForLoop {
}
#[derive(Diagnostic)]
#[diag(parse_loop_else)]
#[note]
#[diag("`{$loop_kind}...else` loops are not supported")]
#[note(
"consider moving this `else` clause to a separate `if` statement and use a `bool` variable to control if it should run"
)]
pub(crate) struct LoopElseNotSupported {
#[primary_span]
pub span: Span,
pub loop_kind: &'static str,
#[label(parse_loop_keyword)]
#[label("`else` is attached to this loop")]
pub loop_kw: Span,
}
#[derive(Diagnostic)]
#[diag(parse_missing_comma_after_match_arm)]
#[diag("expected `,` following `match` arm")]
pub(crate) struct MissingCommaAfterMatchArm {
#[primary_span]
#[suggestion(applicability = "machine-applicable", code = ",", style = "verbose")]
#[suggestion(
"missing a comma here to end this `match` arm",
applicability = "machine-applicable",
code = ",",
style = "verbose"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_catch_after_try)]
#[help]
#[diag("keyword `catch` cannot follow a `try` block")]
#[help("try using `match` on the result of the `try` block instead")]
pub(crate) struct CatchAfterTry {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_comma_after_base_struct)]
#[note]
#[diag("cannot use a comma after the base struct")]
#[note("the base struct must always be the last field")]
pub(crate) struct CommaAfterBaseStruct {
#[primary_span]
pub span: Span,
#[suggestion(style = "verbose", applicability = "machine-applicable", code = "")]
#[suggestion(
"remove this comma",
style = "verbose",
applicability = "machine-applicable",
code = ""
)]
pub comma: Span,
}
#[derive(Diagnostic)]
#[diag(parse_eq_field_init)]
#[diag("expected `:`, found `=`")]
pub(crate) struct EqFieldInit {
#[primary_span]
pub span: Span,
#[suggestion(applicability = "machine-applicable", code = ":", style = "verbose")]
#[suggestion(
"replace equals symbol with a colon",
applicability = "machine-applicable",
code = ":",
style = "verbose"
)]
pub eq: Span,
}
#[derive(Diagnostic)]
#[diag(parse_dotdotdot)]
#[diag("unexpected token: `...`")]
pub(crate) struct DotDotDot {
#[primary_span]
#[suggestion(
parse_suggest_exclusive_range,
"use `..` for an exclusive range",
applicability = "maybe-incorrect",
code = "..",
style = "verbose"
)]
#[suggestion(
parse_suggest_inclusive_range,
"or `..=` for an inclusive range",
applicability = "maybe-incorrect",
code = "..=",
style = "verbose"
@@ -689,67 +799,74 @@ pub(crate) struct DotDotDot {
}
#[derive(Diagnostic)]
#[diag(parse_left_arrow_operator)]
#[diag("unexpected token: `<-`")]
pub(crate) struct LeftArrowOperator {
#[primary_span]
#[suggestion(applicability = "maybe-incorrect", code = "< -", style = "verbose")]
#[suggestion(
"if you meant to write a comparison against a negative value, add a space in between `<` and `-`",
applicability = "maybe-incorrect",
code = "< -",
style = "verbose"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_remove_let)]
#[diag("expected pattern, found `let`")]
pub(crate) struct RemoveLet {
#[primary_span]
pub span: Span,
#[suggestion(applicability = "machine-applicable", code = "", style = "verbose")]
#[suggestion(
"remove the unnecessary `let` keyword",
applicability = "machine-applicable",
code = "",
style = "verbose"
)]
pub suggestion: Span,
}
#[derive(Diagnostic)]
#[diag(parse_use_eq_instead)]
#[diag("unexpected `==`")]
pub(crate) struct UseEqInstead {
#[primary_span]
#[suggestion(style = "verbose", applicability = "machine-applicable", code = "=")]
#[suggestion(
"try using `=` instead",
style = "verbose",
applicability = "machine-applicable",
code = "="
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_use_empty_block_not_semi)]
#[diag("expected { \"`{}`\" }, found `;`")]
pub(crate) struct UseEmptyBlockNotSemi {
#[primary_span]
#[suggestion(style = "hidden", applicability = "machine-applicable", code = "{{}}")]
#[suggestion(
r#"try using { "`{}`" } instead"#,
style = "hidden",
applicability = "machine-applicable",
code = "{{}}"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_comparison_interpreted_as_generic)]
#[diag("`<` is interpreted as a start of generic arguments for `{$type}`, not a comparison")]
pub(crate) struct ComparisonInterpretedAsGeneric {
#[primary_span]
#[label(parse_label_comparison)]
#[label("not interpreted as comparison")]
pub comparison: Span,
pub r#type: Path,
#[label(parse_label_args)]
#[label("interpreted as generic arguments")]
pub args: Span,
#[subdiagnostic]
pub suggestion: ComparisonOrShiftInterpretedAsGenericSugg,
}
#[derive(Diagnostic)]
#[diag(parse_shift_interpreted_as_generic)]
pub(crate) struct ShiftInterpretedAsGeneric {
#[primary_span]
#[label(parse_label_comparison)]
pub shift: Span,
pub r#type: Path,
#[label(parse_label_args)]
pub args: Span,
#[subdiagnostic]
pub suggestion: ComparisonOrShiftInterpretedAsGenericSugg,
pub suggestion: ComparisonInterpretedAsGenericSugg,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(parse_suggestion, applicability = "machine-applicable")]
pub(crate) struct ComparisonOrShiftInterpretedAsGenericSugg {
#[multipart_suggestion("try comparing the cast value", applicability = "machine-applicable")]
pub(crate) struct ComparisonInterpretedAsGenericSugg {
#[suggestion_part(code = "(")]
pub left: Span,
#[suggestion_part(code = ")")]
@@ -757,10 +874,32 @@ pub(crate) struct ComparisonOrShiftInterpretedAsGenericSugg {
}
#[derive(Diagnostic)]
#[diag(parse_found_expr_would_be_stmt)]
#[diag("`<<` is interpreted as a start of generic arguments for `{$type}`, not a shift")]
pub(crate) struct ShiftInterpretedAsGeneric {
#[primary_span]
#[label("not interpreted as shift")]
pub shift: Span,
pub r#type: Path,
#[label("interpreted as generic arguments")]
pub args: Span,
#[subdiagnostic]
pub suggestion: ShiftInterpretedAsGenericSugg,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion("try shifting the cast value", applicability = "machine-applicable")]
pub(crate) struct ShiftInterpretedAsGenericSugg {
#[suggestion_part(code = "(")]
pub left: Span,
#[suggestion_part(code = ")")]
pub right: Span,
}
#[derive(Diagnostic)]
#[diag("expected expression, found `{$token}`")]
pub(crate) struct FoundExprWouldBeStmt {
#[primary_span]
#[label]
#[label("expected expression")]
pub span: Span,
pub token: Token,
#[subdiagnostic]
@@ -768,81 +907,83 @@ pub(crate) struct FoundExprWouldBeStmt {
}
#[derive(Diagnostic)]
#[diag(parse_frontmatter_extra_characters_after_close)]
#[diag("extra characters after frontmatter close are not allowed")]
pub(crate) struct FrontmatterExtraCharactersAfterClose {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_frontmatter_invalid_infostring)]
#[note]
#[diag("invalid infostring for frontmatter")]
#[note("frontmatter infostrings must be a single identifier immediately following the opening")]
pub(crate) struct FrontmatterInvalidInfostring {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_frontmatter_invalid_opening_preceding_whitespace)]
#[diag("invalid preceding whitespace for frontmatter opening")]
pub(crate) struct FrontmatterInvalidOpeningPrecedingWhitespace {
#[primary_span]
pub span: Span,
#[note]
#[note("frontmatter opening should not be preceded by whitespace")]
pub note_span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_frontmatter_unclosed)]
#[diag("unclosed frontmatter")]
pub(crate) struct FrontmatterUnclosed {
#[primary_span]
pub span: Span,
#[note]
#[note("frontmatter opening here was not closed")]
pub note_span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_frontmatter_invalid_close_preceding_whitespace)]
#[diag("invalid preceding whitespace for frontmatter close")]
pub(crate) struct FrontmatterInvalidClosingPrecedingWhitespace {
#[primary_span]
pub span: Span,
#[note]
#[note("frontmatter close should not be preceded by whitespace")]
pub note_span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_frontmatter_length_mismatch)]
#[diag("frontmatter close does not match the opening")]
pub(crate) struct FrontmatterLengthMismatch {
#[primary_span]
pub span: Span,
#[label(parse_label_opening)]
#[label("the opening here has {$len_opening} dashes...")]
pub opening: Span,
#[label(parse_label_close)]
#[label("...while the close has {$len_close} dashes")]
pub close: Span,
pub len_opening: usize,
pub len_close: usize,
}
#[derive(Diagnostic)]
#[diag(parse_frontmatter_too_many_dashes)]
#[diag(
"too many `-` symbols: frontmatter openings may be delimited by up to 255 `-` symbols, but found {$len_opening}"
)]
pub(crate) struct FrontmatterTooManyDashes {
pub len_opening: usize,
}
#[derive(Diagnostic)]
#[diag(parse_bare_cr_in_frontmatter)]
#[diag("bare CR not allowed in frontmatter")]
pub(crate) struct BareCrFrontmatter {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_leading_plus_not_supported)]
#[diag("leading `+` is not supported")]
pub(crate) struct LeadingPlusNotSupported {
#[primary_span]
#[label]
#[label("unexpected `+`")]
pub span: Span,
#[suggestion(
parse_suggestion_remove_plus,
"try removing the `+`",
style = "verbose",
code = "",
applicability = "machine-applicable"
@@ -853,7 +994,7 @@ pub(crate) struct LeadingPlusNotSupported {
}
#[derive(Diagnostic)]
#[diag(parse_parentheses_with_struct_fields)]
#[diag("invalid `struct` delimiters or `fn` call arguments")]
pub(crate) struct ParenthesesWithStructFields {
#[primary_span]
pub span: Span,
@@ -865,7 +1006,10 @@ pub(crate) struct ParenthesesWithStructFields {
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(parse_suggestion_braces_for_struct, applicability = "maybe-incorrect")]
#[multipart_suggestion(
"if `{$type}` is a struct, use braces as delimiters",
applicability = "maybe-incorrect"
)]
pub(crate) struct BracesForStructLiteral {
#[suggestion_part(code = " {{ ")]
pub first: Span,
@@ -874,14 +1018,19 @@ pub(crate) struct BracesForStructLiteral {
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(parse_suggestion_no_fields_for_fn, applicability = "maybe-incorrect")]
#[multipart_suggestion(
"if `{$type}` is a function, use the arguments directly",
applicability = "maybe-incorrect"
)]
pub(crate) struct NoFieldsForFnCall {
#[suggestion_part(code = "")]
pub fields: Vec<Span>,
}
#[derive(Diagnostic)]
#[diag(parse_labeled_loop_in_break)]
#[diag(
"parentheses are required around this expression to avoid confusion with a labeled break expression"
)]
pub(crate) struct LabeledLoopInBreak {
#[primary_span]
pub span: Span,
@@ -892,7 +1041,7 @@ pub(crate) struct LabeledLoopInBreak {
#[derive(Subdiagnostic)]
pub(crate) enum WrapInParentheses {
#[multipart_suggestion(
parse_sugg_wrap_expression_in_parentheses,
"wrap the expression in parentheses",
applicability = "machine-applicable"
)]
Expression {
@@ -902,7 +1051,7 @@ pub(crate) enum WrapInParentheses {
right: Span,
},
#[multipart_suggestion(
parse_sugg_wrap_macro_in_parentheses,
"use parentheses instead of braces for this macro",
applicability = "machine-applicable"
)]
MacroArgs {
@@ -914,7 +1063,7 @@ pub(crate) enum WrapInParentheses {
}
#[derive(Diagnostic)]
#[diag(parse_array_brackets_instead_of_braces)]
#[diag("this is a block expression, not an array")]
pub(crate) struct ArrayBracketsInsteadOfBraces {
#[primary_span]
pub span: Span,
@@ -923,7 +1072,10 @@ pub(crate) struct ArrayBracketsInsteadOfBraces {
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(parse_suggestion, applicability = "maybe-incorrect")]
#[multipart_suggestion(
"to make an array, use square brackets instead of curly braces",
applicability = "maybe-incorrect"
)]
pub(crate) struct ArrayBracketsInsteadOfBracesSugg {
#[suggestion_part(code = "[")]
pub left: Span,
@@ -932,12 +1084,17 @@ pub(crate) struct ArrayBracketsInsteadOfBracesSugg {
}
#[derive(Diagnostic)]
#[diag(parse_match_arm_body_without_braces)]
#[diag("`match` arm body without braces")]
pub(crate) struct MatchArmBodyWithoutBraces {
#[primary_span]
#[label(parse_label_statements)]
#[label(
"{$num_statements ->
[one] this statement is not surrounded by a body
*[other] these statements are not surrounded by a body
}"
)]
pub statements: Span,
#[label(parse_label_arrow)]
#[label("while parsing the `match` arm starting here")]
pub arrow: Span,
pub num_statements: usize,
#[subdiagnostic]
@@ -945,12 +1102,12 @@ pub(crate) struct MatchArmBodyWithoutBraces {
}
#[derive(Diagnostic)]
#[diag(parse_inclusive_range_extra_equals)]
#[note]
#[diag("unexpected `=` after inclusive range")]
#[note("inclusive ranges end with a single equals sign (`..=`)")]
pub(crate) struct InclusiveRangeExtraEquals {
#[primary_span]
#[suggestion(
parse_suggestion_remove_eq,
"use `..=` instead",
style = "verbose",
code = "..=",
applicability = "maybe-incorrect"
@@ -959,24 +1116,29 @@ pub(crate) struct InclusiveRangeExtraEquals {
}
#[derive(Diagnostic)]
#[diag(parse_inclusive_range_match_arrow)]
#[diag("unexpected `>` after inclusive range")]
pub(crate) struct InclusiveRangeMatchArrow {
#[primary_span]
pub arrow: Span,
#[label]
#[label("this is parsed as an inclusive range `..=`")]
pub span: Span,
#[suggestion(style = "verbose", code = " ", applicability = "machine-applicable")]
#[suggestion(
"add a space between the pattern and `=>`",
style = "verbose",
code = " ",
applicability = "machine-applicable"
)]
pub after_pat: Span,
}
#[derive(Diagnostic)]
#[diag(parse_inclusive_range_no_end, code = E0586)]
#[note]
#[diag("inclusive range with no end", code = E0586)]
#[note("inclusive ranges must be bounded at the end (`..=b` or `a..=b`)")]
pub(crate) struct InclusiveRangeNoEnd {
#[primary_span]
pub span: Span,
#[suggestion(
parse_suggestion_open_range,
"use `..` instead",
code = "",
applicability = "machine-applicable",
style = "verbose"
@@ -986,7 +1148,13 @@ pub(crate) struct InclusiveRangeNoEnd {
#[derive(Subdiagnostic)]
pub(crate) enum MatchArmBodyWithoutBracesSugg {
#[multipart_suggestion(parse_suggestion_add_braces, applicability = "machine-applicable")]
#[multipart_suggestion(
"surround the {$num_statements ->
[one] statement
*[other] statements
} with a body",
applicability = "machine-applicable"
)]
AddBraces {
#[suggestion_part(code = "{{ ")]
left: Span,
@@ -994,7 +1162,7 @@ pub(crate) enum MatchArmBodyWithoutBracesSugg {
right: Span,
},
#[suggestion(
parse_suggestion_use_comma_not_semicolon,
"replace `;` with `,` to end a `match` arm expression",
code = ",",
applicability = "machine-applicable",
style = "verbose"
@@ -1006,7 +1174,7 @@ pub(crate) enum MatchArmBodyWithoutBracesSugg {
}
#[derive(Diagnostic)]
#[diag(parse_struct_literal_not_allowed_here)]
#[diag("struct literals are not allowed here")]
pub(crate) struct StructLiteralNotAllowedHere {
#[primary_span]
pub span: Span,
@@ -1015,7 +1183,10 @@ pub(crate) struct StructLiteralNotAllowedHere {
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(parse_suggestion, applicability = "machine-applicable")]
#[multipart_suggestion(
"surround the struct literal with parentheses",
applicability = "machine-applicable"
)]
pub(crate) struct StructLiteralNotAllowedHereSugg {
#[suggestion_part(code = "(")]
pub left: Span,
@@ -1024,80 +1195,105 @@ pub(crate) struct StructLiteralNotAllowedHereSugg {
}
#[derive(Diagnostic)]
#[diag(parse_invalid_literal_suffix_on_tuple_index)]
#[diag("suffixes on a tuple index are invalid")]
pub(crate) struct InvalidLiteralSuffixOnTupleIndex {
#[primary_span]
#[label]
#[label("invalid suffix `{$suffix}`")]
pub span: Span,
pub suffix: Symbol,
}
#[derive(Diagnostic)]
#[diag(parse_non_string_abi_literal)]
#[diag("non-string ABI literal")]
pub(crate) struct NonStringAbiLiteral {
#[primary_span]
#[suggestion(code = "\"C\"", applicability = "maybe-incorrect", style = "verbose")]
#[suggestion(
"specify the ABI with a string literal",
code = "\"C\"",
applicability = "maybe-incorrect",
style = "verbose"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_mismatched_closing_delimiter)]
#[diag("mismatched closing delimiter: `{$delimiter}`")]
pub(crate) struct MismatchedClosingDelimiter {
#[primary_span]
pub spans: Vec<Span>,
pub delimiter: String,
#[label(parse_label_unmatched)]
#[label("mismatched closing delimiter")]
pub unmatched: Span,
#[label(parse_label_opening_candidate)]
#[label("closing delimiter possibly meant for this")]
pub opening_candidate: Option<Span>,
#[label(parse_label_unclosed)]
#[label("unclosed delimiter")]
pub unclosed: Option<Span>,
}
#[derive(Diagnostic)]
#[diag(parse_incorrect_visibility_restriction, code = E0704)]
#[help]
#[diag("incorrect visibility restriction", code = E0704)]
#[help(
"some possible visibility restrictions are:
`pub(crate)`: visible only on the current crate
`pub(super)`: visible only in the current module's parent
`pub(in path::to::module)`: visible only on the specified path"
)]
pub(crate) struct IncorrectVisibilityRestriction {
#[primary_span]
#[suggestion(code = "in {inner_str}", applicability = "machine-applicable", style = "verbose")]
#[suggestion(
"make this visible only to module `{$inner_str}` with `in`",
code = "in {inner_str}",
applicability = "machine-applicable",
style = "verbose"
)]
pub span: Span,
pub inner_str: String,
}
#[derive(Diagnostic)]
#[diag(parse_assignment_else_not_allowed)]
#[diag("<assignment> ... else {\"{\"} ... {\"}\"} is not allowed")]
pub(crate) struct AssignmentElseNotAllowed {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_expected_statement_after_outer_attr)]
#[diag("expected statement after outer attribute")]
pub(crate) struct ExpectedStatementAfterOuterAttr {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_doc_comment_does_not_document_anything, code = E0585)]
#[help]
#[diag("found a documentation comment that doesn't document anything", code = E0585)]
#[help("doc comments must come before what they document, if a comment was intended use `//`")]
pub(crate) struct DocCommentDoesNotDocumentAnything {
#[primary_span]
pub span: Span,
#[suggestion(code = ",", applicability = "machine-applicable", style = "verbose")]
#[suggestion(
"missing comma here",
code = ",",
applicability = "machine-applicable",
style = "verbose"
)]
pub missing_comma: Option<Span>,
}
#[derive(Diagnostic)]
#[diag(parse_const_let_mutually_exclusive)]
#[diag("`const` and `let` are mutually exclusive")]
pub(crate) struct ConstLetMutuallyExclusive {
#[primary_span]
#[suggestion(code = "const", applicability = "maybe-incorrect", style = "verbose")]
#[suggestion(
"remove `let`",
code = "const",
applicability = "maybe-incorrect",
style = "verbose"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_invalid_expression_in_let_else)]
#[diag("a `{$operator}` expression cannot be directly assigned in `let...else`")]
pub(crate) struct InvalidExpressionInLetElse {
#[primary_span]
pub span: Span,
@@ -1107,7 +1303,7 @@ pub(crate) struct InvalidExpressionInLetElse {
}
#[derive(Diagnostic)]
#[diag(parse_invalid_curly_in_let_else)]
#[diag("right curly brace `{\"}\"}` before `else` in a `let...else` statement not allowed")]
pub(crate) struct InvalidCurlyInLetElse {
#[primary_span]
pub span: Span,
@@ -1116,25 +1312,32 @@ pub(crate) struct InvalidCurlyInLetElse {
}
#[derive(Diagnostic)]
#[diag(parse_compound_assignment_expression_in_let)]
#[help]
#[diag("can't reassign to an uninitialized variable")]
#[help("if you meant to overwrite, remove the `let` binding")]
pub(crate) struct CompoundAssignmentExpressionInLet {
#[primary_span]
pub span: Span,
#[suggestion(style = "verbose", code = "", applicability = "maybe-incorrect")]
#[suggestion(
"initialize the variable",
style = "verbose",
code = "",
applicability = "maybe-incorrect"
)]
pub suggestion: Span,
}
#[derive(Diagnostic)]
#[diag(parse_suffixed_literal_in_attribute)]
#[help]
#[diag("suffixed literals are not allowed in attributes")]
#[help(
"instead of using a suffixed literal (`1u8`, `1.0f32`, etc.), use an unsuffixed version (`1`, `1.0`, etc.)"
)]
pub(crate) struct SuffixedLiteralInAttribute {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_invalid_meta_item)]
#[diag("expected unsuffixed literal, found {$descr}")]
pub(crate) struct InvalidMetaItem {
#[primary_span]
pub span: Span,
@@ -1144,7 +1347,10 @@ pub(crate) struct InvalidMetaItem {
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(parse_quote_ident_sugg, applicability = "machine-applicable")]
#[multipart_suggestion(
"surround the identifier with quotation marks to make it into a string literal",
applicability = "machine-applicable"
)]
pub(crate) struct InvalidMetaItemQuoteIdentSugg {
#[suggestion_part(code = "\"")]
pub before: Span,
@@ -1154,7 +1360,7 @@ pub(crate) struct InvalidMetaItemQuoteIdentSugg {
#[derive(Subdiagnostic)]
#[suggestion(
parse_sugg_escape_identifier,
"escape `{$ident_name}` to use it as an identifier",
style = "verbose",
applicability = "maybe-incorrect",
code = "r#"
@@ -1167,7 +1373,7 @@ pub(crate) struct SuggEscapeIdentifier {
#[derive(Subdiagnostic)]
#[suggestion(
parse_sugg_remove_comma,
"remove this comma",
applicability = "machine-applicable",
code = "",
style = "verbose"
@@ -1179,7 +1385,7 @@ pub(crate) struct SuggRemoveComma {
#[derive(Subdiagnostic)]
#[suggestion(
parse_sugg_add_let_for_stmt,
"you might have meant to introduce a new binding",
style = "verbose",
applicability = "maybe-incorrect",
code = "let "
@@ -1191,17 +1397,17 @@ pub(crate) struct SuggAddMissingLetStmt {
#[derive(Subdiagnostic)]
pub(crate) enum ExpectedIdentifierFound {
#[label(parse_expected_identifier_found_reserved_identifier)]
#[label("expected identifier, found reserved identifier")]
ReservedIdentifier(#[primary_span] Span),
#[label(parse_expected_identifier_found_keyword)]
#[label("expected identifier, found keyword")]
Keyword(#[primary_span] Span),
#[label(parse_expected_identifier_found_reserved_keyword)]
#[label("expected identifier, found reserved keyword")]
ReservedKeyword(#[primary_span] Span),
#[label(parse_expected_identifier_found_doc_comment)]
#[label("expected identifier, found doc comment")]
DocComment(#[primary_span] Span),
#[label(parse_expected_identifier_found_metavar)]
#[label("expected identifier, found metavariable")]
MetaVar(#[primary_span] Span),
#[label(parse_expected_identifier)]
#[label("expected identifier")]
Other(#[primary_span] Span),
}
@@ -1239,22 +1445,22 @@ fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
level,
match token_descr {
Some(TokenDescription::ReservedIdentifier) => {
fluent::parse_expected_identifier_found_reserved_identifier_str
inline_fluent!("expected identifier, found reserved identifier `{$token}`")
}
Some(TokenDescription::Keyword) => {
fluent::parse_expected_identifier_found_keyword_str
inline_fluent!("expected identifier, found keyword `{$token}`")
}
Some(TokenDescription::ReservedKeyword) => {
fluent::parse_expected_identifier_found_reserved_keyword_str
inline_fluent!("expected identifier, found reserved keyword `{$token}`")
}
Some(TokenDescription::DocComment) => {
fluent::parse_expected_identifier_found_doc_comment_str
inline_fluent!("expected identifier, found doc comment `{$token}`")
}
Some(TokenDescription::MetaVar(_)) => {
add_token = false;
fluent::parse_expected_identifier_found_metavar_str
inline_fluent!("expected identifier, found metavariable")
}
None => fluent::parse_expected_identifier_found_str,
None => inline_fluent!("expected identifier, found `{$token}`"),
},
);
diag.span(self.span);
@@ -1281,7 +1487,7 @@ fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
}
#[derive(Subdiagnostic)]
#[help(parse_invalid_identifier_with_leading_number)]
#[help("identifiers cannot start with a number")]
pub(crate) struct HelpIdentifierStartsWithNumber {
#[primary_span]
pub num_span: Span,
@@ -1306,20 +1512,22 @@ fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
level,
match token_descr {
Some(TokenDescription::ReservedIdentifier) => {
fluent::parse_expected_semi_found_reserved_identifier_str
inline_fluent!("expected `;`, found reserved identifier `{$token}`")
}
Some(TokenDescription::Keyword) => {
inline_fluent!("expected `;`, found keyword `{$token}`")
}
Some(TokenDescription::Keyword) => fluent::parse_expected_semi_found_keyword_str,
Some(TokenDescription::ReservedKeyword) => {
fluent::parse_expected_semi_found_reserved_keyword_str
inline_fluent!("expected `;`, found reserved keyword `{$token}`")
}
Some(TokenDescription::DocComment) => {
fluent::parse_expected_semi_found_doc_comment_str
inline_fluent!("expected `;`, found doc comment `{$token}`")
}
Some(TokenDescription::MetaVar(_)) => {
add_token = false;
fluent::parse_expected_semi_found_metavar_str
inline_fluent!("expected `;`, found metavariable")
}
None => fluent::parse_expected_semi_found_str,
None => inline_fluent!("expected `;`, found `{$token}`"),
},
);
diag.span(self.span);
@@ -1328,7 +1536,7 @@ fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
}
if let Some(unexpected_token_label) = self.unexpected_token_label {
diag.span_label(unexpected_token_label, fluent::parse_label_unexpected_token);
diag.span_label(unexpected_token_label, inline_fluent!("unexpected token"));
}
self.sugg.add_to_diag(&mut diag);
@@ -1340,23 +1548,18 @@ fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
#[derive(Subdiagnostic)]
pub(crate) enum ExpectedSemiSugg {
#[suggestion(
parse_sugg_change_this_to_semi,
"change this to `;`",
code = ";",
applicability = "machine-applicable",
style = "short"
)]
ChangeToSemi(#[primary_span] Span),
#[suggestion(
parse_sugg_add_semi,
code = ";",
applicability = "machine-applicable",
style = "short"
)]
#[suggestion("add `;` here", code = ";", applicability = "machine-applicable", style = "short")]
AddSemi(#[primary_span] Span),
}
#[derive(Diagnostic)]
#[diag(parse_struct_literal_body_without_path)]
#[diag("struct literal body without path")]
pub(crate) struct StructLiteralBodyWithoutPath {
#[primary_span]
pub span: Span,
@@ -1365,7 +1568,10 @@ pub(crate) struct StructLiteralBodyWithoutPath {
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(parse_suggestion, applicability = "has-placeholders")]
#[multipart_suggestion(
"you might have forgotten to add the struct literal inside the block",
applicability = "has-placeholders"
)]
pub(crate) struct StructLiteralBodyWithoutPathSugg {
#[suggestion_part(code = "{{ SomeStruct ")]
pub before: Span,
@@ -1374,16 +1580,29 @@ pub(crate) struct StructLiteralBodyWithoutPathSugg {
}
#[derive(Diagnostic)]
#[diag(parse_unmatched_angle_brackets)]
#[diag(
"{$num_extra_brackets ->
[one] unmatched angle bracket
*[other] unmatched angle brackets
}"
)]
pub(crate) struct UnmatchedAngleBrackets {
#[primary_span]
#[suggestion(code = "", applicability = "machine-applicable", style = "verbose")]
#[suggestion(
"{$num_extra_brackets ->
[one] remove extra angle bracket
*[other] remove extra angle brackets
}",
code = "",
applicability = "machine-applicable",
style = "verbose"
)]
pub span: Span,
pub num_extra_brackets: usize,
}
#[derive(Diagnostic)]
#[diag(parse_generic_parameters_without_angle_brackets)]
#[diag("generic parameters without surrounding angle brackets")]
pub(crate) struct GenericParamsWithoutAngleBrackets {
#[primary_span]
pub span: Span,
@@ -1392,7 +1611,10 @@ pub(crate) struct GenericParamsWithoutAngleBrackets {
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(parse_suggestion, applicability = "machine-applicable")]
#[multipart_suggestion(
"surround the type parameters with angle brackets",
applicability = "machine-applicable"
)]
pub(crate) struct GenericParamsWithoutAngleBracketsSugg {
#[suggestion_part(code = "<")]
pub left: Span,
@@ -1401,19 +1623,19 @@ pub(crate) struct GenericParamsWithoutAngleBracketsSugg {
}
#[derive(Diagnostic)]
#[diag(parse_comparison_operators_cannot_be_chained)]
#[diag("comparison operators cannot be chained")]
pub(crate) struct ComparisonOperatorsCannotBeChained {
#[primary_span]
pub span: Vec<Span>,
#[suggestion(
parse_sugg_turbofish_syntax,
"use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments",
style = "verbose",
code = "::",
applicability = "maybe-incorrect"
)]
pub suggest_turbofish: Option<Span>,
#[help(parse_sugg_turbofish_syntax)]
#[help(parse_sugg_parentheses_for_function_args)]
#[help("use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments")]
#[help("or use `(...)` if you meant to specify fn arguments")]
pub help_turbofish: bool,
#[subdiagnostic]
pub chaining_sugg: Option<ComparisonOperatorsCannotBeChainedSugg>,
@@ -1422,7 +1644,7 @@ pub(crate) struct ComparisonOperatorsCannotBeChained {
#[derive(Subdiagnostic)]
pub(crate) enum ComparisonOperatorsCannotBeChainedSugg {
#[suggestion(
parse_sugg_split_comparison,
"split the comparison into two",
style = "verbose",
code = " && {middle_term}",
applicability = "maybe-incorrect"
@@ -1432,7 +1654,7 @@ pub(crate) enum ComparisonOperatorsCannotBeChainedSugg {
span: Span,
middle_term: String,
},
#[multipart_suggestion(parse_sugg_parenthesize, applicability = "maybe-incorrect")]
#[multipart_suggestion("parenthesize the comparison", applicability = "maybe-incorrect")]
Parenthesize {
#[suggestion_part(code = "(")]
left: Span,
@@ -1442,17 +1664,20 @@ pub(crate) enum ComparisonOperatorsCannotBeChainedSugg {
}
#[derive(Diagnostic)]
#[diag(parse_question_mark_in_type)]
#[diag("invalid `?` in type")]
pub(crate) struct QuestionMarkInType {
#[primary_span]
#[label]
#[label("`?` is only allowed on expressions, not types")]
pub span: Span,
#[subdiagnostic]
pub sugg: QuestionMarkInTypeSugg,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(parse_suggestion, applicability = "machine-applicable")]
#[multipart_suggestion(
"if you meant to express that the type might not contain a value, use the `Option` wrapper type",
applicability = "machine-applicable"
)]
pub(crate) struct QuestionMarkInTypeSugg {
#[suggestion_part(code = "Option<")]
pub left: Span,
@@ -1461,7 +1686,7 @@ pub(crate) struct QuestionMarkInTypeSugg {
}
#[derive(Diagnostic)]
#[diag(parse_unexpected_parentheses_in_for_head)]
#[diag("unexpected parentheses surrounding `for` loop head")]
pub(crate) struct ParenthesesInForHead {
#[primary_span]
pub span: Vec<Span>,
@@ -1470,7 +1695,7 @@ pub(crate) struct ParenthesesInForHead {
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(parse_suggestion, applicability = "machine-applicable")]
#[multipart_suggestion("remove parentheses in `for` loop", applicability = "machine-applicable")]
pub(crate) struct ParenthesesInForHeadSugg {
#[suggestion_part(code = " ")]
pub left: Span,
@@ -1479,7 +1704,7 @@ pub(crate) struct ParenthesesInForHeadSugg {
}
#[derive(Diagnostic)]
#[diag(parse_unexpected_parentheses_in_match_arm_pattern)]
#[diag("unexpected parentheses surrounding `match` arm pattern")]
pub(crate) struct ParenthesesInMatchPat {
#[primary_span]
pub span: Vec<Span>,
@@ -1488,7 +1713,10 @@ pub(crate) struct ParenthesesInMatchPat {
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(parse_suggestion, applicability = "machine-applicable")]
#[multipart_suggestion(
"remove parentheses surrounding the pattern",
applicability = "machine-applicable"
)]
pub(crate) struct ParenthesesInMatchPatSugg {
#[suggestion_part(code = "")]
pub left: Span,
@@ -1497,67 +1725,82 @@ pub(crate) struct ParenthesesInMatchPatSugg {
}
#[derive(Diagnostic)]
#[diag(parse_doc_comment_on_param_type)]
#[diag("documentation comments cannot be applied to a function parameter's type")]
pub(crate) struct DocCommentOnParamType {
#[primary_span]
#[label]
#[label("doc comments are not allowed here")]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_attribute_on_param_type)]
#[diag("attributes cannot be applied to a function parameter's type")]
pub(crate) struct AttributeOnParamType {
#[primary_span]
#[label]
#[label("attributes are not allowed here")]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_attribute_on_type)]
#[diag("attributes cannot be applied to types")]
pub(crate) struct AttributeOnType {
#[primary_span]
#[label]
#[label("attributes are not allowed here")]
pub span: Span,
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
#[suggestion(
"remove attribute from here",
code = "",
applicability = "machine-applicable",
style = "tool-only"
)]
pub fix_span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_attribute_on_generic_arg)]
#[diag("attributes cannot be applied to generic arguments")]
pub(crate) struct AttributeOnGenericArg {
#[primary_span]
#[label]
#[label("attributes are not allowed here")]
pub span: Span,
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
#[suggestion(
"remove attribute from here",
code = "",
applicability = "machine-applicable",
style = "tool-only"
)]
pub fix_span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_attribute_on_empty_type)]
#[diag("attributes cannot be applied here")]
pub(crate) struct AttributeOnEmptyType {
#[primary_span]
#[label]
#[label("attributes are not allowed here")]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_pattern_method_param_without_body, code = E0642)]
#[diag("patterns aren't allowed in methods without bodies", code = E0642)]
pub(crate) struct PatternMethodParamWithoutBody {
#[primary_span]
#[suggestion(code = "_", applicability = "machine-applicable", style = "verbose")]
#[suggestion(
"give this argument a name or use an underscore to ignore it",
code = "_",
applicability = "machine-applicable",
style = "verbose"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_self_param_not_first)]
#[diag("unexpected `self` parameter in function")]
pub(crate) struct SelfParamNotFirst {
#[primary_span]
#[label]
#[label("must be the first parameter of an associated function")]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_const_generic_without_braces)]
#[diag("expressions must be enclosed in braces to be used as const generic arguments")]
pub(crate) struct ConstGenericWithoutBraces {
#[primary_span]
pub span: Span,
@@ -1566,7 +1809,10 @@ pub(crate) struct ConstGenericWithoutBraces {
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(parse_suggestion, applicability = "machine-applicable")]
#[multipart_suggestion(
"enclose the `const` expression in braces",
applicability = "machine-applicable"
)]
pub(crate) struct ConstGenericWithoutBracesSugg {
#[suggestion_part(code = "{{ ")]
pub left: Span,
@@ -1575,10 +1821,10 @@ pub(crate) struct ConstGenericWithoutBracesSugg {
}
#[derive(Diagnostic)]
#[diag(parse_unexpected_const_param_declaration)]
#[diag("unexpected `const` parameter declaration")]
pub(crate) struct UnexpectedConstParamDeclaration {
#[primary_span]
#[label]
#[label("expected a `const` expression, not a parameter declaration")]
pub span: Span,
#[subdiagnostic]
pub sugg: Option<UnexpectedConstParamDeclarationSugg>,
@@ -1586,7 +1832,10 @@ pub(crate) struct UnexpectedConstParamDeclaration {
#[derive(Subdiagnostic)]
pub(crate) enum UnexpectedConstParamDeclarationSugg {
#[multipart_suggestion(parse_suggestion, applicability = "machine-applicable")]
#[multipart_suggestion(
"`const` parameters must be declared for the `impl`",
applicability = "machine-applicable"
)]
AddParam {
#[suggestion_part(code = "<{snippet}>")]
impl_generics: Span,
@@ -1595,7 +1844,10 @@ pub(crate) enum UnexpectedConstParamDeclarationSugg {
snippet: String,
ident: String,
},
#[multipart_suggestion(parse_suggestion, applicability = "machine-applicable")]
#[multipart_suggestion(
"`const` parameters must be declared for the `impl`",
applicability = "machine-applicable"
)]
AppendParam {
#[suggestion_part(code = ", {snippet}")]
impl_generics_end: Span,
@@ -1607,41 +1859,61 @@ pub(crate) enum UnexpectedConstParamDeclarationSugg {
}
#[derive(Diagnostic)]
#[diag(parse_unexpected_const_in_generic_param)]
#[diag("expected lifetime, type, or constant, found keyword `const`")]
pub(crate) struct UnexpectedConstInGenericParam {
#[primary_span]
pub span: Span,
#[suggestion(style = "verbose", code = "", applicability = "maybe-incorrect")]
#[suggestion(
"the `const` keyword is only needed in the definition of the type",
style = "verbose",
code = "",
applicability = "maybe-incorrect"
)]
pub to_remove: Option<Span>,
}
#[derive(Diagnostic)]
#[diag(parse_async_move_order_incorrect)]
#[diag("the order of `move` and `async` is incorrect")]
pub(crate) struct AsyncMoveOrderIncorrect {
#[primary_span]
#[suggestion(style = "verbose", code = "async move", applicability = "maybe-incorrect")]
#[suggestion(
"try switching the order",
style = "verbose",
code = "async move",
applicability = "maybe-incorrect"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_async_use_order_incorrect)]
#[diag("the order of `use` and `async` is incorrect")]
pub(crate) struct AsyncUseOrderIncorrect {
#[primary_span]
#[suggestion(style = "verbose", code = "async use", applicability = "maybe-incorrect")]
#[suggestion(
"try switching the order",
style = "verbose",
code = "async use",
applicability = "maybe-incorrect"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_double_colon_in_bound)]
#[diag("expected `:` followed by trait or lifetime")]
pub(crate) struct DoubleColonInBound {
#[primary_span]
pub span: Span,
#[suggestion(code = ": ", applicability = "machine-applicable", style = "verbose")]
#[suggestion(
"use single colon",
code = ": ",
applicability = "machine-applicable",
style = "verbose"
)]
pub between: Span,
}
#[derive(Diagnostic)]
#[diag(parse_fn_ptr_with_generics)]
#[diag("function pointer types may not have generic parameters")]
pub(crate) struct FnPtrWithGenerics {
#[primary_span]
pub span: Span,
@@ -1651,7 +1923,7 @@ pub(crate) struct FnPtrWithGenerics {
#[derive(Subdiagnostic)]
#[multipart_suggestion(
parse_misplaced_return_type,
"place the return type after the function parameters",
style = "verbose",
applicability = "maybe-incorrect"
)]
@@ -1664,7 +1936,16 @@ pub(crate) struct MisplacedReturnType {
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(parse_suggestion, applicability = "maybe-incorrect")]
#[multipart_suggestion(
"consider moving the lifetime {$arity ->
[one] parameter
*[other] parameters
} to {$for_param_list_exists ->
[true] the
*[false] a
} `for` parameter list",
applicability = "maybe-incorrect"
)]
pub(crate) struct FnPtrWithGenericsSugg {
#[suggestion_part(code = "{snippet}")]
pub left: Span,
@@ -1681,10 +1962,10 @@ pub(crate) struct FnTraitMissingParen {
impl Subdiagnostic for FnTraitMissingParen {
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
diag.span_label(self.span, crate::fluent_generated::parse_fn_trait_missing_paren);
diag.span_label(self.span, inline_fluent!("`Fn` bounds require arguments in parentheses"));
diag.span_suggestion_short(
self.span.shrink_to_hi(),
crate::fluent_generated::parse_add_paren,
inline_fluent!("try adding parentheses"),
"()",
Applicability::MachineApplicable,
);
@@ -1692,95 +1973,128 @@ fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
}
#[derive(Diagnostic)]
#[diag(parse_unexpected_if_with_if)]
#[diag("unexpected `if` in the condition expression")]
pub(crate) struct UnexpectedIfWithIf(
#[primary_span]
#[suggestion(applicability = "machine-applicable", code = " ", style = "verbose")]
#[suggestion(
"remove the `if`",
applicability = "machine-applicable",
code = " ",
style = "verbose"
)]
pub Span,
);
#[derive(Diagnostic)]
#[diag(parse_maybe_fn_typo_with_impl)]
#[diag("you might have meant to write `impl` instead of `fn`")]
pub(crate) struct FnTypoWithImpl {
#[primary_span]
#[suggestion(applicability = "maybe-incorrect", code = "impl", style = "verbose")]
#[suggestion(
"replace `fn` with `impl` here",
applicability = "maybe-incorrect",
code = "impl",
style = "verbose"
)]
pub fn_span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_expected_fn_path_found_fn_keyword)]
#[diag("expected identifier, found keyword `fn`")]
pub(crate) struct ExpectedFnPathFoundFnKeyword {
#[primary_span]
#[suggestion(applicability = "machine-applicable", code = "Fn", style = "verbose")]
#[suggestion(
"use `Fn` to refer to the trait",
applicability = "machine-applicable",
code = "Fn",
style = "verbose"
)]
pub fn_token_span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_path_found_named_params)]
#[diag("`Trait(...)` syntax does not support named parameters")]
pub(crate) struct FnPathFoundNamedParams {
#[primary_span]
#[suggestion(applicability = "machine-applicable", code = "")]
#[suggestion("remove the parameter name", applicability = "machine-applicable", code = "")]
pub named_param_span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_path_found_c_variadic_params)]
#[diag("`Trait(...)` syntax does not support c_variadic parameters")]
pub(crate) struct PathFoundCVariadicParams {
#[primary_span]
#[suggestion(applicability = "machine-applicable", code = "")]
#[suggestion("remove the `...`", applicability = "machine-applicable", code = "")]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_path_found_attribute_in_params)]
#[diag("`Trait(...)` syntax does not support attributes in parameters")]
pub(crate) struct PathFoundAttributeInParams {
#[primary_span]
#[suggestion(applicability = "machine-applicable", code = "")]
#[suggestion("remove the attributes", applicability = "machine-applicable", code = "")]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_path_double_colon)]
#[diag("path separator must be a double colon")]
pub(crate) struct PathSingleColon {
#[primary_span]
pub span: Span,
#[suggestion(applicability = "machine-applicable", code = ":", style = "verbose")]
#[suggestion(
"use a double colon instead",
applicability = "machine-applicable",
code = ":",
style = "verbose"
)]
pub suggestion: Span,
}
#[derive(Diagnostic)]
#[diag(parse_path_double_colon)]
#[diag("path separator must be a double colon")]
pub(crate) struct PathTripleColon {
#[primary_span]
#[suggestion(applicability = "maybe-incorrect", code = "", style = "verbose")]
#[suggestion(
"use a double colon instead",
applicability = "maybe-incorrect",
code = "",
style = "verbose"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_colon_as_semi)]
#[diag("statements are terminated with a semicolon")]
pub(crate) struct ColonAsSemi {
#[primary_span]
#[suggestion(applicability = "machine-applicable", code = ";", style = "verbose")]
#[suggestion(
"use a semicolon instead",
applicability = "machine-applicable",
code = ";",
style = "verbose"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_where_clause_before_tuple_struct_body)]
#[diag("where clauses are not allowed before tuple struct bodies")]
pub(crate) struct WhereClauseBeforeTupleStructBody {
#[primary_span]
#[label]
#[label("unexpected where clause")]
pub span: Span,
#[label(parse_name_label)]
#[label("while parsing this tuple struct")]
pub name: Span,
#[label(parse_body_label)]
#[label("the struct body")]
pub body: Span,
#[subdiagnostic]
pub sugg: Option<WhereClauseBeforeTupleStructBodySugg>,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(parse_suggestion, applicability = "machine-applicable")]
#[multipart_suggestion(
"move the body before the where clause",
applicability = "machine-applicable"
)]
pub(crate) struct WhereClauseBeforeTupleStructBodySugg {
#[suggestion_part(code = "{snippet}")]
pub left: Span,
@@ -1790,38 +2104,38 @@ pub(crate) struct WhereClauseBeforeTupleStructBodySugg {
}
#[derive(Diagnostic)]
#[diag(parse_async_fn_in_2015, code = E0670)]
#[diag("`async fn` is not permitted in Rust 2015", code = E0670)]
pub(crate) struct AsyncFnIn2015 {
#[primary_span]
#[label]
#[label("to use `async fn`, switch to Rust 2018 or later")]
pub span: Span,
#[subdiagnostic]
pub help: HelpUseLatestEdition,
}
#[derive(Subdiagnostic)]
#[label(parse_async_block_in_2015)]
#[label("`async` blocks are only allowed in Rust 2018 or later")]
pub(crate) struct AsyncBlockIn2015 {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_async_move_block_in_2015)]
#[diag("`async move` blocks are only allowed in Rust 2018 or later")]
pub(crate) struct AsyncMoveBlockIn2015 {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_async_use_block_in_2015)]
#[diag("`async use` blocks are only allowed in Rust 2018 or later")]
pub(crate) struct AsyncUseBlockIn2015 {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_async_bound_modifier_in_2015)]
#[diag("`async` trait bounds are only allowed in Rust 2018 or later")]
pub(crate) struct AsyncBoundModifierIn2015 {
#[primary_span]
pub span: Span,
@@ -1830,22 +2144,22 @@ pub(crate) struct AsyncBoundModifierIn2015 {
}
#[derive(Diagnostic)]
#[diag(parse_let_chain_pre_2024)]
#[diag("let chains are only allowed in Rust 2024 or later")]
pub(crate) struct LetChainPre2024 {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_self_argument_pointer)]
#[diag("cannot pass `self` by raw pointer")]
pub(crate) struct SelfArgumentPointer {
#[primary_span]
#[label]
#[label("cannot pass `self` by raw pointer")]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_unexpected_token_after_dot)]
#[diag("unexpected token: {$actual}")]
pub(crate) struct UnexpectedTokenAfterDot {
#[primary_span]
pub span: Span,
@@ -1853,64 +2167,84 @@ pub(crate) struct UnexpectedTokenAfterDot {
}
#[derive(Diagnostic)]
#[diag(parse_visibility_not_followed_by_item)]
#[help]
#[diag("visibility `{$vis}` is not followed by an item")]
#[help("you likely meant to define an item, e.g., `{$vis} fn foo() {\"{}\"}`")]
pub(crate) struct VisibilityNotFollowedByItem {
#[primary_span]
#[label]
#[label("the visibility")]
pub span: Span,
pub vis: Visibility,
}
#[derive(Diagnostic)]
#[diag(parse_default_not_followed_by_item)]
#[note]
#[diag("`default` is not followed by an item")]
#[note("only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`")]
pub(crate) struct DefaultNotFollowedByItem {
#[primary_span]
#[label]
#[label("the `default` qualifier")]
pub span: Span,
}
#[derive(Diagnostic)]
pub(crate) enum MissingKeywordForItemDefinition {
#[diag(parse_missing_enum_for_enum_definition)]
#[diag("missing `enum` for enum definition")]
Enum {
#[primary_span]
span: Span,
#[suggestion(style = "verbose", applicability = "maybe-incorrect", code = "enum ")]
#[suggestion(
"add `enum` here to parse `{$ident}` as an enum",
style = "verbose",
applicability = "maybe-incorrect",
code = "enum "
)]
insert_span: Span,
ident: Ident,
},
#[diag(parse_missing_enum_or_struct_for_item_definition)]
#[diag("missing `enum` or `struct` for enum or struct definition")]
EnumOrStruct {
#[primary_span]
span: Span,
},
#[diag(parse_missing_struct_for_struct_definition)]
#[diag("missing `struct` for struct definition")]
Struct {
#[primary_span]
span: Span,
#[suggestion(style = "verbose", applicability = "maybe-incorrect", code = "struct ")]
#[suggestion(
"add `struct` here to parse `{$ident}` as a struct",
style = "verbose",
applicability = "maybe-incorrect",
code = "struct "
)]
insert_span: Span,
ident: Ident,
},
#[diag(parse_missing_fn_for_function_definition)]
#[diag("missing `fn` for function definition")]
Function {
#[primary_span]
span: Span,
#[suggestion(style = "verbose", applicability = "maybe-incorrect", code = "fn ")]
#[suggestion(
"add `fn` here to parse `{$ident}` as a function",
style = "verbose",
applicability = "maybe-incorrect",
code = "fn "
)]
insert_span: Span,
ident: Ident,
},
#[diag(parse_missing_fn_for_method_definition)]
#[diag("missing `fn` for method definition")]
Method {
#[primary_span]
span: Span,
#[suggestion(style = "verbose", applicability = "maybe-incorrect", code = "fn ")]
#[suggestion(
"add `fn` here to parse `{$ident}` as a method",
style = "verbose",
applicability = "maybe-incorrect",
code = "fn "
)]
insert_span: Span,
ident: Ident,
},
#[diag(parse_missing_fn_or_struct_for_item_definition)]
#[diag("missing `fn` or `struct` for function or struct definition")]
Ambiguous {
#[primary_span]
span: Span,
@@ -1922,7 +2256,7 @@ pub(crate) enum MissingKeywordForItemDefinition {
#[derive(Subdiagnostic)]
pub(crate) enum AmbiguousMissingKwForItemSub {
#[suggestion(
parse_suggestion,
"if you meant to call a macro, try",
applicability = "maybe-incorrect",
code = "{snippet}!",
style = "verbose"
@@ -1932,39 +2266,49 @@ pub(crate) enum AmbiguousMissingKwForItemSub {
span: Span,
snippet: String,
},
#[help(parse_help)]
#[help("you likely meant to define an item, e.g., `{$vis} fn foo() {\"{}\"}`")]
HelpMacro,
}
#[derive(Diagnostic)]
#[diag(parse_missing_fn_params)]
#[diag("missing parameters for function definition")]
pub(crate) struct MissingFnParams {
#[primary_span]
#[suggestion(code = "()", applicability = "machine-applicable", style = "verbose")]
#[suggestion(
"add a parameter list",
code = "()",
applicability = "machine-applicable",
style = "verbose"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_invalid_path_sep_in_fn_definition)]
#[diag("invalid path separator in function definition")]
pub(crate) struct InvalidPathSepInFnDefinition {
#[primary_span]
#[suggestion(code = "", applicability = "machine-applicable", style = "verbose")]
#[suggestion(
"remove invalid path separator",
code = "",
applicability = "machine-applicable",
style = "verbose"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_missing_trait_in_trait_impl)]
#[diag("missing trait in a trait impl")]
pub(crate) struct MissingTraitInTraitImpl {
#[primary_span]
#[suggestion(
parse_suggestion_add_trait,
"add a trait here",
code = " Trait ",
applicability = "has-placeholders",
style = "verbose"
)]
pub span: Span,
#[suggestion(
parse_suggestion_remove_for,
"for an inherent impl, drop this `for`",
code = "",
applicability = "maybe-incorrect",
style = "verbose"
@@ -1973,102 +2317,130 @@ pub(crate) struct MissingTraitInTraitImpl {
}
#[derive(Diagnostic)]
#[diag(parse_missing_for_in_trait_impl)]
#[diag("missing `for` in a trait impl")]
pub(crate) struct MissingForInTraitImpl {
#[primary_span]
#[suggestion(style = "verbose", code = " for ", applicability = "machine-applicable")]
#[suggestion(
"add `for` here",
style = "verbose",
code = " for ",
applicability = "machine-applicable"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_expected_trait_in_trait_impl_found_type)]
#[diag("expected a trait, found type")]
pub(crate) struct ExpectedTraitInTraitImplFoundType {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_extra_impl_keyword_in_trait_impl)]
#[diag("unexpected `impl` keyword")]
pub(crate) struct ExtraImplKeywordInTraitImpl {
#[primary_span]
#[suggestion(code = "", applicability = "maybe-incorrect", style = "short")]
#[suggestion(
"remove the extra `impl`",
code = "",
applicability = "maybe-incorrect",
style = "short"
)]
pub extra_impl_kw: Span,
#[note]
#[note("this is parsed as an `impl Trait` type, but a trait is expected at this position")]
pub impl_trait_span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_bounds_not_allowed_on_trait_aliases)]
#[diag("bounds are not allowed on trait aliases")]
pub(crate) struct BoundsNotAllowedOnTraitAliases {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_trait_alias_cannot_be_auto)]
#[diag("trait aliases cannot be `auto`")]
pub(crate) struct TraitAliasCannotBeAuto {
#[primary_span]
#[label(parse_trait_alias_cannot_be_auto)]
#[label("trait aliases cannot be `auto`")]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_trait_alias_cannot_be_unsafe)]
#[diag("trait aliases cannot be `unsafe`")]
pub(crate) struct TraitAliasCannotBeUnsafe {
#[primary_span]
#[label(parse_trait_alias_cannot_be_unsafe)]
#[label("trait aliases cannot be `unsafe`")]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_associated_static_item_not_allowed)]
#[diag("associated `static` items are not allowed")]
pub(crate) struct AssociatedStaticItemNotAllowed {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_extern_crate_name_with_dashes)]
#[diag("crate name using dashes are not valid in `extern crate` statements")]
pub(crate) struct ExternCrateNameWithDashes {
#[primary_span]
#[label]
#[label("dash-separated idents are not valid")]
pub span: Span,
#[subdiagnostic]
pub sugg: ExternCrateNameWithDashesSugg,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(parse_suggestion, applicability = "machine-applicable")]
#[multipart_suggestion(
"if the original crate name uses dashes you need to use underscores in the code",
applicability = "machine-applicable"
)]
pub(crate) struct ExternCrateNameWithDashesSugg {
#[suggestion_part(code = "_")]
pub dashes: Vec<Span>,
}
#[derive(Diagnostic)]
#[diag(parse_extern_item_cannot_be_const)]
#[note]
#[diag("extern items cannot be `const`")]
#[note("for more information, visit https://doc.rust-lang.org/std/keyword.extern.html")]
pub(crate) struct ExternItemCannotBeConst {
#[primary_span]
pub ident_span: Span,
#[suggestion(code = "static ", applicability = "machine-applicable", style = "verbose")]
#[suggestion(
"try using a static value",
code = "static ",
applicability = "machine-applicable",
style = "verbose"
)]
pub const_span: Option<Span>,
}
#[derive(Diagnostic)]
#[diag(parse_const_global_cannot_be_mutable)]
#[diag("const globals cannot be mutable")]
pub(crate) struct ConstGlobalCannotBeMutable {
#[primary_span]
#[label]
#[label("cannot be mutable")]
pub ident_span: Span,
#[suggestion(code = "static", style = "verbose", applicability = "maybe-incorrect")]
#[suggestion(
"you might want to declare a static instead",
code = "static",
style = "verbose",
applicability = "maybe-incorrect"
)]
pub const_span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_missing_const_type)]
#[diag("missing type for `{$kind}` item")]
pub(crate) struct MissingConstType {
#[primary_span]
#[suggestion(code = "{colon} <type>", style = "verbose", applicability = "has-placeholders")]
#[suggestion(
"provide a type for the item",
code = "{colon} <type>",
style = "verbose",
applicability = "has-placeholders"
)]
pub span: Span,
pub kind: &'static str,
@@ -2076,53 +2448,64 @@ pub(crate) struct MissingConstType {
}
#[derive(Diagnostic)]
#[diag(parse_enum_struct_mutually_exclusive)]
#[diag("`enum` and `struct` are mutually exclusive")]
pub(crate) struct EnumStructMutuallyExclusive {
#[primary_span]
#[suggestion(code = "enum", style = "verbose", applicability = "machine-applicable")]
#[suggestion(
"replace `enum struct` with",
code = "enum",
style = "verbose",
applicability = "machine-applicable"
)]
pub span: Span,
}
#[derive(Diagnostic)]
pub(crate) enum UnexpectedTokenAfterStructName {
#[diag(parse_unexpected_token_after_struct_name_found_reserved_identifier)]
#[diag(
"expected `where`, `{\"{\"}`, `(`, or `;` after struct name, found reserved identifier `{$token}`"
)]
ReservedIdentifier {
#[primary_span]
#[label(parse_unexpected_token_after_struct_name)]
#[label("expected `where`, `{\"{\"}`, `(`, or `;` after struct name")]
span: Span,
token: Token,
},
#[diag(parse_unexpected_token_after_struct_name_found_keyword)]
#[diag("expected `where`, `{\"{\"}`, `(`, or `;` after struct name, found keyword `{$token}`")]
Keyword {
#[primary_span]
#[label(parse_unexpected_token_after_struct_name)]
#[label("expected `where`, `{\"{\"}`, `(`, or `;` after struct name")]
span: Span,
token: Token,
},
#[diag(parse_unexpected_token_after_struct_name_found_reserved_keyword)]
#[diag(
"expected `where`, `{\"{\"}`, `(`, or `;` after struct name, found reserved keyword `{$token}`"
)]
ReservedKeyword {
#[primary_span]
#[label(parse_unexpected_token_after_struct_name)]
#[label("expected `where`, `{\"{\"}`, `(`, or `;` after struct name")]
span: Span,
token: Token,
},
#[diag(parse_unexpected_token_after_struct_name_found_doc_comment)]
#[diag(
"expected `where`, `{\"{\"}`, `(`, or `;` after struct name, found doc comment `{$token}`"
)]
DocComment {
#[primary_span]
#[label(parse_unexpected_token_after_struct_name)]
#[label("expected `where`, `{\"{\"}`, `(`, or `;` after struct name")]
span: Span,
token: Token,
},
#[diag(parse_unexpected_token_after_struct_name_found_metavar)]
#[diag("expected `where`, `{\"{\"}`, `(`, or `;` after struct name, found metavar")]
MetaVar {
#[primary_span]
#[label(parse_unexpected_token_after_struct_name)]
#[label("expected `where`, `{\"{\"}`, `(`, or `;` after struct name")]
span: Span,
},
#[diag(parse_unexpected_token_after_struct_name_found_other)]
#[diag("expected `where`, `{\"{\"}`, `(`, or `;` after struct name, found `{$token}`")]
Other {
#[primary_span]
#[label(parse_unexpected_token_after_struct_name)]
#[label("expected `where`, `{\"{\"}`, `(`, or `;` after struct name")]
span: Span,
token: Token,
},
@@ -2142,45 +2525,50 @@ pub(crate) fn new(span: Span, token: Token) -> Self {
}
#[derive(Diagnostic)]
#[diag(parse_unexpected_self_in_generic_parameters)]
#[note]
#[diag("unexpected keyword `Self` in generic parameters")]
#[note("you cannot use `Self` as a generic parameter because it is reserved for associated items")]
pub(crate) struct UnexpectedSelfInGenericParameters {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_unexpected_default_value_for_lifetime_in_generic_parameters)]
#[diag("unexpected default lifetime parameter")]
pub(crate) struct UnexpectedDefaultValueForLifetimeInGenericParameters {
#[primary_span]
#[label]
#[label("lifetime parameters cannot have default values")]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_multiple_where_clauses)]
#[diag("cannot define duplicate `where` clauses on an item")]
pub(crate) struct MultipleWhereClauses {
#[primary_span]
pub span: Span,
#[label]
#[label("previous `where` clause starts here")]
pub previous: Span,
#[suggestion(style = "verbose", code = ",", applicability = "maybe-incorrect")]
#[suggestion(
"consider joining the two `where` clauses into one",
style = "verbose",
code = ",",
applicability = "maybe-incorrect"
)]
pub between: Span,
}
#[derive(Diagnostic)]
pub(crate) enum UnexpectedNonterminal {
#[diag(parse_nonterminal_expected_item_keyword)]
#[diag("expected an item keyword")]
Item(#[primary_span] Span),
#[diag(parse_nonterminal_expected_statement)]
#[diag("expected a statement")]
Statement(#[primary_span] Span),
#[diag(parse_nonterminal_expected_ident)]
#[diag("expected ident, found `{$token}`")]
Ident {
#[primary_span]
span: Span,
token: Token,
},
#[diag(parse_nonterminal_expected_lifetime)]
#[diag("expected a lifetime, found `{$token}`")]
Lifetime {
#[primary_span]
span: Span,
@@ -2190,14 +2578,14 @@ pub(crate) enum UnexpectedNonterminal {
#[derive(Diagnostic)]
pub(crate) enum TopLevelOrPatternNotAllowed {
#[diag(parse_or_pattern_not_allowed_in_let_binding)]
#[diag("`let` bindings require top-level or-patterns in parentheses")]
LetBinding {
#[primary_span]
span: Span,
#[subdiagnostic]
sub: Option<TopLevelOrPatternNotAllowedSugg>,
},
#[diag(parse_or_pattern_not_allowed_in_fn_parameters)]
#[diag("function parameters require top-level or-patterns in parentheses")]
FunctionParameter {
#[primary_span]
span: Span,
@@ -2207,7 +2595,7 @@ pub(crate) enum TopLevelOrPatternNotAllowed {
}
#[derive(Diagnostic)]
#[diag(parse_cannot_be_raw_ident)]
#[diag("`{$ident}` cannot be a raw identifier")]
pub(crate) struct CannotBeRawIdent {
#[primary_span]
pub span: Span,
@@ -2215,7 +2603,7 @@ pub(crate) struct CannotBeRawIdent {
}
#[derive(Diagnostic)]
#[diag(parse_cannot_be_raw_lifetime)]
#[diag("`{$ident}` cannot be a raw lifetime")]
pub(crate) struct CannotBeRawLifetime {
#[primary_span]
pub span: Span,
@@ -2223,21 +2611,26 @@ pub(crate) struct CannotBeRawLifetime {
}
#[derive(Diagnostic)]
#[diag(parse_keyword_lifetime)]
#[diag("lifetimes cannot use keyword names")]
pub(crate) struct KeywordLifetime {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_keyword_label)]
#[diag("labels cannot use keyword names")]
pub(crate) struct KeywordLabel {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_cr_doc_comment)]
#[diag(
"bare CR not allowed in {$block ->
[true] block doc-comment
*[false] doc-comment
}"
)]
pub(crate) struct CrDocComment {
#[primary_span]
pub span: Span,
@@ -2245,14 +2638,14 @@ pub(crate) struct CrDocComment {
}
#[derive(Diagnostic)]
#[diag(parse_no_digits_literal, code = E0768)]
#[diag("no valid digits found for number", code = E0768)]
pub(crate) struct NoDigitsLiteral {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_invalid_digit_literal)]
#[diag("invalid digit for a base {$base} literal")]
pub(crate) struct InvalidDigitLiteral {
#[primary_span]
pub span: Span,
@@ -2260,14 +2653,14 @@ pub(crate) struct InvalidDigitLiteral {
}
#[derive(Diagnostic)]
#[diag(parse_empty_exponent_float)]
#[diag("expected at least one digit in exponent")]
pub(crate) struct EmptyExponentFloat {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_float_literal_unsupported_base)]
#[diag("{$base} float literal is not supported")]
pub(crate) struct FloatLiteralUnsupportedBase {
#[primary_span]
pub span: Span,
@@ -2275,11 +2668,11 @@ pub(crate) struct FloatLiteralUnsupportedBase {
}
#[derive(Diagnostic)]
#[diag(parse_unknown_prefix)]
#[note]
#[diag("prefix `{$prefix}` is unknown")]
#[note("prefixed identifiers and literals are reserved since Rust 2021")]
pub(crate) struct UnknownPrefix<'a> {
#[primary_span]
#[label]
#[label("unknown prefix")]
pub span: Span,
pub prefix: &'a str,
#[subdiagnostic]
@@ -2287,7 +2680,7 @@ pub(crate) struct UnknownPrefix<'a> {
}
#[derive(Subdiagnostic)]
#[note(parse_macro_expands_to_adt_field)]
#[note("macros cannot expand to {$adt_ty} fields")]
pub(crate) struct MacroExpandsToAdtField<'a> {
pub adt_ty: &'a str,
}
@@ -2295,28 +2688,28 @@ pub(crate) struct MacroExpandsToAdtField<'a> {
#[derive(Subdiagnostic)]
pub(crate) enum UnknownPrefixSugg {
#[suggestion(
parse_suggestion_br,
"use `br` for a raw byte string",
code = "br",
applicability = "maybe-incorrect",
style = "verbose"
)]
UseBr(#[primary_span] Span),
#[suggestion(
parse_suggestion_cr,
"use `cr` for a raw C-string",
code = "cr",
applicability = "maybe-incorrect",
style = "verbose"
)]
UseCr(#[primary_span] Span),
#[suggestion(
parse_suggestion_whitespace,
"consider inserting whitespace here",
code = " ",
applicability = "maybe-incorrect",
style = "verbose"
)]
Whitespace(#[primary_span] Span),
#[multipart_suggestion(
parse_suggestion_str,
"if you meant to write a string literal, use double quotes",
applicability = "maybe-incorrect",
style = "verbose"
)]
@@ -2329,8 +2722,8 @@ pub(crate) enum UnknownPrefixSugg {
}
#[derive(Diagnostic)]
#[diag(parse_reserved_multihash)]
#[note]
#[diag("reserved multi-hash token is forbidden")]
#[note("sequences of two or more # are reserved for future use since Rust 2024")]
pub(crate) struct ReservedMultihash {
#[primary_span]
pub span: Span,
@@ -2338,8 +2731,8 @@ pub(crate) struct ReservedMultihash {
pub sugg: Option<GuardedStringSugg>,
}
#[derive(Diagnostic)]
#[diag(parse_reserved_string)]
#[note]
#[diag("invalid string literal")]
#[note("unprefixed guarded string literals are reserved for future use since Rust 2024")]
pub(crate) struct ReservedString {
#[primary_span]
pub span: Span,
@@ -2348,7 +2741,7 @@ pub(crate) struct ReservedString {
}
#[derive(Subdiagnostic)]
#[suggestion(
parse_suggestion_whitespace,
"consider inserting whitespace here",
code = " ",
applicability = "maybe-incorrect",
style = "verbose"
@@ -2356,7 +2749,9 @@ pub(crate) struct ReservedString {
pub(crate) struct GuardedStringSugg(#[primary_span] pub Span);
#[derive(Diagnostic)]
#[diag(parse_too_many_hashes)]
#[diag(
"too many `#` symbols: raw strings may be delimited by up to 255 `#` symbols, but found {$num}"
)]
pub(crate) struct TooManyHashes {
#[primary_span]
pub span: Span,
@@ -2364,7 +2759,7 @@ pub(crate) struct TooManyHashes {
}
#[derive(Diagnostic)]
#[diag(parse_unknown_start_of_token)]
#[diag("unknown start of token: {$escaped}")]
pub(crate) struct UnknownTokenStart {
#[primary_span]
pub span: Span,
@@ -2382,7 +2777,7 @@ pub(crate) struct UnknownTokenStart {
#[derive(Subdiagnostic)]
pub(crate) enum TokenSubstitution {
#[suggestion(
parse_sugg_quotes,
"Unicode characters '“' (Left Double Quotation Mark) and '”' (Right Double Quotation Mark) look like '{$ascii_str}' ({$ascii_name}), but are not",
code = "{suggestion}",
applicability = "maybe-incorrect",
style = "verbose"
@@ -2395,7 +2790,7 @@ pub(crate) enum TokenSubstitution {
ascii_name: &'static str,
},
#[suggestion(
parse_sugg_other,
"Unicode character '{$ch}' ({$u_name}) looks like '{$ascii_str}' ({$ascii_name}), but it is not",
code = "{suggestion}",
applicability = "maybe-incorrect",
style = "verbose"
@@ -2412,35 +2807,52 @@ pub(crate) enum TokenSubstitution {
}
#[derive(Subdiagnostic)]
#[note(parse_note_repeats)]
#[note(
"character appears {$repeats ->
[one] once more
*[other] {$repeats} more times
}"
)]
pub(crate) struct UnknownTokenRepeat {
pub repeats: usize,
}
#[derive(Subdiagnostic)]
#[help(parse_help_invisible_char)]
#[help("invisible characters like '{$escaped}' are not usually visible in text editors")]
pub(crate) struct InvisibleCharacter;
#[derive(Subdiagnostic)]
#[help(parse_help_null)]
#[help(
"source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used"
)]
pub(crate) struct UnknownTokenNull;
#[derive(Diagnostic)]
pub(crate) enum UnescapeError {
#[diag(parse_invalid_unicode_escape)]
#[help]
#[diag("invalid unicode character escape")]
#[help(
"unicode escape must {$surrogate ->
[true] not be a surrogate
*[false] be at most 10FFFF
}"
)]
InvalidUnicodeEscape {
#[primary_span]
#[label]
#[label("invalid escape")]
span: Span,
surrogate: bool,
},
#[diag(parse_escape_only_char)]
#[diag(
"{$byte ->
[true] byte
*[false] character
} constant must be escaped: `{$escaped_msg}`"
)]
EscapeOnlyChar {
#[primary_span]
span: Span,
#[suggestion(
parse_escape,
"escape the character",
applicability = "machine-applicable",
code = "{escaped_sugg}",
style = "verbose"
@@ -2450,11 +2862,16 @@ pub(crate) enum UnescapeError {
escaped_msg: String,
byte: bool,
},
#[diag(parse_bare_cr)]
#[diag(
r#"{$double_quotes ->
[true] bare CR not allowed in string, use `\r` instead
*[false] character constant must be escaped: `\r`
}"#
)]
BareCr {
#[primary_span]
#[suggestion(
parse_escape,
"escape the character",
applicability = "machine-applicable",
code = "\\r",
style = "verbose"
@@ -2462,93 +2879,103 @@ pub(crate) enum UnescapeError {
span: Span,
double_quotes: bool,
},
#[diag(parse_bare_cr_in_raw_string)]
#[diag("bare CR not allowed in raw string")]
BareCrRawString(#[primary_span] Span),
#[diag(parse_too_short_hex_escape)]
#[diag("numeric character escape is too short")]
TooShortHexEscape(#[primary_span] Span),
#[diag(parse_invalid_char_in_escape)]
#[diag(
"invalid character in {$is_hex ->
[true] numeric character
*[false] unicode
} escape: `{$ch}`"
)]
InvalidCharInEscape {
#[primary_span]
#[label]
#[label(
"invalid character in {$is_hex ->
[true] numeric character
*[false] unicode
} escape"
)]
span: Span,
is_hex: bool,
ch: String,
},
#[diag(parse_leading_underscore_unicode_escape)]
#[diag("invalid start of unicode escape: `_`")]
LeadingUnderscoreUnicodeEscape {
#[primary_span]
#[label(parse_leading_underscore_unicode_escape_label)]
#[label("invalid start of unicode escape")]
span: Span,
ch: String,
},
#[diag(parse_overlong_unicode_escape)]
#[diag("overlong unicode escape")]
OverlongUnicodeEscape(
#[primary_span]
#[label]
#[label("must have at most 6 hex digits")]
Span,
),
#[diag(parse_unclosed_unicode_escape)]
#[diag("unterminated unicode escape")]
UnclosedUnicodeEscape(
#[primary_span]
#[label]
#[label(r#"missing a closing `{"}"}`"#)]
Span,
#[suggestion(
parse_terminate,
"terminate the unicode escape",
code = "}}",
applicability = "maybe-incorrect",
style = "verbose"
)]
Span,
),
#[diag(parse_no_brace_unicode_escape)]
#[diag("incorrect unicode escape sequence")]
NoBraceInUnicodeEscape {
#[primary_span]
span: Span,
#[label]
#[label("incorrect unicode escape sequence")]
label: Option<Span>,
#[subdiagnostic]
sub: NoBraceUnicodeSub,
},
#[diag(parse_unicode_escape_in_byte)]
#[help]
#[diag("unicode escape in byte string")]
#[help("unicode escape sequences cannot be used as a byte or in a byte string")]
UnicodeEscapeInByte(
#[primary_span]
#[label]
#[label("unicode escape in byte string")]
Span,
),
#[diag(parse_empty_unicode_escape)]
#[diag("empty unicode escape")]
EmptyUnicodeEscape(
#[primary_span]
#[label]
#[label("this escape must have at least 1 hex digit")]
Span,
),
#[diag(parse_zero_chars)]
#[diag("empty character literal")]
ZeroChars(
#[primary_span]
#[label]
#[label("empty character literal")]
Span,
),
#[diag(parse_lone_slash)]
#[diag("invalid trailing slash in literal")]
LoneSlash(
#[primary_span]
#[label]
#[label("invalid trailing slash in literal")]
Span,
),
#[diag(parse_unskipped_whitespace)]
#[diag("whitespace symbol '{$ch}' is not skipped")]
UnskippedWhitespace {
#[primary_span]
span: Span,
#[label]
#[label("whitespace symbol '{$ch}' is not skipped")]
char_span: Span,
ch: String,
},
#[diag(parse_multiple_skipped_lines)]
#[diag("multiple lines skipped by escaped newline")]
MultipleSkippedLinesWarning(
#[primary_span]
#[label]
#[label("skipping everything up to and including this point")]
Span,
),
#[diag(parse_more_than_one_char)]
#[diag("character literal may only contain one codepoint")]
MoreThanOneChar {
#[primary_span]
span: Span,
@@ -2557,7 +2984,7 @@ pub(crate) enum UnescapeError {
#[subdiagnostic]
suggestion: MoreThanOneCharSugg,
},
#[diag(parse_nul_in_c_str)]
#[diag("null characters in C string literals are not supported")]
NulInCStr {
#[primary_span]
span: Span,
@@ -2567,7 +2994,7 @@ pub(crate) enum UnescapeError {
#[derive(Subdiagnostic)]
pub(crate) enum MoreThanOneCharSugg {
#[suggestion(
parse_consider_normalized,
"consider using the normalized form `{$ch}` of this character",
code = "{normalized}",
applicability = "machine-applicable",
style = "verbose"
@@ -2579,7 +3006,7 @@ pub(crate) enum MoreThanOneCharSugg {
normalized: String,
},
#[suggestion(
parse_remove_non,
"consider removing the non-printing characters",
code = "{ch}",
applicability = "maybe-incorrect",
style = "verbose"
@@ -2590,7 +3017,10 @@ pub(crate) enum MoreThanOneCharSugg {
ch: String,
},
#[suggestion(
parse_use_double_quotes,
"if you meant to write a {$is_byte ->
[true] byte string
*[false] string
} literal, use double quotes",
code = "{sugg}",
applicability = "machine-applicable",
style = "verbose"
@@ -2601,7 +3031,13 @@ pub(crate) enum MoreThanOneCharSugg {
is_byte: bool,
sugg: String,
},
#[multipart_suggestion(parse_use_double_quotes, applicability = "machine-applicable")]
#[multipart_suggestion(
"if you meant to write a {$is_byte ->
[true] byte string
*[false] string
} literal, use double quotes",
applicability = "machine-applicable"
)]
Quotes {
#[suggestion_part(code = "{prefix}\"")]
start: Span,
@@ -2614,7 +3050,12 @@ pub(crate) enum MoreThanOneCharSugg {
#[derive(Subdiagnostic)]
pub(crate) enum MoreThanOneCharNote {
#[note(parse_followed_by)]
#[note(
"this `{$chr}` is followed by the combining {$len ->
[one] mark
*[other] marks
} `{$escaped_marks}`"
)]
AllCombining {
#[primary_span]
span: Span,
@@ -2622,7 +3063,7 @@ pub(crate) enum MoreThanOneCharNote {
len: usize,
escaped_marks: String,
},
#[note(parse_non_printing)]
#[note("there are non-printing characters, the full sequence is `{$escaped}`")]
NonPrinting {
#[primary_span]
span: Span,
@@ -2633,7 +3074,7 @@ pub(crate) enum MoreThanOneCharNote {
#[derive(Subdiagnostic)]
pub(crate) enum NoBraceUnicodeSub {
#[suggestion(
parse_use_braces,
"format of unicode escape sequences uses braces",
code = "{suggestion}",
applicability = "maybe-incorrect",
style = "verbose"
@@ -2643,12 +3084,12 @@ pub(crate) enum NoBraceUnicodeSub {
span: Span,
suggestion: String,
},
#[help(parse_format_of_unicode)]
#[help(r#"format of unicode escape sequences is `\u{"{...}"}`"#)]
Help,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(parse_sugg_wrap_pattern_in_parens, applicability = "machine-applicable")]
#[multipart_suggestion("wrap the pattern in parentheses", applicability = "machine-applicable")]
pub(crate) struct WrapInParens {
#[suggestion_part(code = "(")]
pub(crate) lo: Span,
@@ -2659,7 +3100,7 @@ pub(crate) struct WrapInParens {
#[derive(Subdiagnostic)]
pub(crate) enum TopLevelOrPatternNotAllowedSugg {
#[suggestion(
parse_sugg_remove_leading_vert_in_pattern,
"remove the `|`",
code = "",
applicability = "machine-applicable",
style = "tool-only"
@@ -2677,27 +3118,37 @@ pub(crate) enum TopLevelOrPatternNotAllowedSugg {
}
#[derive(Diagnostic)]
#[diag(parse_unexpected_vert_vert_before_function_parameter)]
#[note(parse_note_pattern_alternatives_use_single_vert)]
#[diag("unexpected `||` before function parameter")]
#[note("alternatives in or-patterns are separated with `|`, not `||`")]
pub(crate) struct UnexpectedVertVertBeforeFunctionParam {
#[primary_span]
#[suggestion(code = "", applicability = "machine-applicable", style = "verbose")]
#[suggestion(
"remove the `||`",
code = "",
applicability = "machine-applicable",
style = "verbose"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_unexpected_vert_vert_in_pattern)]
#[diag("unexpected token `||` in pattern")]
pub(crate) struct UnexpectedVertVertInPattern {
#[primary_span]
#[suggestion(code = "|", applicability = "machine-applicable", style = "verbose")]
#[suggestion(
"use a single `|` to separate multiple alternative patterns",
code = "|",
applicability = "machine-applicable",
style = "verbose"
)]
pub span: Span,
#[label(parse_label_while_parsing_or_pattern_here)]
#[label("while parsing this or-pattern starting here")]
pub start: Option<Span>,
}
#[derive(Subdiagnostic)]
#[suggestion(
parse_trailing_vert_not_allowed,
"a trailing `{$token}` is not allowed in an or-pattern",
code = "",
applicability = "machine-applicable",
style = "tool-only"
@@ -2708,59 +3159,71 @@ pub(crate) struct TrailingVertSuggestion {
}
#[derive(Diagnostic)]
#[diag(parse_trailing_vert_not_allowed)]
#[diag("a trailing `{$token}` is not allowed in an or-pattern")]
pub(crate) struct TrailingVertNotAllowed {
#[primary_span]
pub span: Span,
#[subdiagnostic]
pub suggestion: TrailingVertSuggestion,
#[label(parse_label_while_parsing_or_pattern_here)]
#[label("while parsing this or-pattern starting here")]
pub start: Option<Span>,
pub token: Token,
#[note(parse_note_pattern_alternatives_use_single_vert)]
#[note("alternatives in or-patterns are separated with `|`, not `||`")]
pub note_double_vert: bool,
}
#[derive(Diagnostic)]
#[diag(parse_dotdotdot_rest_pattern)]
#[diag("unexpected `...`")]
pub(crate) struct DotDotDotRestPattern {
#[primary_span]
#[label]
#[label("not a valid pattern")]
pub span: Span,
#[suggestion(style = "verbose", code = "", applicability = "machine-applicable")]
#[suggestion(
"for a rest pattern, use `..` instead of `...`",
style = "verbose",
code = "",
applicability = "machine-applicable"
)]
pub suggestion: Option<Span>,
#[note]
#[note(
"only `extern \"C\"` and `extern \"C-unwind\"` functions may have a C variable argument list"
)]
pub var_args: Option<()>,
}
#[derive(Diagnostic)]
#[diag(parse_pattern_on_wrong_side_of_at)]
#[diag("pattern on wrong side of `@`")]
pub(crate) struct PatternOnWrongSideOfAt {
#[primary_span]
#[suggestion(code = "{whole_pat}", applicability = "machine-applicable", style = "verbose")]
#[suggestion(
"switch the order",
code = "{whole_pat}",
applicability = "machine-applicable",
style = "verbose"
)]
pub whole_span: Span,
pub whole_pat: String,
#[label(parse_label_pattern)]
#[label("pattern on the left, should be on the right")]
pub pattern: Span,
#[label(parse_label_binding)]
#[label("binding on the right, should be on the left")]
pub binding: Span,
}
#[derive(Diagnostic)]
#[diag(parse_expected_binding_left_of_at)]
#[note]
#[diag("left-hand side of `@` must be a binding")]
#[note("bindings are `x`, `mut x`, `ref x`, and `ref mut x`")]
pub(crate) struct ExpectedBindingLeftOfAt {
#[primary_span]
pub whole_span: Span,
#[label(parse_label_lhs)]
#[label("interpreted as a pattern, not a binding")]
pub lhs: Span,
#[label(parse_label_rhs)]
#[label("also a pattern")]
pub rhs: Span,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(
parse_ambiguous_range_pattern_suggestion,
"add parentheses to clarify the precedence",
applicability = "machine-applicable"
)]
pub(crate) struct ParenRangeSuggestion {
@@ -2771,7 +3234,7 @@ pub(crate) struct ParenRangeSuggestion {
}
#[derive(Diagnostic)]
#[diag(parse_ambiguous_range_pattern)]
#[diag("the range pattern here has ambiguous interpretation")]
pub(crate) struct AmbiguousRangePattern {
#[primary_span]
pub span: Span,
@@ -2780,100 +3243,144 @@ pub(crate) struct AmbiguousRangePattern {
}
#[derive(Diagnostic)]
#[diag(parse_unexpected_lifetime_in_pattern)]
#[diag("unexpected lifetime `{$symbol}` in pattern")]
pub(crate) struct UnexpectedLifetimeInPattern {
#[primary_span]
pub span: Span,
pub symbol: Symbol,
#[suggestion(code = "", applicability = "machine-applicable", style = "verbose")]
#[suggestion(
"remove the lifetime",
code = "",
applicability = "machine-applicable",
style = "verbose"
)]
pub suggestion: Span,
}
#[derive(Diagnostic)]
pub(crate) enum InvalidMutInPattern {
#[diag(parse_mut_on_nested_ident_pattern)]
#[note(parse_note_mut_pattern_usage)]
#[diag("`mut` must be attached to each individual binding")]
#[note("`mut` may be followed by `variable` and `variable @ pattern`")]
NestedIdent {
#[primary_span]
#[suggestion(code = "{pat}", applicability = "machine-applicable", style = "verbose")]
#[suggestion(
"add `mut` to each binding",
code = "{pat}",
applicability = "machine-applicable",
style = "verbose"
)]
span: Span,
pat: String,
},
#[diag(parse_mut_on_non_ident_pattern)]
#[note(parse_note_mut_pattern_usage)]
#[diag("`mut` must be followed by a named binding")]
#[note("`mut` may be followed by `variable` and `variable @ pattern`")]
NonIdent {
#[primary_span]
#[suggestion(code = "", applicability = "machine-applicable", style = "verbose")]
#[suggestion(
"remove the `mut` prefix",
code = "",
applicability = "machine-applicable",
style = "verbose"
)]
span: Span,
},
}
#[derive(Diagnostic)]
#[diag(parse_repeated_mut_in_pattern)]
#[diag("`mut` on a binding may not be repeated")]
pub(crate) struct RepeatedMutInPattern {
#[primary_span]
pub span: Span,
#[suggestion(code = "", applicability = "machine-applicable", style = "verbose")]
#[suggestion(
"remove the additional `mut`s",
code = "",
applicability = "machine-applicable",
style = "verbose"
)]
pub suggestion: Span,
}
#[derive(Diagnostic)]
#[diag(parse_dot_dot_dot_range_to_pattern_not_allowed)]
#[diag("range-to patterns with `...` are not allowed")]
pub(crate) struct DotDotDotRangeToPatternNotAllowed {
#[primary_span]
#[suggestion(style = "verbose", code = "..=", applicability = "machine-applicable")]
#[suggestion(
"use `..=` instead",
style = "verbose",
code = "..=",
applicability = "machine-applicable"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_enum_pattern_instead_of_identifier)]
#[diag("expected identifier, found enum pattern")]
pub(crate) struct EnumPatternInsteadOfIdentifier {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_at_dot_dot_in_struct_pattern)]
#[diag("`@ ..` is not supported in struct patterns")]
pub(crate) struct AtDotDotInStructPattern {
#[primary_span]
pub span: Span,
#[suggestion(code = "", style = "verbose", applicability = "machine-applicable")]
#[suggestion(
"bind to each field separately or, if you don't need them, just remove `{$ident} @`",
code = "",
style = "verbose",
applicability = "machine-applicable"
)]
pub remove: Span,
pub ident: Ident,
}
#[derive(Diagnostic)]
#[diag(parse_at_in_struct_pattern)]
#[note]
#[help]
#[diag("unexpected `@` in struct pattern")]
#[note("struct patterns use `field: pattern` syntax to bind to fields")]
#[help(
"consider replacing `new_name @ field_name` with `field_name: new_name` if that is what you intended"
)]
pub(crate) struct AtInStructPattern {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_dot_dot_dot_for_remaining_fields)]
#[diag("expected field pattern, found `{$token_str}`")]
pub(crate) struct DotDotDotForRemainingFields {
#[primary_span]
#[suggestion(code = "..", style = "verbose", applicability = "machine-applicable")]
#[suggestion(
"to omit remaining fields, use `..`",
code = "..",
style = "verbose",
applicability = "machine-applicable"
)]
pub span: Span,
pub token_str: Cow<'static, str>,
}
#[derive(Diagnostic)]
#[diag(parse_expected_comma_after_pattern_field)]
#[diag("expected `,`")]
pub(crate) struct ExpectedCommaAfterPatternField {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_unexpected_expr_in_pat)]
#[note]
#[diag(
"expected {$is_bound ->
[true] a pattern range bound
*[false] a pattern
}, found an expression"
)]
#[note(
"arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch19-00-patterns.html>"
)]
pub(crate) struct UnexpectedExpressionInPattern {
/// The unexpected expr's span.
#[primary_span]
#[label]
#[label("not a pattern")]
pub span: Span,
/// Was a `RangePatternBound` expected?
pub is_bound: bool,
@@ -2884,7 +3391,7 @@ pub(crate) struct UnexpectedExpressionInPattern {
#[derive(Subdiagnostic)]
pub(crate) enum UnexpectedExpressionInPatternSugg {
#[multipart_suggestion(
parse_unexpected_expr_in_pat_create_guard_sugg,
"consider moving the expression to a match arm guard",
applicability = "maybe-incorrect"
)]
CreateGuard {
@@ -2901,7 +3408,7 @@ pub(crate) enum UnexpectedExpressionInPatternSugg {
},
#[multipart_suggestion(
parse_unexpected_expr_in_pat_update_guard_sugg,
"consider moving the expression to the match arm guard",
applicability = "maybe-incorrect"
)]
UpdateGuard {
@@ -2923,7 +3430,7 @@ pub(crate) enum UnexpectedExpressionInPatternSugg {
},
#[multipart_suggestion(
parse_unexpected_expr_in_pat_const_sugg,
"consider extracting the expression into a `const`",
applicability = "has-placeholders"
)]
Const {
@@ -2943,7 +3450,7 @@ pub(crate) enum UnexpectedExpressionInPatternSugg {
}
#[derive(Diagnostic)]
#[diag(parse_unexpected_paren_in_range_pat)]
#[diag("range pattern bounds cannot have parentheses")]
pub(crate) struct UnexpectedParenInRangePat {
#[primary_span]
pub span: Vec<Span>,
@@ -2952,10 +3459,7 @@ pub(crate) struct UnexpectedParenInRangePat {
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(
parse_unexpected_paren_in_range_pat_sugg,
applicability = "machine-applicable"
)]
#[multipart_suggestion("remove these parentheses", applicability = "machine-applicable")]
pub(crate) struct UnexpectedParenInRangePatSugg {
#[suggestion_part(code = "")]
pub start_span: Span,
@@ -2964,104 +3468,145 @@ pub(crate) struct UnexpectedParenInRangePatSugg {
}
#[derive(Diagnostic)]
#[diag(parse_return_types_use_thin_arrow)]
#[diag("return types are denoted using `->`")]
pub(crate) struct ReturnTypesUseThinArrow {
#[primary_span]
pub span: Span,
#[suggestion(style = "verbose", code = " -> ", applicability = "machine-applicable")]
#[suggestion(
"use `->` instead",
style = "verbose",
code = " -> ",
applicability = "machine-applicable"
)]
pub suggestion: Span,
}
#[derive(Diagnostic)]
#[diag(parse_need_plus_after_trait_object_lifetime)]
#[diag("lifetimes must be followed by `+` to form a trait object type")]
pub(crate) struct NeedPlusAfterTraitObjectLifetime {
#[primary_span]
pub span: Span,
#[suggestion(code = " + /* Trait */", applicability = "has-placeholders")]
#[suggestion(
"consider adding a trait bound after the potential lifetime bound",
code = " + /* Trait */",
applicability = "has-placeholders"
)]
pub suggestion: Span,
}
#[derive(Diagnostic)]
#[diag(parse_expected_mut_or_const_in_raw_pointer_type)]
#[diag("expected `mut` or `const` keyword in raw pointer type")]
pub(crate) struct ExpectedMutOrConstInRawPointerType {
#[primary_span]
pub span: Span,
#[suggestion(code("mut ", "const "), applicability = "has-placeholders", style = "verbose")]
#[suggestion(
"add `mut` or `const` here",
code("mut ", "const "),
applicability = "has-placeholders",
style = "verbose"
)]
pub after_asterisk: Span,
}
#[derive(Diagnostic)]
#[diag(parse_lifetime_after_mut)]
#[diag("lifetime must precede `mut`")]
pub(crate) struct LifetimeAfterMut {
#[primary_span]
pub span: Span,
#[suggestion(code = "&{snippet} mut", applicability = "maybe-incorrect", style = "verbose")]
#[suggestion(
"place the lifetime before `mut`",
code = "&{snippet} mut",
applicability = "maybe-incorrect",
style = "verbose"
)]
pub suggest_lifetime: Option<Span>,
pub snippet: String,
}
#[derive(Diagnostic)]
#[diag(parse_dyn_after_mut)]
#[diag("`mut` must precede `dyn`")]
pub(crate) struct DynAfterMut {
#[primary_span]
#[suggestion(code = "&mut dyn", applicability = "machine-applicable", style = "verbose")]
#[suggestion(
"place `mut` before `dyn`",
code = "&mut dyn",
applicability = "machine-applicable",
style = "verbose"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_fn_pointer_cannot_be_const)]
#[note]
#[diag("an `fn` pointer type cannot be `const`")]
#[note("allowed qualifiers are: `unsafe` and `extern`")]
pub(crate) struct FnPointerCannotBeConst {
#[primary_span]
#[label]
#[label("`const` because of this")]
pub span: Span,
#[suggestion(code = "", applicability = "maybe-incorrect", style = "verbose")]
#[suggestion(
"remove the `const` qualifier",
code = "",
applicability = "maybe-incorrect",
style = "verbose"
)]
pub suggestion: Span,
}
#[derive(Diagnostic)]
#[diag(parse_fn_pointer_cannot_be_async)]
#[note]
#[diag("an `fn` pointer type cannot be `async`")]
#[note("allowed qualifiers are: `unsafe` and `extern`")]
pub(crate) struct FnPointerCannotBeAsync {
#[primary_span]
#[label]
#[label("`async` because of this")]
pub span: Span,
#[suggestion(code = "", applicability = "maybe-incorrect", style = "verbose")]
#[suggestion(
"remove the `async` qualifier",
code = "",
applicability = "maybe-incorrect",
style = "verbose"
)]
pub suggestion: Span,
}
#[derive(Diagnostic)]
#[diag(parse_nested_c_variadic_type, code = E0743)]
#[diag("C-variadic type `...` may not be nested inside another type", code = E0743)]
pub(crate) struct NestedCVariadicType {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_dotdotdot_rest_type)]
#[note]
#[diag("unexpected `...`")]
#[note(
"only `extern \"C\"` and `extern \"C-unwind\"` functions may have a C variable argument list"
)]
pub(crate) struct InvalidCVariadicType {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_invalid_dyn_keyword)]
#[help]
#[diag("invalid `dyn` keyword")]
#[help("`dyn` is only needed at the start of a trait `+`-separated list")]
pub(crate) struct InvalidDynKeyword {
#[primary_span]
pub span: Span,
#[suggestion(code = "", applicability = "machine-applicable", style = "verbose")]
#[suggestion(
"remove this keyword",
code = "",
applicability = "machine-applicable",
style = "verbose"
)]
pub suggestion: Span,
}
#[derive(Subdiagnostic)]
pub(crate) enum HelpUseLatestEdition {
#[help(parse_help_set_edition_cargo)]
#[note(parse_note_edition_guide)]
#[help("set `edition = \"{$edition}\"` in `Cargo.toml`")]
#[note("for more on editions, read https://doc.rust-lang.org/edition-guide")]
Cargo { edition: Edition },
#[help(parse_help_set_edition_standalone)]
#[note(parse_note_edition_guide)]
#[help("pass `--edition {$edition}` to `rustc`")]
#[note("for more on editions, read https://doc.rust-lang.org/edition-guide")]
Standalone { edition: Edition },
}
@@ -3077,7 +3622,7 @@ pub(crate) fn new() -> Self {
}
#[derive(Diagnostic)]
#[diag(parse_box_syntax_removed)]
#[diag("`box_syntax` has been removed")]
pub(crate) struct BoxSyntaxRemoved {
#[primary_span]
pub span: Span,
@@ -3087,7 +3632,7 @@ pub(crate) struct BoxSyntaxRemoved {
#[derive(Subdiagnostic)]
#[multipart_suggestion(
parse_box_syntax_removed_suggestion,
"use `Box::new()` instead",
applicability = "machine-applicable",
style = "verbose"
)]
@@ -3099,65 +3644,70 @@ pub(crate) struct AddBoxNew {
}
#[derive(Diagnostic)]
#[diag(parse_bad_return_type_notation_output)]
#[diag("return type not allowed with return type notation")]
pub(crate) struct BadReturnTypeNotationOutput {
#[primary_span]
pub span: Span,
#[suggestion(code = "", applicability = "maybe-incorrect", style = "verbose")]
#[suggestion(
"remove the return type",
code = "",
applicability = "maybe-incorrect",
style = "verbose"
)]
pub suggestion: Span,
}
#[derive(Diagnostic)]
#[diag(parse_bad_assoc_type_bounds)]
#[diag("bounds on associated types do not belong here")]
pub(crate) struct BadAssocTypeBounds {
#[primary_span]
#[label]
#[label("belongs in `where` clause")]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_attr_after_generic)]
#[diag("trailing attribute after generic parameter")]
pub(crate) struct AttrAfterGeneric {
#[primary_span]
#[label]
#[label("attributes must go before parameters")]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_attr_without_generics)]
#[diag("attribute without generic parameters")]
pub(crate) struct AttrWithoutGenerics {
#[primary_span]
#[label]
#[label("attributes are only permitted when preceding parameters")]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_where_generics)]
#[diag("generic parameters on `where` clauses are reserved for future use")]
pub(crate) struct WhereOnGenerics {
#[primary_span]
#[label]
#[label("currently unsupported")]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_generics_in_path)]
#[diag("unexpected generic arguments in path")]
pub(crate) struct GenericsInPath {
#[primary_span]
pub span: Vec<Span>,
}
#[derive(Diagnostic)]
#[diag(parse_lifetime_in_eq_constraint)]
#[help]
#[diag("lifetimes are not permitted in this context")]
#[help("if you meant to specify a trait object, write `dyn /* Trait */ + {$lifetime}`")]
pub(crate) struct LifetimeInEqConstraint {
#[primary_span]
#[label]
#[label("lifetime is not allowed here")]
pub span: Span,
pub lifetime: Ident,
#[label(parse_context_label)]
#[label("this introduces an associated item binding")]
pub binding_label: Span,
#[suggestion(
parse_colon_sugg,
"you might have meant to write a bound here",
style = "verbose",
applicability = "maybe-incorrect",
code = ": "
@@ -3166,119 +3716,159 @@ pub(crate) struct LifetimeInEqConstraint {
}
#[derive(Diagnostic)]
#[diag(parse_modifier_lifetime)]
#[diag("`{$modifier}` may only modify trait bounds, not lifetime bounds")]
pub(crate) struct ModifierLifetime {
#[primary_span]
#[suggestion(style = "tool-only", applicability = "maybe-incorrect", code = "")]
#[suggestion(
"remove the `{$modifier}`",
style = "tool-only",
applicability = "maybe-incorrect",
code = ""
)]
pub span: Span,
pub modifier: &'static str,
}
#[derive(Diagnostic)]
#[diag(parse_underscore_literal_suffix)]
#[diag("underscore literal suffix is not allowed")]
pub(crate) struct UnderscoreLiteralSuffix {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_expect_label_found_ident)]
#[diag("expected a label, found an identifier")]
pub(crate) struct ExpectedLabelFoundIdent {
#[primary_span]
pub span: Span,
#[suggestion(code = "'", applicability = "machine-applicable", style = "verbose")]
#[suggestion(
"labels start with a tick",
code = "'",
applicability = "machine-applicable",
style = "verbose"
)]
pub start: Span,
}
#[derive(Diagnostic)]
#[diag(parse_inappropriate_default)]
#[note]
#[diag("{$article} {$descr} cannot be `default`")]
#[note("only associated `fn`, `const`, and `type` items can be `default`")]
pub(crate) struct InappropriateDefault {
#[primary_span]
#[label]
#[label("`default` because of this")]
pub span: Span,
pub article: &'static str,
pub descr: &'static str,
}
#[derive(Diagnostic)]
#[diag(parse_recover_import_as_use)]
#[diag("expected item, found {$token_name}")]
pub(crate) struct RecoverImportAsUse {
#[primary_span]
#[suggestion(code = "use", applicability = "machine-applicable", style = "verbose")]
#[suggestion(
"items are imported using the `use` keyword",
code = "use",
applicability = "machine-applicable",
style = "verbose"
)]
pub span: Span,
pub token_name: String,
}
#[derive(Diagnostic)]
#[diag(parse_single_colon_import_path)]
#[note]
#[diag("expected `::`, found `:`")]
#[note("import paths are delimited using `::`")]
pub(crate) struct SingleColonImportPath {
#[primary_span]
#[suggestion(code = "::", applicability = "machine-applicable", style = "verbose")]
#[suggestion(
"use double colon",
code = "::",
applicability = "machine-applicable",
style = "verbose"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_bad_item_kind)]
#[diag("{$descr} is not supported in {$ctx}")]
pub(crate) struct BadItemKind {
#[primary_span]
pub span: Span,
pub descr: &'static str,
pub ctx: &'static str,
#[help]
#[help("consider moving the {$descr} out to a nearby module scope")]
pub help: bool,
}
#[derive(Diagnostic)]
#[diag(parse_macro_rules_missing_bang)]
#[diag("expected `!` after `macro_rules`")]
pub(crate) struct MacroRulesMissingBang {
#[primary_span]
pub span: Span,
#[suggestion(code = "!", applicability = "machine-applicable", style = "verbose")]
#[suggestion("add a `!`", code = "!", applicability = "machine-applicable", style = "verbose")]
pub hi: Span,
}
#[derive(Diagnostic)]
#[diag(parse_macro_name_remove_bang)]
#[diag("macro names aren't followed by a `!`")]
pub(crate) struct MacroNameRemoveBang {
#[primary_span]
#[suggestion(code = "", applicability = "machine-applicable", style = "short")]
#[suggestion(
"remove the `!`",
code = "",
applicability = "machine-applicable",
style = "short"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_macro_rules_visibility)]
#[diag("can't qualify macro_rules invocation with `{$vis}`")]
pub(crate) struct MacroRulesVisibility<'a> {
#[primary_span]
#[suggestion(code = "#[macro_export]", applicability = "maybe-incorrect", style = "verbose")]
#[suggestion(
"try exporting the macro",
code = "#[macro_export]",
applicability = "maybe-incorrect",
style = "verbose"
)]
pub span: Span,
pub vis: &'a str,
}
#[derive(Diagnostic)]
#[diag(parse_macro_invocation_visibility)]
#[help]
#[diag("can't qualify macro invocation with `pub`")]
#[help("try adjusting the macro to put `{$vis}` inside the invocation")]
pub(crate) struct MacroInvocationVisibility<'a> {
#[primary_span]
#[suggestion(code = "", applicability = "machine-applicable", style = "verbose")]
#[suggestion(
"remove the visibility",
code = "",
applicability = "machine-applicable",
style = "verbose"
)]
pub span: Span,
pub vis: &'a str,
}
#[derive(Diagnostic)]
#[diag(parse_nested_adt)]
#[diag("`{$kw_str}` definition cannot be nested inside `{$keyword}`")]
pub(crate) struct NestedAdt<'a> {
#[primary_span]
pub span: Span,
#[suggestion(code = "", applicability = "maybe-incorrect", style = "verbose")]
#[suggestion(
"consider creating a new `{$kw_str}` definition instead of nesting",
code = "",
applicability = "maybe-incorrect",
style = "verbose"
)]
pub item: Span,
pub keyword: &'a str,
pub kw_str: Cow<'a, str>,
}
#[derive(Diagnostic)]
#[diag(parse_function_body_equals_expr)]
#[diag("function body cannot be `= expression;`")]
pub(crate) struct FunctionBodyEqualsExpr {
#[primary_span]
pub span: Span,
@@ -3287,7 +3877,10 @@ pub(crate) struct FunctionBodyEqualsExpr {
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(parse_suggestion, applicability = "machine-applicable")]
#[multipart_suggestion(
r#"surround the expression with `{"{"}` and `{"}"}` instead of `=` and `;`"#,
applicability = "machine-applicable"
)]
pub(crate) struct FunctionBodyEqualsExprSugg {
#[suggestion_part(code = "{{")]
pub eq: Span,
@@ -3296,38 +3889,56 @@ pub(crate) struct FunctionBodyEqualsExprSugg {
}
#[derive(Diagnostic)]
#[diag(parse_box_not_pat)]
#[diag("expected pattern, found {$descr}")]
pub(crate) struct BoxNotPat {
#[primary_span]
pub span: Span,
#[note]
#[note("`box` is a reserved keyword")]
pub kw: Span,
#[suggestion(code = "r#", applicability = "maybe-incorrect", style = "verbose")]
#[suggestion(
"escape `box` to use it as an identifier",
code = "r#",
applicability = "maybe-incorrect",
style = "verbose"
)]
pub lo: Span,
pub descr: String,
}
#[derive(Diagnostic)]
#[diag(parse_unmatched_angle)]
#[diag(
"unmatched angle {$plural ->
[true] brackets
*[false] bracket
}"
)]
pub(crate) struct UnmatchedAngle {
#[primary_span]
#[suggestion(code = "", applicability = "machine-applicable", style = "verbose")]
#[suggestion(
"remove extra angle {$plural ->
[true] brackets
*[false] bracket
}",
code = "",
applicability = "machine-applicable",
style = "verbose"
)]
pub span: Span,
pub plural: bool,
}
#[derive(Diagnostic)]
#[diag(parse_missing_plus_in_bounds)]
#[diag("expected `+` between lifetime and {$sym}")]
pub(crate) struct MissingPlusBounds {
#[primary_span]
pub span: Span,
#[suggestion(code = " +", applicability = "maybe-incorrect", style = "verbose")]
#[suggestion("add `+`", code = " +", applicability = "maybe-incorrect", style = "verbose")]
pub hi: Span,
pub sym: Symbol,
}
#[derive(Diagnostic)]
#[diag(parse_incorrect_parens_trait_bounds)]
#[diag("incorrect parentheses around trait bounds")]
pub(crate) struct IncorrectParensTraitBounds {
#[primary_span]
pub span: Vec<Span>,
@@ -3336,10 +3947,7 @@ pub(crate) struct IncorrectParensTraitBounds {
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(
parse_incorrect_parens_trait_bounds_sugg,
applicability = "machine-applicable"
)]
#[multipart_suggestion("fix the parentheses", applicability = "machine-applicable")]
pub(crate) struct IncorrectParensTraitBoundsSugg {
#[suggestion_part(code = " ")]
pub wrong_span: Span,
@@ -3348,10 +3956,15 @@ pub(crate) struct IncorrectParensTraitBoundsSugg {
}
#[derive(Diagnostic)]
#[diag(parse_kw_bad_case)]
#[diag("keyword `{$kw}` is written in the wrong case")]
pub(crate) struct KwBadCase<'a> {
#[primary_span]
#[suggestion(code = "{kw}", style = "verbose", applicability = "machine-applicable")]
#[suggestion(
"write it in {$case}",
code = "{kw}",
style = "verbose",
applicability = "machine-applicable"
)]
pub span: Span,
pub kw: &'a str,
pub case: Case,
@@ -3375,7 +3988,7 @@ fn into_diag_arg(self, path: &mut Option<PathBuf>) -> DiagArgValue {
}
#[derive(Diagnostic)]
#[diag(parse_unknown_builtin_construct)]
#[diag("unknown `builtin #` construct `{$name}`")]
pub(crate) struct UnknownBuiltinConstruct {
#[primary_span]
pub span: Span,
@@ -3383,35 +3996,38 @@ pub(crate) struct UnknownBuiltinConstruct {
}
#[derive(Diagnostic)]
#[diag(parse_expected_builtin_ident)]
#[diag("expected identifier after `builtin #`")]
pub(crate) struct ExpectedBuiltinIdent {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_static_with_generics)]
#[diag("static items may not have generic parameters")]
pub(crate) struct StaticWithGenerics {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_where_clause_before_const_body)]
#[diag("where clauses are not allowed before const item bodies")]
pub(crate) struct WhereClauseBeforeConstBody {
#[primary_span]
#[label]
#[label("unexpected where clause")]
pub span: Span,
#[label(parse_name_label)]
#[label("while parsing this const item")]
pub name: Span,
#[label(parse_body_label)]
#[label("the item body")]
pub body: Span,
#[subdiagnostic]
pub sugg: Option<WhereClauseBeforeConstBodySugg>,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(parse_suggestion, applicability = "machine-applicable")]
#[multipart_suggestion(
"move the body before the where clause",
applicability = "machine-applicable"
)]
pub(crate) struct WhereClauseBeforeConstBodySugg {
#[suggestion_part(code = "= {snippet} ")]
pub left: Span,
@@ -3421,12 +4037,12 @@ pub(crate) struct WhereClauseBeforeConstBodySugg {
}
#[derive(Diagnostic)]
#[diag(parse_generic_args_in_pat_require_turbofish_syntax)]
#[diag("generic args in patterns require the turbofish syntax")]
pub(crate) struct GenericArgsInPatRequireTurbofishSyntax {
#[primary_span]
pub span: Span,
#[suggestion(
parse_sugg_turbofish_syntax,
"use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments",
style = "verbose",
code = "::",
applicability = "maybe-incorrect"
@@ -3435,7 +4051,7 @@ pub(crate) struct GenericArgsInPatRequireTurbofishSyntax {
}
#[derive(Diagnostic)]
#[diag(parse_transpose_dyn_or_impl)]
#[diag("`for<...>` expected after `{$kw}`, not before")]
pub(crate) struct TransposeDynOrImpl<'a> {
#[primary_span]
pub span: Span,
@@ -3445,7 +4061,7 @@ pub(crate) struct TransposeDynOrImpl<'a> {
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(parse_suggestion, applicability = "machine-applicable")]
#[multipart_suggestion("move `{$kw}` before the `for<...>`", applicability = "machine-applicable")]
pub(crate) struct TransposeDynOrImplSugg<'a> {
#[suggestion_part(code = "")]
pub removal_span: Span,
@@ -3455,68 +4071,77 @@ pub(crate) struct TransposeDynOrImplSugg<'a> {
}
#[derive(Diagnostic)]
#[diag(parse_array_index_offset_of)]
#[diag("array indexing not supported in offset_of")]
pub(crate) struct ArrayIndexInOffsetOf(#[primary_span] pub Span);
#[derive(Diagnostic)]
#[diag(parse_invalid_offset_of)]
#[diag("offset_of expects dot-separated field and variant names")]
pub(crate) struct InvalidOffsetOf(#[primary_span] pub Span);
#[derive(Diagnostic)]
#[diag(parse_async_impl)]
#[diag("`async` trait implementations are unsupported")]
pub(crate) struct AsyncImpl {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_expr_rarrow_call)]
#[help]
#[diag("`->` is not valid syntax for field accesses and method calls")]
#[help(
"the `.` operator will automatically dereference the value, except if the value is a raw pointer"
)]
pub(crate) struct ExprRArrowCall {
#[primary_span]
#[suggestion(style = "verbose", applicability = "machine-applicable", code = ".")]
#[suggestion(
"try using `.` instead",
style = "verbose",
applicability = "machine-applicable",
code = "."
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_dot_dot_range_attribute)]
#[diag("attributes are not allowed on range expressions starting with `..`")]
pub(crate) struct DotDotRangeAttribute {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_binder_before_modifiers)]
#[diag("`for<...>` binder should be placed before trait bound modifiers")]
pub(crate) struct BinderBeforeModifiers {
#[primary_span]
pub binder_span: Span,
#[label]
#[label("place the `for<...>` binder before any modifiers")]
pub modifiers_span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_binder_and_polarity)]
#[diag("`for<...>` binder not allowed with `{$polarity}` trait polarity modifier")]
pub(crate) struct BinderAndPolarity {
#[primary_span]
pub polarity_span: Span,
#[label]
#[label("there is not a well-defined meaning for a higher-ranked `{$polarity}` trait")]
pub binder_span: Span,
pub polarity: &'static str,
}
#[derive(Diagnostic)]
#[diag(parse_modifiers_and_polarity)]
#[diag("`{$modifiers_concatenated}` trait not allowed with `{$polarity}` trait polarity modifier")]
pub(crate) struct PolarityAndModifiers {
#[primary_span]
pub polarity_span: Span,
#[label]
#[label(
"there is not a well-defined meaning for a `{$modifiers_concatenated} {$polarity}` trait"
)]
pub modifiers_span: Span,
pub polarity: &'static str,
pub modifiers_concatenated: String,
}
#[derive(Diagnostic)]
#[diag(parse_incorrect_type_on_self)]
#[diag("type not allowed for shorthand `self` parameter")]
pub(crate) struct IncorrectTypeOnSelf {
#[primary_span]
pub span: Span,
@@ -3525,7 +4150,10 @@ pub(crate) struct IncorrectTypeOnSelf {
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(parse_suggestion, applicability = "machine-applicable")]
#[multipart_suggestion(
"move the modifiers on `self` to the type",
applicability = "machine-applicable"
)]
pub(crate) struct MoveSelfModifier {
#[suggestion_part(code = "")]
pub removal_span: Span,
@@ -3535,82 +4163,104 @@ pub(crate) struct MoveSelfModifier {
}
#[derive(Diagnostic)]
#[diag(parse_asm_unsupported_operand)]
#[diag("the `{$symbol}` operand cannot be used with `{$macro_name}!`")]
pub(crate) struct AsmUnsupportedOperand<'a> {
#[primary_span]
#[label]
#[label(
"the `{$symbol}` operand is not meaningful for global-scoped inline assembly, remove it"
)]
pub(crate) span: Span,
pub(crate) symbol: &'a str,
pub(crate) macro_name: &'static str,
}
#[derive(Diagnostic)]
#[diag(parse_asm_underscore_input)]
#[diag("_ cannot be used for input operands")]
pub(crate) struct AsmUnderscoreInput {
#[primary_span]
pub(crate) span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_asm_sym_no_path)]
#[diag("expected a path for argument to `sym`")]
pub(crate) struct AsmSymNoPath {
#[primary_span]
pub(crate) span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_asm_requires_template)]
#[diag("requires at least a template string argument")]
pub(crate) struct AsmRequiresTemplate {
#[primary_span]
pub(crate) span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_asm_expected_comma)]
#[diag("expected token: `,`")]
pub(crate) struct AsmExpectedComma {
#[primary_span]
#[label]
#[label("expected `,`")]
pub(crate) span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_asm_expected_other)]
#[diag(
"expected operand, {$is_inline_asm ->
[false] options
*[true] clobber_abi, options
}, or additional template string"
)]
pub(crate) struct AsmExpectedOther {
#[primary_span]
#[label(parse_asm_expected_other)]
#[label(
"expected operand, {$is_inline_asm ->
[false] options
*[true] clobber_abi, options
}, or additional template string"
)]
pub(crate) span: Span,
pub(crate) is_inline_asm: bool,
}
#[derive(Diagnostic)]
#[diag(parse_asm_non_abi)]
#[diag("at least one abi must be provided as an argument to `clobber_abi`")]
pub(crate) struct NonABI {
#[primary_span]
pub(crate) span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_asm_expected_string_literal)]
#[diag("expected string literal")]
pub(crate) struct AsmExpectedStringLiteral {
#[primary_span]
#[label]
#[label("not a string literal")]
pub(crate) span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_asm_expected_register_class_or_explicit_register)]
#[diag("expected register class or explicit register")]
pub(crate) struct ExpectedRegisterClassOrExplicitRegister {
#[primary_span]
pub(crate) span: Span,
}
#[derive(LintDiagnostic)]
#[diag(parse_hidden_unicode_codepoints)]
#[note]
#[diag("unicode codepoint changing visible direction of text present in {$label}")]
#[note(
"these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen"
)]
pub(crate) struct HiddenUnicodeCodepointsDiag {
pub label: String,
pub count: usize,
#[label]
#[label(
"this {$label} contains {$count ->
[one] an invisible
*[other] invisible
} unicode text flow control {$count ->
[one] codepoint
*[other] codepoints
}"
)]
pub span_label: Span,
#[subdiagnostic]
pub labels: Option<HiddenUnicodeCodepointsDiagLabels>,
@@ -3641,13 +4291,13 @@ fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
match self {
HiddenUnicodeCodepointsDiagSub::Escape { spans } => {
diag.multipart_suggestion_with_style(
fluent::parse_suggestion_remove,
inline_fluent!("if their presence wasn't intentional, you can remove them"),
spans.iter().map(|(_, span)| (*span, "".to_string())).collect(),
Applicability::MachineApplicable,
SuggestionStyle::HideCodeAlways,
);
diag.multipart_suggestion(
fluent::parse_suggestion_escape,
inline_fluent!("if you want to keep them but make them visible in your source code, you can escape them"),
spans
.into_iter()
.map(|(c, span)| {
@@ -3670,43 +4320,59 @@ fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
.collect::<Vec<String>>()
.join(", "),
);
diag.note(fluent::parse_suggestion_remove);
diag.note(fluent::parse_no_suggestion_note_escape);
diag.note(inline_fluent!(
"if their presence wasn't intentional, you can remove them"
));
diag.note(inline_fluent!("if you want to keep them but make them visible in your source code, you can escape them: {$escaped}"));
}
}
}
}
#[derive(LintDiagnostic)]
#[diag(parse_varargs_without_pattern)]
#[diag("missing pattern for `...` argument")]
pub(crate) struct VarargsWithoutPattern {
#[suggestion(code = "_: ...", applicability = "machine-applicable")]
#[suggestion(
"name the argument, or use `_` to continue ignoring it",
code = "_: ...",
applicability = "machine-applicable"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_delegation_non_trait_impl_reuse)]
#[diag("only trait impls can be reused")]
pub(crate) struct ImplReuseInherentImpl {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_struct_literal_placeholder_path)]
#[diag("placeholder `_` is not allowed for the path in struct literals")]
pub(crate) struct StructLiteralPlaceholderPath {
#[primary_span]
#[label]
#[suggestion(applicability = "has-placeholders", code = "/* Type */", style = "verbose")]
#[label("not allowed in struct literals")]
#[suggestion(
"replace it with the correct type",
applicability = "has-placeholders",
code = "/* Type */",
style = "verbose"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_struct_literal_body_without_path_late)]
#[diag("struct literal body without path")]
pub(crate) struct StructLiteralWithoutPathLate {
#[primary_span]
#[label]
#[label("struct name missing for struct literal")]
pub span: Span,
#[suggestion(applicability = "has-placeholders", code = "/* Type */ ", style = "verbose")]
#[suggestion(
"add the correct type",
applicability = "has-placeholders",
code = "/* Type */ ",
style = "verbose"
)]
pub suggestion_span: Span,
}
@@ -3716,19 +4382,22 @@ pub(crate) enum ForbiddenLetReason {
/// `let` is not valid and the source environment is not important
OtherForbidden,
/// A let chain with the `||` operator
#[note(parse_not_supported_or)]
#[note("`||` operators are not supported in let chain expressions")]
NotSupportedOr(#[primary_span] Span),
/// A let chain with invalid parentheses
///
/// For example, `let 1 = 1 && (expr && expr)` is allowed
/// but `(let 1 = 1 && (let 1 = 1 && (let 1 = 1))) && let a = 1` is not
#[note(parse_not_supported_parentheses)]
#[note("`let`s wrapped in parentheses are not supported in a context with let chains")]
NotSupportedParentheses(#[primary_span] Span),
}
#[derive(Debug, rustc_macros::Subdiagnostic)]
#[suggestion(
parse_misspelled_kw,
"{$is_incorrect_case ->
[true] write keyword `{$similar_kw}` in lowercase
*[false] there is a keyword `{$similar_kw}` with a similar name
}",
applicability = "machine-applicable",
code = "{similar_kw}",
style = "verbose"
-2
View File
@@ -75,8 +75,6 @@
}
};
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
// Unwrap the result if `Ok`, otherwise emit the diagnostics and abort.
pub fn unwrap_or_emit_fatal<T>(expr: Result<T, Vec<Diag<'_>>>) -> T {
match expr {
+49 -19
View File
@@ -3,7 +3,7 @@
use rustc_ast::tokenstream::ParserRange;
use rustc_ast::{AttrItemKind, Attribute, attr};
use rustc_errors::codes::*;
use rustc_errors::{Diag, PResult};
use rustc_errors::{Diag, PResult, inline_fluent};
use rustc_span::{BytePos, Span};
use thin_vec::ThinVec;
use tracing::debug;
@@ -13,7 +13,7 @@
Trailing, UsePreAttrPos,
};
use crate::parser::FnContext;
use crate::{errors, exp, fluent_generated as fluent};
use crate::{errors, exp};
// Public for rustfmt usage
#[derive(Debug)]
@@ -68,7 +68,7 @@ pub(super) fn parse_outer_attributes(&mut self) -> PResult<'a, AttrWrapper> {
let span = self.token.span;
let mut err = self
.dcx()
.struct_span_err(span, fluent::parse_inner_doc_comment_not_permitted);
.struct_span_err(span, inline_fluent!("expected outer doc comment"));
err.code(E0753);
if let Some(replacement_span) = self.annotate_following_item_if_applicable(
&mut err,
@@ -79,10 +79,12 @@ pub(super) fn parse_outer_attributes(&mut self) -> PResult<'a, AttrWrapper> {
},
true,
) {
err.note(fluent::parse_note);
err.note(inline_fluent!(
"inner doc comments like this (starting with `//!` or `/*!`) can only appear before items"
));
err.span_suggestion_verbose(
replacement_span,
fluent::parse_suggestion,
inline_fluent!("you might have meant to write a regular comment"),
"",
rustc_errors::Applicability::MachineApplicable,
);
@@ -207,13 +209,25 @@ fn annotate_following_item_if_applicable(
AllowConstBlockItems::Yes,
) {
Ok(Some(item)) => {
// FIXME(#100717)
err.arg("item", item.kind.descr());
err.span_label(item.span, fluent::parse_label_does_not_annotate_this);
err.span_label(
item.span,
match attr_type {
OuterAttributeType::Attribute => {
inline_fluent!("the inner attribute doesn't annotate this {$item}")
}
OuterAttributeType::DocComment | OuterAttributeType::DocBlockComment => {
inline_fluent!("the inner doc comment doesn't annotate this {$item}")
}
},
);
if suggest_to_outer {
err.span_suggestion_verbose(
replacement_span,
fluent::parse_sugg_change_inner_to_outer,
match attr_type {
OuterAttributeType::Attribute => inline_fluent!("to annotate the {$item}, change the attribute from inner to outer style"),
OuterAttributeType::DocComment | OuterAttributeType::DocBlockComment => inline_fluent!("to annotate the {$item}, change the doc comment from inner to outer style"),
},
match attr_type {
OuterAttributeType::Attribute => "",
OuterAttributeType::DocBlockComment => "*",
@@ -244,28 +258,42 @@ pub(super) fn error_on_forbidden_inner_attr(
self.dcx()
.struct_span_err(
attr_sp,
fluent::parse_inner_attr_not_permitted_after_outer_doc_comment,
inline_fluent!(
"an inner attribute is not permitted following an outer doc comment"
),
)
.with_span_label(
attr_sp,
inline_fluent!("not permitted following an outer doc comment"),
)
.with_span_label(attr_sp, fluent::parse_label_attr)
.with_span_label(
prev_doc_comment_span,
fluent::parse_label_prev_doc_comment,
inline_fluent!("previous doc comment"),
)
}
Some(InnerAttrForbiddenReason::AfterOuterAttribute { prev_outer_attr_sp }) => self
.dcx()
.struct_span_err(
attr_sp,
fluent::parse_inner_attr_not_permitted_after_outer_attr,
inline_fluent!(
"an inner attribute is not permitted following an outer attribute"
),
)
.with_span_label(attr_sp, fluent::parse_label_attr)
.with_span_label(prev_outer_attr_sp, fluent::parse_label_prev_attr),
Some(InnerAttrForbiddenReason::InCodeBlock) | None => {
self.dcx().struct_span_err(attr_sp, fluent::parse_inner_attr_not_permitted)
}
.with_span_label(
attr_sp,
inline_fluent!("not permitted following an outer attribute"),
)
.with_span_label(
prev_outer_attr_sp,
inline_fluent!("previous outer attribute"),
),
Some(InnerAttrForbiddenReason::InCodeBlock) | None => self.dcx().struct_span_err(
attr_sp,
inline_fluent!("an inner attribute is not permitted in this context"),
),
};
diag.note(fluent::parse_inner_attr_explanation);
diag.note(inline_fluent!("inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files"));
if self
.annotate_following_item_if_applicable(
&mut diag,
@@ -275,7 +303,9 @@ pub(super) fn error_on_forbidden_inner_attr(
)
.is_some()
{
diag.note(fluent::parse_outer_attr_explanation);
diag.note(inline_fluent!(
"outer attributes, like `#[test]`, annotate the item following them"
));
};
diag.emit();
}
@@ -13,7 +13,7 @@
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{
Applicability, Diag, DiagCtxtHandle, ErrorGuaranteed, PResult, Subdiagnostic, Suggestions,
pluralize,
inline_fluent, pluralize,
};
use rustc_session::errors::ExprParenthesesNeeded;
use rustc_span::source_map::Spanned;
@@ -41,10 +41,10 @@
TernaryOperatorSuggestion, UnexpectedConstInGenericParam, UnexpectedConstParamDeclaration,
UnexpectedConstParamDeclarationSugg, UnmatchedAngleBrackets, UseEqInstead, WrapType,
};
use crate::exp;
use crate::parser::FnContext;
use crate::parser::attr::InnerAttrPolicy;
use crate::parser::item::IsDotDotDot;
use crate::{exp, fluent_generated as fluent};
/// Creates a placeholder argument.
pub(super) fn dummy_arg(ident: Ident, guar: ErrorGuaranteed) -> Param {
@@ -1272,7 +1272,7 @@ pub(super) fn check_mistyped_turbofish_with_multiple_type_params(
// We made sense of it. Improve the error message.
e.span_suggestion_verbose(
binop.span.shrink_to_lo(),
fluent::parse_sugg_turbofish_syntax,
inline_fluent!("use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments"),
"::",
Applicability::MaybeIncorrect,
);
+8 -7
View File
@@ -727,25 +727,26 @@ fn parse_assoc_op_cast(
);
let args_span = self.look_ahead(1, |t| t.span).to(span_after_type);
let suggestion = errors::ComparisonOrShiftInterpretedAsGenericSugg {
left: expr.span.shrink_to_lo(),
right: expr.span.shrink_to_hi(),
};
match self.token.kind {
token::Lt => {
self.dcx().emit_err(errors::ComparisonInterpretedAsGeneric {
comparison: self.token.span,
r#type: path,
args: args_span,
suggestion,
suggestion: errors::ComparisonInterpretedAsGenericSugg {
left: expr.span.shrink_to_lo(),
right: expr.span.shrink_to_hi(),
},
})
}
token::Shl => self.dcx().emit_err(errors::ShiftInterpretedAsGeneric {
shift: self.token.span,
r#type: path,
args: args_span,
suggestion,
suggestion: errors::ShiftInterpretedAsGenericSugg {
left: expr.span.shrink_to_lo(),
right: expr.span.shrink_to_hi(),
},
}),
_ => {
// We can end up here even without `<` being the next token, for
+3 -3
View File
@@ -11,7 +11,7 @@
};
use rustc_ast_pretty::pprust;
use rustc_errors::codes::*;
use rustc_errors::{Applicability, PResult, StashKey, struct_span_code_err};
use rustc_errors::{Applicability, PResult, StashKey, inline_fluent, struct_span_code_err};
use rustc_session::lint::builtin::VARARGS_WITHOUT_PATTERN;
use rustc_span::edit_distance::edit_distance;
use rustc_span::edition::Edition;
@@ -26,7 +26,7 @@
Parser, PathStyle, Recovered, Trailing, UsePreAttrPos,
};
use crate::errors::{self, FnPointerCannotBeAsync, FnPointerCannotBeConst, MacroExpandsToAdtField};
use crate::{exp, fluent_generated as fluent};
use crate::exp;
impl<'a> Parser<'a> {
/// Parses a source module as a crate. This is the main entry point for the parser.
@@ -1721,7 +1721,7 @@ fn parse_enum_variant(&mut self, span: Span) -> PResult<'a, Option<Variant>> {
if this.token == token::Bang {
if let Err(err) = this.unexpected() {
err.with_note(fluent::parse_macro_expands_to_enum_variant).emit();
err.with_note(inline_fluent!("macros cannot expand to enum variants")).emit();
}
this.bump();
+10 -14
View File
@@ -25,10 +25,6 @@
use crate::parser::{AllowConstBlockItems, ForceCollect, Parser};
use crate::{new_parser_from_source_str, source_str_to_stream, unwrap_or_emit_fatal};
fn psess() -> ParseSess {
ParseSess::new(vec![crate::DEFAULT_LOCALE_RESOURCE])
}
fn filename(sm: &SourceMap, path: &str) -> FileName {
FileName::Real(sm.path_mapping().to_real_filename(sm.working_dir(), PathBuf::from(path)))
}
@@ -46,7 +42,7 @@ fn string_to_parser(psess: &ParseSess, source_str: String) -> Parser<'_> {
fn create_test_handler(theme: OutputTheme) -> (DiagCtxt, Arc<SourceMap>, Arc<Mutex<Vec<u8>>>) {
let output = Arc::new(Mutex::new(Vec::new()));
let source_map = Arc::new(SourceMap::new(FilePathMapping::empty()));
let translator = Translator::with_fallback_bundle(vec![crate::DEFAULT_LOCALE_RESOURCE], false);
let translator = Translator::with_fallback_bundle(vec![], false);
let shared: Box<dyn Write + Send> = Box::new(Shared { data: output.clone() });
let auto_stream = AutoStream::never(shared);
let dcx = DiagCtxt::new(Box::new(
@@ -93,7 +89,7 @@ fn with_expected_parse_error<T, F>(source_str: &str, expected_output: &str, f: F
/// Maps a string to tts, using a made-up filename.
pub(crate) fn string_to_stream(source_str: String) -> TokenStream {
let psess = psess();
let psess = ParseSess::new(vec![]);
unwrap_or_emit_fatal(source_str_to_stream(
&psess,
filename(psess.source_map(), "bogofile"),
@@ -2243,12 +2239,12 @@ fn sp(a: u32, b: u32) -> Span {
/// Parses a string, return an expression.
fn string_to_expr(source_str: String) -> Box<ast::Expr> {
with_error_checking_parse(source_str, &psess(), |p| p.parse_expr())
with_error_checking_parse(source_str, &ParseSess::new(vec![]), |p| p.parse_expr())
}
/// Parses a string, returns an item.
fn string_to_item(source_str: String) -> Option<Box<ast::Item>> {
with_error_checking_parse(source_str, &psess(), |p| {
with_error_checking_parse(source_str, &ParseSess::new(vec![]), |p| {
p.parse_item(ForceCollect::No, AllowConstBlockItems::Yes)
})
}
@@ -2484,7 +2480,7 @@ fn wb() -> c_int { O_WRONLY as c_int }
#[test]
fn crlf_doc_comments() {
create_default_session_globals_then(|| {
let psess = psess();
let psess = ParseSess::new(vec![]);
let name_1 = FileName::Custom("crlf_source_1".to_string());
let source = "/// doc comment\r\nfn foo() {}".to_string();
@@ -2519,7 +2515,7 @@ fn parse_expr_from_source_str(
}
create_default_session_globals_then(|| {
let psess = psess();
let psess = ParseSess::new(vec![]);
let expr = parse_expr_from_source_str(
filename(psess.source_map(), "foo"),
"foo!( fn main() { body } )".to_string(),
@@ -2555,7 +2551,7 @@ fn look_ahead() {
let sym_S = Symbol::intern("S");
let raw_no = IdentIsRaw::No;
let psess = psess();
let psess = ParseSess::new(vec![]);
let mut p = string_to_parser(&psess, "fn f(x: u32) { x } struct S;".to_string());
// Current position is the `fn`.
@@ -2630,7 +2626,7 @@ fn look_ahead_non_outermost_stream() {
let sym_S = Symbol::intern("S");
let raw_no = IdentIsRaw::No;
let psess = psess();
let psess = ParseSess::new(vec![]);
let mut p = string_to_parser(&psess, "mod m { fn f(x: u32) { x } struct S; }".to_string());
// Move forward to the `fn`, which is not within the outermost token
@@ -2662,7 +2658,7 @@ fn look_ahead_non_outermost_stream() {
#[test]
fn debug_lookahead() {
create_default_session_globals_then(|| {
let psess = psess();
let psess = ParseSess::new(vec![]);
let mut p = string_to_parser(&psess, "fn f(x: u32) { x } struct S;".to_string());
// Current position is the `fn`.
@@ -2883,7 +2879,7 @@ fn debug_lookahead() {
#[test]
fn out_of_line_mod() {
create_default_session_globals_then(|| {
let psess = psess();
let psess = ParseSess::new(vec![]);
let item = parse_item_from_source_str(
filename(psess.source_map(), "foo"),
"mod foo { struct S; mod this_does_not_exist; }".to_owned(),
+2 -2
View File
@@ -313,8 +313,8 @@ pub fn with_dcx(dcx: DiagCtxt, source_map: Arc<SourceMap>) -> Self {
}
}
pub fn emitter_with_note(locale_resources: Vec<&'static str>, note: String) -> Self {
let translator = Translator::with_fallback_bundle(locale_resources, false);
pub fn emitter_with_note(note: String) -> Self {
let translator = Translator::with_fallback_bundle(vec![], false);
let sm = Arc::new(SourceMap::new(FilePathMapping::empty()));
let emitter = Box::new(AnnotateSnippetEmitter::new(
stderr_destination(ColorConfig::Auto),
+3
View File
@@ -10,6 +10,9 @@
//@ needs-symlink
//@ needs-subprocess
// FIXME(151366) Currently `-Ztranslate-additional-ftl` is currently broken
//@ ignore-test
#![deny(warnings)]
use std::path::{Path, PathBuf};
@@ -29,7 +29,7 @@ pub fn main() {
}
fn parse() {
let psess = ParseSess::new(vec![rustc_parse::DEFAULT_LOCALE_RESOURCE]);
let psess = ParseSess::new(vec![]);
let path = Path::new(file!());
let path = path.canonicalize().unwrap();
+1 -1
View File
@@ -219,7 +219,7 @@ fn main() {
}
fn run() {
let psess = ParseSess::new(vec![rustc_parse::DEFAULT_LOCALE_RESOURCE]);
let psess = ParseSess::new(vec![]);
iter_exprs(2, &mut |mut e| {
// If the pretty printer is correct, then `parse(print(e))` should be identical to `e`,
@@ -196,7 +196,7 @@ fn main() -> ExitCode {
};
rustc_span::create_default_session_globals_then(|| {
let psess = &ParseSess::new(vec![rustc_parse::DEFAULT_LOCALE_RESOURCE]);
let psess = &ParseSess::new(vec![]);
for &source_code in EXPRS {
let Some(expr) = parse_expr(psess, source_code) else {