diff --git a/Cargo.lock b/Cargo.lock index 23abc6626aaba..161b8e0a68a4d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3959,7 +3959,6 @@ dependencies = [ "rustc_data_structures", "rustc_errors", "rustc_feature", - "rustc_fluent_macro", "rustc_hir", "rustc_index", "rustc_infer", diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index 2e97b4fed245d..1c54f503b7fdb 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -116,7 +116,6 @@ pub static DEFAULT_LOCALE_RESOURCES: &[&str] = &[ // tidy-alphabetical-start rustc_borrowck::DEFAULT_LOCALE_RESOURCE, rustc_const_eval::DEFAULT_LOCALE_RESOURCE, - rustc_hir_analysis::DEFAULT_LOCALE_RESOURCE, rustc_lint::DEFAULT_LOCALE_RESOURCE, rustc_mir_build::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE, diff --git a/compiler/rustc_hir_analysis/Cargo.toml b/compiler/rustc_hir_analysis/Cargo.toml index 8d114862b3fe1..0ce93561ddd4d 100644 --- a/compiler/rustc_hir_analysis/Cargo.toml +++ b/compiler/rustc_hir_analysis/Cargo.toml @@ -16,7 +16,6 @@ rustc_ast = { path = "../rustc_ast" } 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_hir = { path = "../rustc_hir" } rustc_index = { path = "../rustc_index" } rustc_infer = { path = "../rustc_infer" } diff --git a/compiler/rustc_hir_analysis/messages.ftl b/compiler/rustc_hir_analysis/messages.ftl deleted file mode 100644 index 4dd9f50d4a5d0..0000000000000 --- a/compiler/rustc_hir_analysis/messages.ftl +++ /dev/null @@ -1,606 +0,0 @@ -hir_analysis_abi_custom_clothed_function = - items with the "custom" ABI can only be declared externally or defined via naked functions - .suggestion = convert this to an `#[unsafe(naked)]` function - -hir_analysis_ambiguous_assoc_item = ambiguous associated {$assoc_kind} `{$assoc_ident}` in bounds of `{$qself}` - .label = ambiguous associated {$assoc_kind} `{$assoc_ident}` - -hir_analysis_ambiguous_lifetime_bound = - ambiguous lifetime bound, explicit lifetime bound required - -hir_analysis_assoc_item_constraints_not_allowed_here = - associated item constraints are not allowed here - .label = associated item constraint not allowed here - -hir_analysis_assoc_item_is_private = {$kind} `{$name}` is private - .label = private {$kind} - .defined_here_label = the {$kind} is defined here - -hir_analysis_assoc_item_not_found = associated {$assoc_kind} `{$assoc_ident}` not found for `{$qself}` - -hir_analysis_assoc_item_not_found_found_in_other_trait_label = there is {$identically_named -> - [true] an - *[false] a similarly named - } associated {$assoc_kind} `{$suggested_name}` in the trait `{$trait_name}` -hir_analysis_assoc_item_not_found_label = associated {$assoc_kind} `{$assoc_ident}` not found -hir_analysis_assoc_item_not_found_other_sugg = `{$qself}` has the following associated {$assoc_kind} -hir_analysis_assoc_item_not_found_similar_in_other_trait_qpath_sugg = - consider fully qualifying{$identically_named -> - [true] {""} - *[false] {" "}and renaming - } the associated {$assoc_kind} -hir_analysis_assoc_item_not_found_similar_in_other_trait_sugg = change the associated {$assoc_kind} name to use `{$suggested_name}` from `{$trait_name}` -hir_analysis_assoc_item_not_found_similar_in_other_trait_with_bound_sugg = ...and changing the associated {$assoc_kind} name -hir_analysis_assoc_item_not_found_similar_sugg = there is an associated {$assoc_kind} with a similar name - -hir_analysis_assoc_kind_mismatch = expected {$expected}, found {$got} - .label = unexpected {$got} - .expected_because_label = expected a {$expected} because of this associated {$expected} - .note = the associated {$assoc_kind} is defined here - .bound_on_assoc_const_label = bounds are not allowed on associated constants - -hir_analysis_assoc_kind_mismatch_wrap_in_braces_sugg = consider adding braces here - -hir_analysis_associated_type_trait_uninferred_generic_params = cannot use the {$what} of a trait with uninferred generic parameters - .suggestion = use a fully qualified path with inferred lifetimes - -hir_analysis_associated_type_trait_uninferred_generic_params_multipart_suggestion = use a fully qualified path with explicit lifetimes - -hir_analysis_async_drop_without_sync_drop = `AsyncDrop` impl without `Drop` impl - .help = type implementing `AsyncDrop` trait must also implement `Drop` trait to be used in sync context and unwinds - -hir_analysis_auto_deref_reached_recursion_limit = reached the recursion limit while auto-dereferencing `{$ty}` - .label = deref recursion limit reached - .help = consider increasing the recursion limit by adding a `#![recursion_limit = "{$suggested_limit}"]` attribute to your crate (`{$crate_name}`) - -hir_analysis_bad_precise_capture = expected {$kind} parameter in `use<...>` precise captures list, found {$found} - -hir_analysis_bad_return_type_notation_position = return type notation not allowed in this position yet - -hir_analysis_cannot_capture_late_bound_const = - cannot capture late-bound const parameter in {$what} - .label = parameter defined here - -hir_analysis_cannot_capture_late_bound_lifetime = - cannot capture late-bound lifetime in {$what} - .label = lifetime defined here - -hir_analysis_cannot_capture_late_bound_ty = - cannot capture late-bound type parameter in {$what} - .label = parameter defined here - -hir_analysis_closure_implicit_hrtb = implicit types in closure signatures are forbidden when `for<...>` is present - .label = `for<...>` is here - -hir_analysis_cmse_generic = - generics are not allowed in `extern {$abi}` signatures - -hir_analysis_cmse_impl_trait = - `impl Trait` is not allowed in `extern {$abi}` signatures - -hir_analysis_cmse_inputs_stack_spill = - arguments for `{$abi}` function too large to pass via registers - .label = does not fit in the available registers - .note = functions with the `{$abi}` ABI must pass all their arguments via the 4 32-bit argument registers - -hir_analysis_cmse_output_stack_spill = - return value of `{$abi}` function too large to pass via registers - .label = this type doesn't fit in the available registers - .note1 = functions with the `{$abi}` ABI must pass their result via the available return registers - .note2 = the result must either be a (transparently wrapped) i64, u64 or f64, or be at most 4 bytes in size - -hir_analysis_coerce_multi = implementing `{$trait_name}` does not allow multiple fields to be coerced - .note = the trait `{$trait_name}` may only be implemented when a single field is being coerced - .label = these fields must be coerced for `{$trait_name}` to be valid - -hir_analysis_coerce_pointee_no_field = `CoercePointee` can only be derived on `struct`s with at least one field - -hir_analysis_coerce_pointee_no_user_validity_assertion = asserting applicability of `derive(CoercePointee)` on a target data is forbidden - -hir_analysis_coerce_pointee_not_concrete_ty = `derive(CoercePointee)` is only applicable to `struct` - -hir_analysis_coerce_pointee_not_struct = `derive(CoercePointee)` is only applicable to `struct`, instead of `{$kind}` - -hir_analysis_coerce_pointee_not_transparent = `derive(CoercePointee)` is only applicable to `struct` with `repr(transparent)` layout - -hir_analysis_coerce_same_pat_kind = only pattern types with the same pattern can be coerced between each other - -hir_analysis_coerce_unsized_field_validity = for `{$ty}` to have a valid implementation of `{$trait_name}`, it must be possible to coerce the field of type `{$field_ty}` - .label = `{$field_ty}` must be a pointer, reference, or smart pointer that is allowed to be unsized - -hir_analysis_coerce_unsized_may = the trait `{$trait_name}` may only be implemented for a coercion between structures - -hir_analysis_coerce_zero = implementing `{$trait_name}` requires a field to be coerced - -hir_analysis_coercion_between_struct_same_note = expected coercion between the same definition; expected `{$source_path}`, found `{$target_path}` - -hir_analysis_coercion_between_struct_single_note = expected a single field to be coerced, none found - -hir_analysis_const_bound_for_non_const_trait = `{$modifier}` can only be applied to `const` traits - .label = can't be applied to `{$trait_name}` - .note = `{$trait_name}` can't be used with `{$modifier}` because it isn't `const` - .suggestion = {$suggestion_pre}mark `{$trait_name}` as `const` to allow it to have `const` implementations - -hir_analysis_const_impl_for_non_const_trait = const `impl` for trait `{$trait_name}` which is not `const` - .label = this trait is not `const` - .suggestion = {$suggestion_pre}mark `{$trait_name}` as `const` to allow it to have `const` implementations - .note = marking a trait with `const` ensures all default method bodies are `const` - .adding = adding a non-const method body in the future would be a breaking change - -hir_analysis_const_param_ty_impl_on_non_adt = - the trait `ConstParamTy` may not be implemented for this type - .label = type is not a structure or enumeration - -hir_analysis_const_param_ty_impl_on_unsized = - the trait `ConstParamTy` may not be implemented for this type - .label = type is not `Sized` - -hir_analysis_copy_impl_on_non_adt = - the trait `Copy` cannot be implemented for this type - .label = type is not a structure or enumeration - -hir_analysis_copy_impl_on_type_with_dtor = - the trait `Copy` cannot be implemented for this type; the type has a destructor - .label = `Copy` not allowed on types with destructors - .note = destructor declared here - -hir_analysis_cross_crate_traits = cross-crate traits with a default impl, like `{$traits}`, can only be implemented for a struct/enum type, not `{$self_ty}` - .label = can't implement cross-crate trait with a default impl for non-struct/enum type - -hir_analysis_cross_crate_traits_defined = cross-crate traits with a default impl, like `{$traits}`, can only be implemented for a struct/enum type defined in the current crate - .label = can't implement cross-crate trait for type in another crate - -hir_analysis_dispatch_from_dyn_repr = structs implementing `DispatchFromDyn` may not have `#[repr(packed)]` or `#[repr(C)]` - -hir_analysis_dispatch_from_dyn_zst = the trait `DispatchFromDyn` may only be implemented for structs containing the field being coerced, ZST fields with 1 byte alignment that don't mention type/const generics, and nothing else - .note = extra field `{$name}` of type `{$ty}` is not allowed - -hir_analysis_drop_impl_negative = negative `Drop` impls are not supported - -hir_analysis_drop_impl_on_wrong_item = - the `{$trait_}` trait may only be implemented for local structs, enums, and unions - .label = must be a struct, enum, or union in the current crate - -hir_analysis_drop_impl_reservation = reservation `Drop` impls are not supported - -hir_analysis_duplicate_precise_capture = cannot capture parameter `{$name}` twice - .label = parameter captured again here - -hir_analysis_dyn_trait_assoc_item_binding_mentions_self = - {$kind} binding in trait object type mentions `Self` - .label = contains a mention of `Self` - .binding_label = this binding mentions `Self` - -hir_analysis_eii_with_generics = - `{$impl_name}` cannot have generic parameters other than lifetimes - .label = required by this attribute - .help = `#[{$eii_name}]` marks the implementation of an "externally implementable item" - -hir_analysis_empty_specialization = specialization impl does not specialize any associated items - .note = impl is a specialization of this impl - -hir_analysis_enum_discriminant_overflowed = enum discriminant overflowed - .label = overflowed on value after {$discr} - .note = explicitly set `{$item_name} = {$wrapped_discr}` if that is desired outcome - -hir_analysis_escaping_bound_var_in_ty_of_assoc_const_binding = - the type of the associated constant `{$assoc_const}` cannot capture late-bound generic parameters - .label = its type cannot capture the late-bound {$var_def_kind} `{$var_name}` - .var_defined_here_label = the late-bound {$var_def_kind} `{$var_name}` is defined here - -hir_analysis_field_already_declared = - field `{$field_name}` is already declared - .label = field already declared - .previous_decl_label = `{$field_name}` first declared here - -hir_analysis_field_already_declared_both_nested = - field `{$field_name}` is already declared - .label = field `{$field_name}` declared in this unnamed field - .nested_field_decl_note = field `{$field_name}` declared here - .previous_decl_label = `{$field_name}` first declared here in this unnamed field - .previous_nested_field_decl_note = field `{$field_name}` first declared here - -hir_analysis_field_already_declared_current_nested = - field `{$field_name}` is already declared - .label = field `{$field_name}` declared in this unnamed field - .nested_field_decl_note = field `{$field_name}` declared here - .previous_decl_label = `{$field_name}` first declared here - -hir_analysis_field_already_declared_nested_help = - fields from the type of this unnamed field are considered fields of the outer type - -hir_analysis_field_already_declared_previous_nested = - field `{$field_name}` is already declared - .label = field already declared - .previous_decl_label = `{$field_name}` first declared here in this unnamed field - .previous_nested_field_decl_note = field `{$field_name}` first declared here - -hir_analysis_generic_args_on_overridden_impl = could not resolve generic parameters on overridden impl - -hir_analysis_impl_not_marked_default = `{$ident}` specializes an item from a parent `impl`, but that item is not marked `default` - .label = cannot specialize default item `{$ident}` - .ok_label = parent `impl` is here - .note = to specialize, `{$ident}` in the parent `impl` must be marked `default` - -hir_analysis_impl_not_marked_default_err = `{$ident}` specializes an item from a parent `impl`, but that item is not marked `default` - .note = parent implementation is in crate `{$cname}` - -hir_analysis_impl_unpin_for_pin_projected_type = explicit impls for the `Unpin` trait are not permitted for structurally pinned types - .label = impl of `Unpin` not allowed - .help = `{$adt_name}` is structurally pinned because it is marked as `#[pin_v2]` - -hir_analysis_inherent_dyn = cannot define inherent `impl` for a dyn auto trait - .label = impl requires at least one non-auto trait - .note = define and implement a new trait or type instead - -hir_analysis_inherent_nominal = no nominal type found for inherent implementation - .label = impl requires a nominal type - .note = either implement a trait on it or create a newtype to wrap it instead -hir_analysis_inherent_primitive_ty = cannot define inherent `impl` for primitive types - .help = consider using an extension trait instead - -hir_analysis_inherent_primitive_ty_note = you could also try moving the reference to uses of `{$subty}` (such as `self`) within the implementation - -hir_analysis_inherent_ty_outside = cannot define inherent `impl` for a type outside of the crate where the type is defined - .help = consider moving this inherent impl into the crate defining the type if possible - .span_help = alternatively add `#[rustc_has_incoherent_inherent_impls]` to the type and `#[rustc_allow_incoherent_impl]` to the relevant impl items - -hir_analysis_inherent_ty_outside_new = cannot define inherent `impl` for a type outside of the crate where the type is defined - .label = impl for type defined outside of crate - .note = define and implement a trait or new type instead - -hir_analysis_inherent_ty_outside_primitive = cannot define inherent `impl` for primitive types outside of `core` - .help = consider moving this inherent impl into `core` if possible - .span_help = alternatively add `#[rustc_allow_incoherent_impl]` to the relevant impl items - -hir_analysis_inherent_ty_outside_relevant = cannot define inherent `impl` for a type outside of the crate where the type is defined - .help = consider moving this inherent impl into the crate defining the type if possible - .span_help = alternatively add `#[rustc_allow_incoherent_impl]` to the relevant impl items - -hir_analysis_invalid_generic_receiver_ty = invalid generic `self` parameter type: `{$receiver_ty}` - .note = type of `self` must not be a method generic parameter type - -hir_analysis_invalid_generic_receiver_ty_help = - use a concrete type such as `self`, `&self`, `&mut self`, `self: Box`, `self: Rc`, `self: Arc`, or `self: Pin

` (where P is one of the previous types except `Self`) - -hir_analysis_invalid_receiver_ty = invalid `self` parameter type: `{$receiver_ty}` - .note = type of `self` must be `Self` or some type implementing `Receiver` - -hir_analysis_invalid_receiver_ty_help = - consider changing to `self`, `&self`, `&mut self`, or a type implementing `Receiver` such as `self: Box`, `self: Rc`, or `self: Arc` - -hir_analysis_invalid_receiver_ty_help_no_arbitrary_self_types = - consider changing to `self`, `&self`, `&mut self`, `self: Box`, `self: Rc`, `self: Arc`, or `self: Pin

` (where P is one of the previous types except `Self`) - -hir_analysis_invalid_receiver_ty_help_nonnull_note = - `NonNull` does not implement `Receiver` because it has methods that may shadow the referent; consider wrapping your `NonNull` in a newtype wrapper for which you implement `Receiver` - -hir_analysis_invalid_receiver_ty_help_weak_note = - `Weak` does not implement `Receiver` because it has methods that may shadow the referent; consider wrapping your `Weak` in a newtype wrapper for which you implement `Receiver` - -hir_analysis_invalid_receiver_ty_no_arbitrary_self_types = invalid `self` parameter type: `{$receiver_ty}` - .note = type of `self` must be `Self` or a type that dereferences to it - -hir_analysis_invalid_union_field = - field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union - .note = union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>` - -hir_analysis_invalid_union_field_sugg = - wrap the field type in `ManuallyDrop<...>` - -hir_analysis_late_bound_const_in_apit = `impl Trait` can only mention const parameters from an fn or impl - .label = const parameter declared here - -hir_analysis_late_bound_lifetime_in_apit = `impl Trait` can only mention lifetimes from an fn or impl - .label = lifetime declared here - -hir_analysis_late_bound_type_in_apit = `impl Trait` can only mention type parameters from an fn or impl - .label = type parameter declared here - -hir_analysis_lifetime_implicitly_captured = `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list - .param_label = all lifetime parameters originating from a trait are captured implicitly - -hir_analysis_lifetime_must_be_first = lifetime parameter `{$name}` must be listed before non-lifetime parameters - .label = move the lifetime before this parameter - -hir_analysis_lifetime_not_captured = `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list - .label = lifetime captured due to being mentioned in the bounds of the `impl Trait` - .param_label = this lifetime parameter is captured - -hir_analysis_lifetimes_or_bounds_mismatch_on_eii = - lifetime parameters or bounds of `{$ident}` do not match the declaration - .label = lifetimes do not match - .generics_label = lifetimes in impl do not match this signature - .where_label = this `where` clause might not match the one in the declaration - .bounds_label = this bound might be missing in the implementation - -hir_analysis_lifetimes_or_bounds_mismatch_on_trait = - lifetime parameters or bounds on {$item_kind} `{$ident}` do not match the trait declaration - .label = lifetimes do not match {$item_kind} in trait - .generics_label = lifetimes in impl do not match this {$item_kind} in trait - .where_label = this `where` clause might not match the one in the trait - .bounds_label = this bound might be missing in the impl - -hir_analysis_linkage_type = - invalid type for variable with `#[linkage]` attribute - -hir_analysis_main_function_async = `main` function is not allowed to be `async` - .label = `main` function is not allowed to be `async` - -hir_analysis_main_function_generic_parameters = `main` function is not allowed to have generic parameters - .label = `main` cannot have generic parameters - -hir_analysis_main_function_return_type_generic = `main` function return type is not allowed to have generic parameters - -hir_analysis_manual_implementation = - manual implementations of `{$trait_name}` are experimental - .label = manual implementations of `{$trait_name}` are experimental - .help = add `#![feature(unboxed_closures)]` to the crate attributes to enable - -hir_analysis_method_should_return_future = method should be `async` or return a future, but it is synchronous - .note = this method is `async` so it expects a future to be returned - -hir_analysis_missing_generic_params = - the {$descr} {$parameterCount -> - [one] parameter - *[other] parameters - } {$parameters} must be explicitly specified - .label = {$descr} {$parameterCount -> - [one] parameter - *[other] parameters - } {$parameters} must be specified for this - .suggestion = explicitly specify the {$descr} {$parameterCount -> - [one] parameter - *[other] parameters - } - .no_suggestion_label = missing {$parameterCount -> - [one] reference - *[other] references - } to {$parameters} - .note = because the parameter {$parameterCount -> - [one] default references - *[other] defaults reference - } `Self`, the {$parameterCount -> - [one] parameter - *[other] parameters - } must be specified on the trait object type - -hir_analysis_missing_one_of_trait_item = not all trait items implemented, missing one of: `{$missing_items_msg}` - .label = missing one of `{$missing_items_msg}` in implementation - .note = required because of this annotation - -hir_analysis_missing_trait_item = not all trait items implemented, missing: `{$missing_items_msg}` - .label = missing `{$missing_items_msg}` in implementation - -hir_analysis_missing_trait_item_label = `{$item}` from trait - -hir_analysis_missing_trait_item_suggestion = implement the missing item: `{$snippet}` - -hir_analysis_missing_trait_item_unstable = not all trait items implemented, missing: `{$missing_item_name}` - .note = default implementation of `{$missing_item_name}` is unstable - .some_note = use of unstable library feature `{$feature}`: {$reason} - .none_note = use of unstable library feature `{$feature}` - -hir_analysis_no_variant_named = no variant named `{$ident}` found for enum `{$ty}` - -hir_analysis_not_supported_delegation = {$descr} - .label = callee defined here - -hir_analysis_only_current_traits_adt = `{$name}` is not defined in the current crate - -hir_analysis_only_current_traits_arbitrary = only traits defined in the current crate can be implemented for arbitrary types - -hir_analysis_only_current_traits_foreign = this is not defined in the current crate because this is a foreign trait - -hir_analysis_only_current_traits_name = this is not defined in the current crate because {$name} are always foreign - -hir_analysis_only_current_traits_note = define and implement a trait or new type instead - -hir_analysis_only_current_traits_note_more_info = for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules - -hir_analysis_only_current_traits_note_uncovered = impl doesn't have any local type before any uncovered type parameters - -hir_analysis_only_current_traits_opaque = type alias impl trait is treated as if it were foreign, because its hidden type could be from a foreign crate - -hir_analysis_only_current_traits_outside = only traits defined in the current crate can be implemented for types defined outside of the crate - -hir_analysis_only_current_traits_pointer = `{$pointer}` is not defined in the current crate because raw pointers are always foreign - -hir_analysis_only_current_traits_pointer_sugg = consider introducing a new wrapper type - -hir_analysis_only_current_traits_primitive = only traits defined in the current crate can be implemented for primitive types - -hir_analysis_only_current_traits_ty = `{$ty}` is not defined in the current crate - -hir_analysis_opaque_captures_higher_ranked_lifetime = `impl Trait` cannot capture {$bad_place} - .label = `impl Trait` implicitly captures all lifetimes in scope - .note = lifetime declared here - -hir_analysis_param_in_ty_of_assoc_const_binding = - the type of the associated constant `{$assoc_const}` must not depend on {$param_category -> - [self] `Self` - [synthetic] `impl Trait` - *[normal] generic parameters - } - .label = its type must not depend on {$param_category -> - [self] `Self` - [synthetic] `impl Trait` - *[normal] the {$param_def_kind} `{$param_name}` - } - .param_defined_here_label = {$param_category -> - [synthetic] the `impl Trait` is specified here - *[normal] the {$param_def_kind} `{$param_name}` is defined here - } - -hir_analysis_param_not_captured = `impl Trait` must mention all {$kind} parameters in scope in `use<...>` - .label = {$kind} parameter is implicitly captured by this `impl Trait` - .note = currently, all {$kind} parameters are required to be mentioned in the precise captures list - -hir_analysis_paren_sugar_attribute = the `#[rustc_paren_sugar]` attribute is a temporary means of controlling which traits can use parenthetical notation - .help = add `#![feature(unboxed_closures)]` to the crate attributes to use it - -hir_analysis_parenthesized_fn_trait_expansion = - parenthesized trait syntax expands to `{$expanded_type}` - -hir_analysis_placeholder_not_allowed_item_signatures = the placeholder `_` is not allowed within types on item signatures for {$kind} - .label = not allowed in type signatures - -hir_analysis_precise_capture_self_alias = `Self` can't be captured in `use<...>` precise captures list, since it is an alias - .label = `Self` is not a generic argument, but an alias to the type of the {$what} - -hir_analysis_recursive_generic_parameter = {$param_def_kind} `{$param_name}` is only used recursively - .label = {$param_def_kind} must be used non-recursively in the definition - .note = all type parameters must be used in a non-recursive way in order to constrain their variance - -hir_analysis_redundant_lifetime_args = unnecessary lifetime parameter `{$victim}` - .note = you can use the `{$candidate}` lifetime directly, in place of `{$victim}` - -hir_analysis_requires_note = the `{$trait_name}` impl for `{$ty}` requires that `{$error_predicate}` - -hir_analysis_return_type_notation_equality_bound = - return type notation is not allowed to use type equality - -hir_analysis_return_type_notation_illegal_param_const = - return type notation is not allowed for functions that have const parameters - .label = const parameter declared here -hir_analysis_return_type_notation_illegal_param_type = - return type notation is not allowed for functions that have type parameters - .label = type parameter declared here - -hir_analysis_return_type_notation_on_non_rpitit = - return type notation used on function that is not `async` and does not return `impl Trait` - .note = function returns `{$ty}`, which is not compatible with associated type return bounds - .label = this function must be `async` or return `impl Trait` - -hir_analysis_rpitit_refined = impl trait in impl method signature does not match trait method signature - .suggestion = replace the return type so that it matches the trait - .label = return type from trait method defined here - .unmatched_bound_label = this bound is stronger than that defined on the trait - .note = add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate - .feedback_note = we are soliciting feedback, see issue #121718 for more information - -hir_analysis_rpitit_refined_lifetimes = impl trait in impl method captures fewer lifetimes than in trait - .suggestion = modify the `use<..>` bound to capture the same lifetimes that the trait does - .note = add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate - .feedback_note = we are soliciting feedback, see issue #121718 for more information - -hir_analysis_self_in_impl_self = - `Self` is not valid in the self type of an impl block - .note = replace `Self` with a different type - -hir_analysis_self_ty_not_captured = `impl Trait` must mention the `Self` type of the trait in `use<...>` - .label = `Self` type parameter is implicitly captured by this `impl Trait` - .note = currently, all type parameters are required to be mentioned in the precise captures list - -hir_analysis_simd_ffi_highly_experimental = use of SIMD type{$snip} in FFI is highly experimental and may result in invalid code - .help = add `#![feature(simd_ffi)]` to the crate attributes to enable - -hir_analysis_specialization_trait = implementing `rustc_specialization_trait` traits is unstable - .help = add `#![feature(min_specialization)]` to the crate attributes to enable - -hir_analysis_static_specialize = cannot specialize on `'static` lifetime - -hir_analysis_supertrait_item_multiple_shadowee = items from several supertraits are shadowed: {$traits} - -hir_analysis_supertrait_item_shadowee = item from `{$supertrait}` is shadowed by a subtrait item - -hir_analysis_supertrait_item_shadowing = trait item `{$item}` from `{$subtrait}` shadows identically named item from supertrait - -hir_analysis_target_feature_on_main = `main` function is not allowed to have `#[target_feature]` - -hir_analysis_too_large_static = extern static is too large for the target architecture - -hir_analysis_track_caller_on_main = `main` function is not allowed to be `#[track_caller]` - .suggestion = remove this annotation - -hir_analysis_trait_cannot_impl_for_ty = the trait `{$trait_name}` cannot be implemented for this type - .label = this field does not implement `{$trait_name}` - -hir_analysis_trait_object_declared_with_no_traits = - at least one trait is required for an object type - .alias_span = this alias does not contain a trait - -hir_analysis_traits_with_default_impl = traits with a default impl, like `{$traits}`, cannot be implemented for {$problematic_kind} `{$self_ty}` - .note = a trait object implements `{$traits}` if and only if `{$traits}` is one of the trait object's trait bounds - -hir_analysis_transparent_enum_variant = transparent enum needs exactly one variant, but has {$number} - .label = needs exactly one variant, but has {$number} - .many_label = too many variants in `{$path}` - .multi_label = variant here - -hir_analysis_transparent_non_zero_sized = transparent {$desc} needs at most one field with non-trivial size or alignment, but has {$field_count} - .label = needs at most one field with non-trivial size or alignment, but has {$field_count} - .labels = this field has non-zero size or requires alignment - -hir_analysis_transparent_non_zero_sized_enum = the variant of a transparent {$desc} needs at most one field with non-trivial size or alignment, but has {$field_count} - .label = needs at most one field with non-trivial size or alignment, but has {$field_count} - .labels = this field has non-zero size or requires alignment - -hir_analysis_ty_of_assoc_const_binding_note = `{$assoc_const}` has type `{$ty}` - -hir_analysis_ty_param_first_local = type parameter `{$param}` must be covered by another type when it appears before the first local type (`{$local_type}`) - .label = type parameter `{$param}` must be covered by another type when it appears before the first local type (`{$local_type}`) - .note = implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type - .case_note = in this case, 'before' refers to the following order: `impl<..> ForeignTrait for T0`, where `T0` is the first and `Tn` is the last - -hir_analysis_ty_param_some = type parameter `{$param}` must be used as the type parameter for some local type (e.g., `MyStruct<{$param}>`) - .label = type parameter `{$param}` must be used as the type parameter for some local type - .note = implementing a foreign trait is only possible if at least one of the types for which it is implemented is local - .only_note = only traits defined in the current crate can be implemented for a type parameter - -hir_analysis_type_of = {$ty} - -hir_analysis_unconstrained_generic_parameter = the {$param_def_kind} `{$param_name}` is not constrained by the impl trait, self type, or predicates - .label = unconstrained {$param_def_kind} - .const_param_note = expressions using a const parameter must map each value to a distinct output value - .const_param_note2 = proving the result of expressions other than the parameter are unique is not supported - -hir_analysis_unconstrained_opaque_type = unconstrained opaque type - .note = `{$name}` must be used in combination with a concrete type within the same {$what} - -hir_analysis_unrecognized_intrinsic_function = - unrecognized intrinsic function: `{$name}` - .label = unrecognized intrinsic - .help = if you're adding an intrinsic, be sure to update `check_intrinsic_type` - -hir_analysis_unused_associated_type_bounds = - unnecessary associated type bound for dyn-incompatible associated type - .note = this associated type has a `where Self: Sized` bound, and while the associated type can be specified, it cannot be used because trait objects are never `Sized` - .suggestion = remove this bound - -hir_analysis_unused_generic_parameter = - {$param_def_kind} `{$param_name}` is never used - .label = unused {$param_def_kind} - .const_param_help = if you intended `{$param_name}` to be a const parameter, use `const {$param_name}: /* Type */` instead - .usage_spans = `{$param_name}` is named here, but is likely unused in the containing type - -hir_analysis_unused_generic_parameter_adt_help = - consider removing `{$param_name}`, referring to it in a field, or using a marker such as `{$phantom_data}` -hir_analysis_unused_generic_parameter_adt_no_phantom_data_help = - consider removing `{$param_name}` or referring to it in a field -hir_analysis_unused_generic_parameter_ty_alias_help = - consider removing `{$param_name}` or referring to it in the body of the type alias - -hir_analysis_useless_impl_item = this item cannot be used as its where bounds are not satisfied for the `Self` type - -hir_analysis_value_of_associated_struct_already_specified = - the value of the associated type `{$item_name}` in trait `{$def_path}` is already specified - .label = re-bound here - .previous_bound_label = `{$item_name}` bound here first - -hir_analysis_variadic_function_compatible_convention = C-variadic functions with the {$convention} calling convention are not supported - .label = C-variadic function must have a compatible calling convention - -hir_analysis_variances_of = {$variances} - -hir_analysis_where_clause_on_main = `main` function is not allowed to have a `where` clause - .label = `main` cannot have a `where` clause - -hir_analysis_within_macro = due to this macro variable - -hir_analysis_wrong_number_of_generic_arguments_to_intrinsic = - intrinsic has wrong number of {$descr} parameters: found {$found}, expected {$expected} - .label = expected {$expected} {$descr} {$expected -> - [one] parameter - *[other] parameters - } diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 8b50eceb26e49..d3b5350061a89 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -5,7 +5,9 @@ use hir::intravisit::{self, Visitor}; use rustc_abi::{ExternAbi, ScalableElt}; use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet}; use rustc_errors::codes::*; -use rustc_errors::{Applicability, ErrorGuaranteed, pluralize, struct_span_code_err}; +use rustc_errors::{ + Applicability, ErrorGuaranteed, inline_fluent, pluralize, struct_span_code_err, +}; use rustc_hir::attrs::{AttributeKind, EiiDecl, EiiImpl, EiiImplResolution}; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, LocalDefId}; @@ -42,8 +44,8 @@ use {rustc_ast as ast, rustc_hir as hir}; use super::compare_eii::compare_eii_function_types; use crate::autoderef::Autoderef; use crate::constrained_generic_params::{Parameter, identify_constrained_generic_params}; +use crate::errors; use crate::errors::InvalidReceiverTyHint; -use crate::{errors, fluent_generated as fluent}; pub(super) struct WfCheckingCtxt<'a, 'tcx> { pub(super) ocx: ObligationCtxt<'a, 'tcx, FulfillmentError<'tcx>>, @@ -1740,7 +1742,7 @@ fn check_method_receiver<'tcx>( the `arbitrary_self_types` feature", ), ) - .with_help(fluent::hir_analysis_invalid_receiver_ty_help) + .with_help(inline_fluent!("consider changing to `self`, `&self`, `&mut self`, or a type implementing `Receiver` such as `self: Box`, `self: Rc`, or `self: Arc`")) .emit() } None | Some(ArbitrarySelfTypesLevel::Basic) @@ -1764,7 +1766,7 @@ fn check_method_receiver<'tcx>( the `arbitrary_self_types_pointers` feature", ), ) - .with_help(fluent::hir_analysis_invalid_receiver_ty_help) + .with_help(inline_fluent!("consider changing to `self`, `&self`, `&mut self`, or a type implementing `Receiver` such as `self: Box`, `self: Rc`, or `self: Arc`")) .emit() } _ => @@ -2442,8 +2444,8 @@ fn lint_redundant_lifetimes<'tcx>( } #[derive(LintDiagnostic)] -#[diag(hir_analysis_redundant_lifetime_args)] -#[note] +#[diag("unnecessary lifetime parameter `{$victim}`")] +#[note("you can use the `{$candidate}` lifetime directly, in place of `{$victim}`")] struct RedundantLifetimeArgsLint<'tcx> { /// The lifetime we have found to be redundant. victim: ty::Region<'tcx>, diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs index c996fc97cd679..6a23b42ae0981 100644 --- a/compiler/rustc_hir_analysis/src/errors.rs +++ b/compiler/rustc_hir_analysis/src/errors.rs @@ -4,24 +4,22 @@ use rustc_abi::ExternAbi; use rustc_errors::codes::*; use rustc_errors::{ Applicability, Diag, DiagCtxtHandle, DiagSymbolList, Diagnostic, EmissionGuarantee, Level, - MultiSpan, listify, + MultiSpan, inline_fluent, listify, }; use rustc_hir::limit::Limit; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_middle::ty::{self, Ty}; use rustc_span::{Ident, Span, Symbol}; - -use crate::fluent_generated as fluent; pub(crate) mod wrong_number_of_generic_args; mod precise_captures; pub(crate) use precise_captures::*; #[derive(Diagnostic)] -#[diag(hir_analysis_ambiguous_assoc_item)] +#[diag("ambiguous associated {$assoc_kind} `{$assoc_ident}` in bounds of `{$qself}`")] pub(crate) struct AmbiguousAssocItem<'a> { #[primary_span] - #[label] + #[label("ambiguous associated {$assoc_kind} `{$assoc_ident}`")] pub span: Span, pub assoc_kind: &'static str, pub assoc_ident: Ident, @@ -29,29 +27,26 @@ pub(crate) struct AmbiguousAssocItem<'a> { } #[derive(Diagnostic)] -#[diag(hir_analysis_assoc_kind_mismatch)] +#[diag("expected {$expected}, found {$got}")] pub(crate) struct AssocKindMismatch { #[primary_span] - #[label] + #[label("unexpected {$got}")] pub span: Span, pub expected: &'static str, pub got: &'static str, - #[label(hir_analysis_expected_because_label)] + #[label("expected a {$expected} because of this associated {$expected}")] pub expected_because_label: Option, pub assoc_kind: &'static str, - #[note] + #[note("the associated {$assoc_kind} is defined here")] pub def_span: Span, - #[label(hir_analysis_bound_on_assoc_const_label)] + #[label("bounds are not allowed on associated constants")] pub bound_on_assoc_const_label: Option, #[subdiagnostic] pub wrap_in_braces_sugg: Option, } #[derive(Subdiagnostic)] -#[multipart_suggestion( - hir_analysis_assoc_kind_mismatch_wrap_in_braces_sugg, - applicability = "maybe-incorrect" -)] +#[multipart_suggestion("consider adding braces here", applicability = "maybe-incorrect")] pub(crate) struct AssocKindMismatchWrapInBracesSugg { #[suggestion_part(code = "{{ ")] pub lo: Span, @@ -60,19 +55,19 @@ pub(crate) struct AssocKindMismatchWrapInBracesSugg { } #[derive(Diagnostic)] -#[diag(hir_analysis_assoc_item_is_private, code = E0624)] +#[diag("{$kind} `{$name}` is private", code = E0624)] pub(crate) struct AssocItemIsPrivate { #[primary_span] - #[label] + #[label("private {$kind}")] pub span: Span, pub kind: &'static str, pub name: Ident, - #[label(hir_analysis_defined_here_label)] + #[label("the {$kind} is defined here")] pub defined_here_label: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_assoc_item_not_found, code = E0220)] +#[diag("associated {$assoc_kind} `{$assoc_ident}` not found for `{$qself}`", code = E0220)] pub(crate) struct AssocItemNotFound<'a> { #[primary_span] pub span: Span, @@ -83,18 +78,23 @@ pub(crate) struct AssocItemNotFound<'a> { pub label: Option>, #[subdiagnostic] pub sugg: Option>, - #[label(hir_analysis_within_macro)] + #[label("due to this macro variable")] pub within_macro_span: Option, } #[derive(Subdiagnostic)] pub(crate) enum AssocItemNotFoundLabel<'a> { - #[label(hir_analysis_assoc_item_not_found_label)] + #[label("associated {$assoc_kind} `{$assoc_ident}` not found")] NotFound { #[primary_span] span: Span, }, - #[label(hir_analysis_assoc_item_not_found_found_in_other_trait_label)] + #[label( + "there is {$identically_named -> + [true] an + *[false] a similarly named + } associated {$assoc_kind} `{$suggested_name}` in the trait `{$trait_name}`" + )] FoundInOtherTrait { #[primary_span] span: Span, @@ -109,7 +109,7 @@ pub(crate) enum AssocItemNotFoundLabel<'a> { pub(crate) enum AssocItemNotFoundSugg<'a> { #[suggestion( - hir_analysis_assoc_item_not_found_similar_sugg, + "there is an associated {$assoc_kind} with a similar name", code = "{suggested_name}", applicability = "maybe-incorrect" )] @@ -120,7 +120,7 @@ pub(crate) enum AssocItemNotFoundSugg<'a> { suggested_name: Symbol, }, #[suggestion( - hir_analysis_assoc_item_not_found_similar_in_other_trait_sugg, + "change the associated {$assoc_kind} name to use `{$suggested_name}` from `{$trait_name}`", code = "{suggested_name}", style = "verbose", applicability = "maybe-incorrect" @@ -133,7 +133,10 @@ pub(crate) enum AssocItemNotFoundSugg<'a> { suggested_name: Symbol, }, #[multipart_suggestion( - hir_analysis_assoc_item_not_found_similar_in_other_trait_qpath_sugg, + "consider fully qualifying{$identically_named -> + [true] {\"\"} + *[false] {\" \"}and renaming + } the associated {$assoc_kind}", style = "verbose" )] SimilarInOtherTraitQPath { @@ -150,7 +153,7 @@ pub(crate) enum AssocItemNotFoundSugg<'a> { applicability: Applicability, }, #[suggestion( - hir_analysis_assoc_item_not_found_other_sugg, + "`{$qself}` has the following associated {$assoc_kind}", code = "{suggested_name}", applicability = "maybe-incorrect" )] @@ -164,10 +167,15 @@ pub(crate) enum AssocItemNotFoundSugg<'a> { } #[derive(Diagnostic)] -#[diag(hir_analysis_wrong_number_of_generic_arguments_to_intrinsic, code = E0094)] +#[diag("intrinsic has wrong number of {$descr} parameters: found {$found}, expected {$expected}", code = E0094)] pub(crate) struct WrongNumberOfGenericArgumentsToIntrinsic<'a> { #[primary_span] - #[label] + #[label( + "expected {$expected} {$descr} {$expected -> + [one] parameter + *[other] parameters + }" + )] pub span: Span, pub found: usize, pub expected: usize, @@ -175,90 +183,90 @@ pub(crate) struct WrongNumberOfGenericArgumentsToIntrinsic<'a> { } #[derive(Diagnostic)] -#[diag(hir_analysis_unrecognized_intrinsic_function, code = E0093)] -#[help] +#[diag("unrecognized intrinsic function: `{$name}`", code = E0093)] +#[help("if you're adding an intrinsic, be sure to update `check_intrinsic_type`")] pub(crate) struct UnrecognizedIntrinsicFunction { #[primary_span] - #[label] + #[label("unrecognized intrinsic")] pub span: Span, pub name: Symbol, } #[derive(Diagnostic)] -#[diag(hir_analysis_lifetimes_or_bounds_mismatch_on_trait, code = E0195)] +#[diag("lifetime parameters or bounds on {$item_kind} `{$ident}` do not match the trait declaration", code = E0195)] pub(crate) struct LifetimesOrBoundsMismatchOnTrait { #[primary_span] - #[label] + #[label("lifetimes do not match {$item_kind} in trait")] pub span: Span, - #[label(hir_analysis_generics_label)] + #[label("lifetimes in impl do not match this {$item_kind} in trait")] pub generics_span: Span, - #[label(hir_analysis_where_label)] + #[label("this `where` clause might not match the one in the trait")] pub where_span: Option, - #[label(hir_analysis_bounds_label)] + #[label("this bound might be missing in the impl")] pub bounds_span: Vec, pub item_kind: &'static str, pub ident: Ident, } #[derive(Diagnostic)] -#[diag(hir_analysis_drop_impl_on_wrong_item, code = E0120)] +#[diag("the `{$trait_}` trait may only be implemented for local structs, enums, and unions", code = E0120)] pub(crate) struct DropImplOnWrongItem { #[primary_span] - #[label] + #[label("must be a struct, enum, or union in the current crate")] pub span: Span, pub trait_: Symbol, } #[derive(Diagnostic)] pub(crate) enum FieldAlreadyDeclared { - #[diag(hir_analysis_field_already_declared, code = E0124)] + #[diag("field `{$field_name}` is already declared", code = E0124)] NotNested { field_name: Ident, #[primary_span] - #[label] + #[label("field already declared")] span: Span, - #[label(hir_analysis_previous_decl_label)] + #[label("`{$field_name}` first declared here")] prev_span: Span, }, - #[diag(hir_analysis_field_already_declared_current_nested)] + #[diag("field `{$field_name}` is already declared")] CurrentNested { field_name: Ident, #[primary_span] - #[label] + #[label("field `{$field_name}` declared in this unnamed field")] span: Span, - #[note(hir_analysis_nested_field_decl_note)] + #[note("field `{$field_name}` declared here")] nested_field_span: Span, #[subdiagnostic] help: FieldAlreadyDeclaredNestedHelp, - #[label(hir_analysis_previous_decl_label)] + #[label("`{$field_name}` first declared here")] prev_span: Span, }, - #[diag(hir_analysis_field_already_declared_previous_nested)] + #[diag("field `{$field_name}` is already declared")] PreviousNested { field_name: Ident, #[primary_span] - #[label] + #[label("field already declared")] span: Span, - #[label(hir_analysis_previous_decl_label)] + #[label("`{$field_name}` first declared here in this unnamed field")] prev_span: Span, - #[note(hir_analysis_previous_nested_field_decl_note)] + #[note("field `{$field_name}` first declared here")] prev_nested_field_span: Span, #[subdiagnostic] prev_help: FieldAlreadyDeclaredNestedHelp, }, - #[diag(hir_analysis_field_already_declared_both_nested)] + #[diag("field `{$field_name}` is already declared")] BothNested { field_name: Ident, #[primary_span] - #[label] + #[label("field `{$field_name}` declared in this unnamed field")] span: Span, - #[note(hir_analysis_nested_field_decl_note)] + #[note("field `{$field_name}` declared here")] nested_field_span: Span, #[subdiagnostic] help: FieldAlreadyDeclaredNestedHelp, - #[label(hir_analysis_previous_decl_label)] + #[label("`{$field_name}` first declared here in this unnamed field")] prev_span: Span, - #[note(hir_analysis_previous_nested_field_decl_note)] + #[note("field `{$field_name}` first declared here")] prev_nested_field_span: Span, #[subdiagnostic] prev_help: FieldAlreadyDeclaredNestedHelp, @@ -266,67 +274,67 @@ pub(crate) enum FieldAlreadyDeclared { } #[derive(Subdiagnostic)] -#[help(hir_analysis_field_already_declared_nested_help)] +#[help("fields from the type of this unnamed field are considered fields of the outer type")] pub(crate) struct FieldAlreadyDeclaredNestedHelp { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_copy_impl_on_type_with_dtor, code = E0184)] +#[diag("the trait `Copy` cannot be implemented for this type; the type has a destructor", code = E0184)] pub(crate) struct CopyImplOnTypeWithDtor { #[primary_span] - #[label] + #[label("`Copy` not allowed on types with destructors")] pub span: Span, - #[note] + #[note("destructor declared here")] pub impl_: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_copy_impl_on_non_adt, code = E0206)] +#[diag("the trait `Copy` cannot be implemented for this type", code = E0206)] pub(crate) struct CopyImplOnNonAdt { #[primary_span] - #[label] + #[label("type is not a structure or enumeration")] pub span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_const_param_ty_impl_on_unsized)] +#[diag("the trait `ConstParamTy` may not be implemented for this type")] pub(crate) struct ConstParamTyImplOnUnsized { #[primary_span] - #[label] + #[label("type is not `Sized`")] pub span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_const_param_ty_impl_on_non_adt)] +#[diag("the trait `ConstParamTy` may not be implemented for this type")] pub(crate) struct ConstParamTyImplOnNonAdt { #[primary_span] - #[label] + #[label("type is not a structure or enumeration")] pub span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_trait_object_declared_with_no_traits, code = E0224)] +#[diag("at least one trait is required for an object type", code = E0224)] pub(crate) struct TraitObjectDeclaredWithNoTraits { #[primary_span] pub span: Span, - #[label(hir_analysis_alias_span)] + #[label("this alias does not contain a trait")] pub trait_alias_span: Option, } #[derive(Diagnostic)] -#[diag(hir_analysis_ambiguous_lifetime_bound, code = E0227)] +#[diag("ambiguous lifetime bound, explicit lifetime bound required", code = E0227)] pub(crate) struct AmbiguousLifetimeBound { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_assoc_item_constraints_not_allowed_here, code = E0229)] +#[diag("associated item constraints are not allowed here", code = E0229)] pub(crate) struct AssocItemConstraintsNotAllowedHere { #[primary_span] - #[label] + #[label("associated item constraint not allowed here")] pub span: Span, #[subdiagnostic] @@ -334,45 +342,64 @@ pub(crate) struct AssocItemConstraintsNotAllowedHere { } #[derive(Diagnostic)] -#[diag(hir_analysis_param_in_ty_of_assoc_const_binding)] +#[diag( + "the type of the associated constant `{$assoc_const}` must not depend on {$param_category -> + [self] `Self` + [synthetic] `impl Trait` + *[normal] generic parameters + }" +)] pub(crate) struct ParamInTyOfAssocConstBinding<'tcx> { #[primary_span] - #[label] + #[label( + "its type must not depend on {$param_category -> + [self] `Self` + [synthetic] `impl Trait` + *[normal] the {$param_def_kind} `{$param_name}` + }" + )] pub span: Span, pub assoc_const: Ident, pub param_name: Symbol, pub param_def_kind: &'static str, pub param_category: &'static str, - #[label(hir_analysis_param_defined_here_label)] + #[label( + "{$param_category -> + [synthetic] the `impl Trait` is specified here + *[normal] the {$param_def_kind} `{$param_name}` is defined here + }" + )] pub param_defined_here_label: Option, #[subdiagnostic] pub ty_note: Option>, } #[derive(Subdiagnostic, Clone, Copy)] -#[note(hir_analysis_ty_of_assoc_const_binding_note)] +#[note("`{$assoc_const}` has type `{$ty}`")] pub(crate) struct TyOfAssocConstBindingNote<'tcx> { pub assoc_const: Ident, pub ty: Ty<'tcx>, } #[derive(Diagnostic)] -#[diag(hir_analysis_escaping_bound_var_in_ty_of_assoc_const_binding)] +#[diag( + "the type of the associated constant `{$assoc_const}` cannot capture late-bound generic parameters" +)] pub(crate) struct EscapingBoundVarInTyOfAssocConstBinding<'tcx> { #[primary_span] - #[label] + #[label("its type cannot capture the late-bound {$var_def_kind} `{$var_name}`")] pub span: Span, pub assoc_const: Ident, pub var_name: Symbol, pub var_def_kind: &'static str, - #[label(hir_analysis_var_defined_here_label)] + #[label("the late-bound {$var_def_kind} `{$var_name}` is defined here")] pub var_defined_here_label: Span, #[subdiagnostic] pub ty_note: Option>, } #[derive(Subdiagnostic)] -#[help(hir_analysis_parenthesized_fn_trait_expansion)] +#[help("parenthesized trait syntax expands to `{$expanded_type}`")] pub(crate) struct ParenthesizedFnTraitExpansion { #[primary_span] pub span: Span, @@ -381,20 +408,20 @@ pub(crate) struct ParenthesizedFnTraitExpansion { } #[derive(Diagnostic)] -#[diag(hir_analysis_value_of_associated_struct_already_specified, code = E0719)] +#[diag("the value of the associated type `{$item_name}` in trait `{$def_path}` is already specified", code = E0719)] pub(crate) struct ValueOfAssociatedStructAlreadySpecified { #[primary_span] - #[label] + #[label("re-bound here")] pub span: Span, - #[label(hir_analysis_previous_bound_label)] + #[label("`{$item_name}` bound here first")] pub prev_span: Span, pub item_name: Ident, pub def_path: String, } #[derive(Diagnostic)] -#[diag(hir_analysis_unconstrained_opaque_type)] -#[note] +#[diag("unconstrained opaque type")] +#[note("`{$name}` must be used in combination with a concrete type within the same {$what}")] pub(crate) struct UnconstrainedOpaqueType { #[primary_span] pub span: Span, @@ -414,10 +441,27 @@ pub(crate) struct MissingGenericParams { impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for MissingGenericParams { #[track_caller] fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> { - let mut err = Diag::new(dcx, level, fluent::hir_analysis_missing_generic_params); + let mut err = Diag::new( + dcx, + level, + inline_fluent!( + "the {$descr} {$parameterCount -> + [one] parameter + *[other] parameters + } {$parameters} must be explicitly specified" + ), + ); err.span(self.span); err.code(E0393); - err.span_label(self.def_span, fluent::hir_analysis_label); + err.span_label( + self.def_span, + inline_fluent!( + "{$descr} {$parameterCount -> + [one] parameter + *[other] parameters + } {$parameters} must be specified for this" + ), + ); enum Descr { Generic, @@ -467,7 +511,12 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for MissingGenericParams { // least we can clue them to the correct syntax `Trait`. err.span_suggestion_verbose( self.span.shrink_to_hi(), - fluent::hir_analysis_suggestion, + inline_fluent!( + "explicitly specify the {$descr} {$parameterCount -> + [one] parameter + *[other] parameters + }" + ), format!( "<{}>", self.missing_generic_params @@ -482,84 +531,112 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for MissingGenericParams { } } if !suggested { - err.span_label(self.span, fluent::hir_analysis_no_suggestion_label); + err.span_label( + self.span, + inline_fluent!( + "missing {$parameterCount -> + [one] reference + *[other] references + } to {$parameters}" + ), + ); } - err.note(fluent::hir_analysis_note); + err.note(inline_fluent!( + "because the parameter {$parameterCount -> + [one] default references + *[other] defaults reference + } `Self`, the {$parameterCount -> + [one] parameter + *[other] parameters + } must be specified on the trait object type" + )); err } } #[derive(Diagnostic)] -#[diag(hir_analysis_manual_implementation, code = E0183)] -#[help] +#[diag("manual implementations of `{$trait_name}` are experimental", code = E0183)] +#[help("add `#![feature(unboxed_closures)]` to the crate attributes to enable")] pub(crate) struct ManualImplementation { #[primary_span] - #[label] + #[label("manual implementations of `{$trait_name}` are experimental")] pub span: Span, pub trait_name: String, } #[derive(Diagnostic)] -#[diag(hir_analysis_generic_args_on_overridden_impl)] +#[diag("could not resolve generic parameters on overridden impl")] pub(crate) struct GenericArgsOnOverriddenImpl { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_const_impl_for_non_const_trait)] +#[diag("const `impl` for trait `{$trait_name}` which is not `const`")] pub(crate) struct ConstImplForNonConstTrait { #[primary_span] - #[label] + #[label("this trait is not `const`")] pub trait_ref_span: Span, pub trait_name: String, - #[suggestion(applicability = "machine-applicable", code = "const ", style = "verbose")] + #[suggestion( + "{$suggestion_pre}mark `{$trait_name}` as `const` to allow it to have `const` implementations", + applicability = "machine-applicable", + code = "const ", + style = "verbose" + )] pub suggestion: Option, pub suggestion_pre: &'static str, - #[note] + #[note("marking a trait with `const` ensures all default method bodies are `const`")] pub marking: (), - #[note(hir_analysis_adding)] + #[note("adding a non-const method body in the future would be a breaking change")] pub adding: (), } #[derive(Diagnostic)] -#[diag(hir_analysis_const_bound_for_non_const_trait)] +#[diag("`{$modifier}` can only be applied to `const` traits")] pub(crate) struct ConstBoundForNonConstTrait { #[primary_span] - #[label] + #[label("can't be applied to `{$trait_name}`")] pub span: Span, pub modifier: &'static str, - #[note] + #[note("`{$trait_name}` can't be used with `{$modifier}` because it isn't `const`")] pub def_span: Option, - #[suggestion(applicability = "machine-applicable", code = "const ", style = "verbose")] + #[suggestion( + "{$suggestion_pre}mark `{$trait_name}` as `const` to allow it to have `const` implementations", + applicability = "machine-applicable", + code = "const ", + style = "verbose" + )] pub suggestion: Option, pub suggestion_pre: &'static str, pub trait_name: String, } #[derive(Diagnostic)] -#[diag(hir_analysis_self_in_impl_self)] +#[diag("`Self` is not valid in the self type of an impl block")] pub(crate) struct SelfInImplSelf { #[primary_span] pub span: MultiSpan, - #[note] + #[note("replace `Self` with a different type")] pub note: (), } #[derive(Diagnostic)] -#[diag(hir_analysis_linkage_type, code = E0791)] +#[diag("invalid type for variable with `#[linkage]` attribute", code = E0791)] pub(crate) struct LinkageType { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -#[help] -#[diag(hir_analysis_auto_deref_reached_recursion_limit, code = E0055)] +#[help( + "consider increasing the recursion limit by adding a `#![recursion_limit = \"{$suggested_limit}\"]` attribute to your crate (`{$crate_name}`)" +)] +#[diag("reached the recursion limit while auto-dereferencing `{$ty}`", code = E0055)] pub(crate) struct AutoDerefReachedRecursionLimit<'a> { #[primary_span] - #[label] + #[label("deref recursion limit reached")] pub span: Span, pub ty: Ty<'a>, pub suggested_limit: Limit, @@ -567,96 +644,96 @@ pub(crate) struct AutoDerefReachedRecursionLimit<'a> { } #[derive(Diagnostic)] -#[diag(hir_analysis_where_clause_on_main, code = E0646)] +#[diag("`main` function is not allowed to have a `where` clause", code = E0646)] pub(crate) struct WhereClauseOnMain { #[primary_span] pub span: Span, - #[label] + #[label("`main` cannot have a `where` clause")] pub generics_span: Option, } #[derive(Diagnostic)] -#[diag(hir_analysis_track_caller_on_main)] +#[diag("`main` function is not allowed to be `#[track_caller]`")] pub(crate) struct TrackCallerOnMain { #[primary_span] - #[suggestion(applicability = "maybe-incorrect", code = "")] + #[suggestion("remove this annotation", applicability = "maybe-incorrect", code = "")] pub span: Span, - #[label(hir_analysis_track_caller_on_main)] + #[label("`main` function is not allowed to be `#[track_caller]`")] pub annotated: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_target_feature_on_main)] +#[diag("`main` function is not allowed to have `#[target_feature]`")] pub(crate) struct TargetFeatureOnMain { #[primary_span] - #[label(hir_analysis_target_feature_on_main)] + #[label("`main` function is not allowed to have `#[target_feature]`")] pub main: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_main_function_return_type_generic, code = E0131)] +#[diag("`main` function return type is not allowed to have generic parameters", code = E0131)] pub(crate) struct MainFunctionReturnTypeGeneric { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_main_function_async, code = E0752)] +#[diag("`main` function is not allowed to be `async`", code = E0752)] pub(crate) struct MainFunctionAsync { #[primary_span] pub span: Span, - #[label] + #[label("`main` function is not allowed to be `async`")] pub asyncness: Option, } #[derive(Diagnostic)] -#[diag(hir_analysis_main_function_generic_parameters, code = E0131)] +#[diag("`main` function is not allowed to have generic parameters", code = E0131)] pub(crate) struct MainFunctionGenericParameters { #[primary_span] pub span: Span, - #[label] + #[label("`main` cannot have generic parameters")] pub label_span: Option, } #[derive(Diagnostic)] -#[diag(hir_analysis_variadic_function_compatible_convention, code = E0045)] +#[diag("C-variadic functions with the {$convention} calling convention are not supported", code = E0045)] pub(crate) struct VariadicFunctionCompatibleConvention<'a> { #[primary_span] - #[label] + #[label("C-variadic function must have a compatible calling convention")] pub span: Span, pub convention: &'a str, } #[derive(Diagnostic)] pub(crate) enum CannotCaptureLateBound { - #[diag(hir_analysis_cannot_capture_late_bound_ty)] + #[diag("cannot capture late-bound type parameter in {$what}")] Type { #[primary_span] use_span: Span, - #[label] + #[label("parameter defined here")] def_span: Span, what: &'static str, }, - #[diag(hir_analysis_cannot_capture_late_bound_const)] + #[diag("cannot capture late-bound const parameter in {$what}")] Const { #[primary_span] use_span: Span, - #[label] + #[label("parameter defined here")] def_span: Span, what: &'static str, }, - #[diag(hir_analysis_cannot_capture_late_bound_lifetime)] + #[diag("cannot capture late-bound lifetime in {$what}")] Lifetime { #[primary_span] use_span: Span, - #[label] + #[label("lifetime defined here")] def_span: Span, what: &'static str, }, } #[derive(Diagnostic)] -#[diag(hir_analysis_variances_of)] +#[diag("{$variances}")] pub(crate) struct VariancesOf { #[primary_span] pub span: Span, @@ -664,7 +741,7 @@ pub(crate) struct VariancesOf { } #[derive(Diagnostic)] -#[diag(hir_analysis_type_of)] +#[diag("{$ty}")] pub(crate) struct TypeOf<'tcx> { #[primary_span] pub span: Span, @@ -672,30 +749,37 @@ pub(crate) struct TypeOf<'tcx> { } #[derive(Diagnostic)] -#[diag(hir_analysis_invalid_union_field, code = E0740)] +#[diag("field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union", code = E0740)] pub(crate) struct InvalidUnionField { #[primary_span] pub field_span: Span, #[subdiagnostic] pub sugg: InvalidUnionFieldSuggestion, - #[note] + #[note( + "union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>`" + )] pub note: (), } #[derive(Diagnostic)] -#[diag(hir_analysis_return_type_notation_on_non_rpitit)] +#[diag( + "return type notation used on function that is not `async` and does not return `impl Trait`" +)] pub(crate) struct ReturnTypeNotationOnNonRpitit<'tcx> { #[primary_span] pub span: Span, pub ty: Ty<'tcx>, - #[label] + #[label("this function must be `async` or return `impl Trait`")] pub fn_span: Option, - #[note] + #[note("function returns `{$ty}`, which is not compatible with associated type return bounds")] pub note: (), } #[derive(Subdiagnostic)] -#[multipart_suggestion(hir_analysis_invalid_union_field_sugg, applicability = "machine-applicable")] +#[multipart_suggestion( + "wrap the field type in `ManuallyDrop<...>`", + applicability = "machine-applicable" +)] pub(crate) struct InvalidUnionFieldSuggestion { #[suggestion_part(code = "std::mem::ManuallyDrop<")] pub lo: Span, @@ -704,27 +788,32 @@ pub(crate) struct InvalidUnionFieldSuggestion { } #[derive(Diagnostic)] -#[diag(hir_analysis_return_type_notation_equality_bound)] +#[diag("return type notation is not allowed to use type equality")] pub(crate) struct ReturnTypeNotationEqualityBound { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_placeholder_not_allowed_item_signatures, code = E0121)] +#[diag("the placeholder `_` is not allowed within types on item signatures for {$kind}", code = E0121)] pub(crate) struct PlaceholderNotAllowedItemSignatures { #[primary_span] - #[label] + #[label("not allowed in type signatures")] pub spans: Vec, pub kind: String, } #[derive(Diagnostic)] -#[diag(hir_analysis_associated_type_trait_uninferred_generic_params, code = E0212)] +#[diag("cannot use the {$what} of a trait with uninferred generic parameters", code = E0212)] pub(crate) struct AssociatedItemTraitUninferredGenericParams { #[primary_span] pub span: Span, - #[suggestion(style = "verbose", applicability = "maybe-incorrect", code = "{bound}")] + #[suggestion( + "use a fully qualified path with inferred lifetimes", + style = "verbose", + applicability = "maybe-incorrect", + code = "{bound}" + )] pub inferred_sugg: Option, pub bound: String, #[subdiagnostic] @@ -734,7 +823,7 @@ pub(crate) struct AssociatedItemTraitUninferredGenericParams { #[derive(Subdiagnostic)] #[multipart_suggestion( - hir_analysis_associated_type_trait_uninferred_generic_params_multipart_suggestion, + "use a fully qualified path with explicit lifetimes", applicability = "maybe-incorrect" )] pub(crate) struct AssociatedItemTraitUninferredGenericParamsMultipartSuggestion { @@ -747,11 +836,11 @@ pub(crate) struct AssociatedItemTraitUninferredGenericParamsMultipartSuggestion } #[derive(Diagnostic)] -#[diag(hir_analysis_enum_discriminant_overflowed, code = E0370)] -#[note] +#[diag("enum discriminant overflowed", code = E0370)] +#[note("explicitly set `{$item_name} = {$wrapped_discr}` if that is desired outcome")] pub(crate) struct EnumDiscriminantOverflowed { #[primary_span] - #[label] + #[label("overflowed on value after {$discr}")] pub span: Span, pub discr: String, pub item_name: Ident, @@ -759,16 +848,18 @@ pub(crate) struct EnumDiscriminantOverflowed { } #[derive(Diagnostic)] -#[diag(hir_analysis_paren_sugar_attribute)] -#[help] +#[diag( + "the `#[rustc_paren_sugar]` attribute is a temporary means of controlling which traits can use parenthetical notation" +)] +#[help("add `#![feature(unboxed_closures)]` to the crate attributes to use it")] pub(crate) struct ParenSugarAttribute { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_simd_ffi_highly_experimental)] -#[help] +#[diag("use of SIMD type{$snip} in FFI is highly experimental and may result in invalid code")] +#[help("add `#![feature(simd_ffi)]` to the crate attributes to enable")] pub(crate) struct SIMDFFIHighlyExperimental { #[primary_span] pub span: Span, @@ -777,18 +868,18 @@ pub(crate) struct SIMDFFIHighlyExperimental { #[derive(Diagnostic)] pub(crate) enum ImplNotMarkedDefault { - #[diag(hir_analysis_impl_not_marked_default, code = E0520)] - #[note] + #[diag("`{$ident}` specializes an item from a parent `impl`, but that item is not marked `default`", code = E0520)] + #[note("to specialize, `{$ident}` in the parent `impl` must be marked `default`")] Ok { #[primary_span] - #[label] + #[label("cannot specialize default item `{$ident}`")] span: Span, - #[label(hir_analysis_ok_label)] + #[label("parent `impl` is here")] ok_label: Span, ident: Ident, }, - #[diag(hir_analysis_impl_not_marked_default_err, code = E0520)] - #[note] + #[diag("`{$ident}` specializes an item from a parent `impl`, but that item is not marked `default`", code = E0520)] + #[note("parent implementation is in crate `{$cname}`")] Err { #[primary_span] span: Span, @@ -798,14 +889,14 @@ pub(crate) enum ImplNotMarkedDefault { } #[derive(LintDiagnostic)] -#[diag(hir_analysis_useless_impl_item)] +#[diag("this item cannot be used as its where bounds are not satisfied for the `Self` type")] pub(crate) struct UselessImplItem; #[derive(Diagnostic)] -#[diag(hir_analysis_missing_trait_item, code = E0046)] +#[diag("not all trait items implemented, missing: `{$missing_items_msg}`", code = E0046)] pub(crate) struct MissingTraitItem { #[primary_span] - #[label] + #[label("missing `{$missing_items_msg}` in implementation")] pub span: Span, #[subdiagnostic] pub missing_trait_item_label: Vec, @@ -817,7 +908,7 @@ pub(crate) struct MissingTraitItem { } #[derive(Subdiagnostic)] -#[label(hir_analysis_missing_trait_item_label)] +#[label("`{$item}` from trait")] pub(crate) struct MissingTraitItemLabel { #[primary_span] pub span: Span, @@ -826,7 +917,7 @@ pub(crate) struct MissingTraitItemLabel { #[derive(Subdiagnostic)] #[suggestion( - hir_analysis_missing_trait_item_suggestion, + "implement the missing item: `{$snippet}`", style = "tool-only", applicability = "has-placeholders", code = "{code}" @@ -840,7 +931,7 @@ pub(crate) struct MissingTraitItemSuggestion { #[derive(Subdiagnostic)] #[suggestion( - hir_analysis_missing_trait_item_suggestion, + "implement the missing item: `{$snippet}`", style = "hidden", applicability = "has-placeholders", code = "{code}" @@ -853,25 +944,25 @@ pub(crate) struct MissingTraitItemSuggestionNone { } #[derive(Diagnostic)] -#[diag(hir_analysis_missing_one_of_trait_item, code = E0046)] +#[diag("not all trait items implemented, missing one of: `{$missing_items_msg}`", code = E0046)] pub(crate) struct MissingOneOfTraitItem { #[primary_span] - #[label] + #[label("missing one of `{$missing_items_msg}` in implementation")] pub span: Span, - #[note] + #[note("required because of this annotation")] pub note: Option, pub missing_items_msg: String, } #[derive(Diagnostic)] -#[diag(hir_analysis_missing_trait_item_unstable, code = E0046)] -#[note] +#[diag("not all trait items implemented, missing: `{$missing_item_name}`", code = E0046)] +#[note("default implementation of `{$missing_item_name}` is unstable")] pub(crate) struct MissingTraitItemUnstable { #[primary_span] pub span: Span, - #[note(hir_analysis_some_note)] + #[note("use of unstable library feature `{$feature}`: {$reason}")] pub some_note: bool, - #[note(hir_analysis_none_note)] + #[note("use of unstable library feature `{$feature}`")] pub none_note: bool, pub missing_item_name: Ident, pub feature: Symbol, @@ -879,78 +970,78 @@ pub(crate) struct MissingTraitItemUnstable { } #[derive(Diagnostic)] -#[diag(hir_analysis_transparent_enum_variant, code = E0731)] +#[diag("transparent enum needs exactly one variant, but has {$number}", code = E0731)] pub(crate) struct TransparentEnumVariant { #[primary_span] - #[label] + #[label("needs exactly one variant, but has {$number}")] pub span: Span, - #[label(hir_analysis_multi_label)] + #[label("variant here")] pub spans: Vec, - #[label(hir_analysis_many_label)] + #[label("too many variants in `{$path}`")] pub many: Option, pub number: usize, pub path: String, } #[derive(Diagnostic)] -#[diag(hir_analysis_transparent_non_zero_sized_enum, code = E0690)] +#[diag("the variant of a transparent {$desc} needs at most one field with non-trivial size or alignment, but has {$field_count}", code = E0690)] pub(crate) struct TransparentNonZeroSizedEnum<'a> { #[primary_span] - #[label] + #[label("needs at most one field with non-trivial size or alignment, but has {$field_count}")] pub span: Span, - #[label(hir_analysis_labels)] + #[label("this field has non-zero size or requires alignment")] pub spans: Vec, pub field_count: usize, pub desc: &'a str, } #[derive(Diagnostic)] -#[diag(hir_analysis_transparent_non_zero_sized, code = E0690)] +#[diag("transparent {$desc} needs at most one field with non-trivial size or alignment, but has {$field_count}", code = E0690)] pub(crate) struct TransparentNonZeroSized<'a> { #[primary_span] - #[label] + #[label("needs at most one field with non-trivial size or alignment, but has {$field_count}")] pub span: Span, - #[label(hir_analysis_labels)] + #[label("this field has non-zero size or requires alignment")] pub spans: Vec, pub field_count: usize, pub desc: &'a str, } #[derive(Diagnostic)] -#[diag(hir_analysis_too_large_static)] +#[diag("extern static is too large for the target architecture")] pub(crate) struct TooLargeStatic { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_specialization_trait)] -#[help] +#[diag("implementing `rustc_specialization_trait` traits is unstable")] +#[help("add `#![feature(min_specialization)]` to the crate attributes to enable")] pub(crate) struct SpecializationTrait { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_closure_implicit_hrtb)] +#[diag("implicit types in closure signatures are forbidden when `for<...>` is present")] pub(crate) struct ClosureImplicitHrtb { #[primary_span] pub spans: Vec, - #[label] + #[label("`for<...>` is here")] pub for_sp: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_empty_specialization)] +#[diag("specialization impl does not specialize any associated items")] pub(crate) struct EmptySpecialization { #[primary_span] pub span: Span, - #[note] + #[note("impl is a specialization of this impl")] pub base_impl_span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_static_specialize)] +#[diag("cannot specialize on `'static` lifetime")] pub(crate) struct StaticSpecialize { #[primary_span] pub span: Span, @@ -958,12 +1049,12 @@ pub(crate) struct StaticSpecialize { #[derive(Diagnostic)] pub(crate) enum DropImplPolarity { - #[diag(hir_analysis_drop_impl_negative)] + #[diag("negative `Drop` impls are not supported")] Negative { #[primary_span] span: Span, }, - #[diag(hir_analysis_drop_impl_reservation)] + #[diag("reservation `Drop` impls are not supported")] Reservation { #[primary_span] span: Span, @@ -972,65 +1063,75 @@ pub(crate) enum DropImplPolarity { #[derive(Diagnostic)] pub(crate) enum ReturnTypeNotationIllegalParam { - #[diag(hir_analysis_return_type_notation_illegal_param_type)] + #[diag("return type notation is not allowed for functions that have type parameters")] Type { #[primary_span] span: Span, - #[label] + #[label("type parameter declared here")] param_span: Span, }, - #[diag(hir_analysis_return_type_notation_illegal_param_const)] + #[diag("return type notation is not allowed for functions that have const parameters")] Const { #[primary_span] span: Span, - #[label] + #[label("const parameter declared here")] param_span: Span, }, } #[derive(Diagnostic)] pub(crate) enum LateBoundInApit { - #[diag(hir_analysis_late_bound_type_in_apit)] + #[diag("`impl Trait` can only mention type parameters from an fn or impl")] Type { #[primary_span] span: Span, - #[label] + #[label("type parameter declared here")] param_span: Span, }, - #[diag(hir_analysis_late_bound_const_in_apit)] + #[diag("`impl Trait` can only mention const parameters from an fn or impl")] Const { #[primary_span] span: Span, - #[label] + #[label("const parameter declared here")] param_span: Span, }, - #[diag(hir_analysis_late_bound_lifetime_in_apit)] + #[diag("`impl Trait` can only mention lifetimes from an fn or impl")] Lifetime { #[primary_span] span: Span, - #[label] + #[label("lifetime declared here")] param_span: Span, }, } #[derive(LintDiagnostic)] -#[diag(hir_analysis_unused_associated_type_bounds)] -#[note] +#[diag("unnecessary associated type bound for dyn-incompatible associated type")] +#[note( + "this associated type has a `where Self: Sized` bound, and while the associated type can be specified, it cannot be used because trait objects are never `Sized`" +)] pub(crate) struct UnusedAssociatedTypeBounds { - #[suggestion(code = "")] + #[suggestion("remove this bound", code = "")] pub span: Span, } #[derive(LintDiagnostic)] -#[diag(hir_analysis_rpitit_refined)] -#[note] -#[note(hir_analysis_feedback_note)] +#[diag("impl trait in impl method signature does not match trait method signature")] +#[note( + "add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate" +)] +#[note( + "we are soliciting feedback, see issue #121718 for more information" +)] pub(crate) struct ReturnPositionImplTraitInTraitRefined<'tcx> { - #[suggestion(applicability = "maybe-incorrect", code = "{pre}{return_ty}{post}")] + #[suggestion( + "replace the return type so that it matches the trait", + applicability = "maybe-incorrect", + code = "{pre}{return_ty}{post}" + )] pub impl_return_span: Span, - #[label] + #[label("return type from trait method defined here")] pub trait_return_span: Option, - #[label(hir_analysis_unmatched_bound_label)] + #[label("this bound is stronger than that defined on the trait")] pub unmatched_bound: Option, pub pre: &'static str, @@ -1039,33 +1140,43 @@ pub(crate) struct ReturnPositionImplTraitInTraitRefined<'tcx> { } #[derive(LintDiagnostic)] -#[diag(hir_analysis_rpitit_refined_lifetimes)] -#[note] -#[note(hir_analysis_feedback_note)] +#[diag("impl trait in impl method captures fewer lifetimes than in trait")] +#[note( + "add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate" +)] +#[note( + "we are soliciting feedback, see issue #121718 for more information" +)] pub(crate) struct ReturnPositionImplTraitInTraitRefinedLifetimes { - #[suggestion(applicability = "maybe-incorrect", code = "{suggestion}")] + #[suggestion( + "modify the `use<..>` bound to capture the same lifetimes that the trait does", + applicability = "maybe-incorrect", + code = "{suggestion}" + )] pub suggestion_span: Span, pub suggestion: String, } #[derive(Diagnostic)] -#[diag(hir_analysis_inherent_ty_outside, code = E0390)] -#[help] +#[diag("cannot define inherent `impl` for a type outside of the crate where the type is defined", code = E0390)] +#[help("consider moving this inherent impl into the crate defining the type if possible")] pub(crate) struct InherentTyOutside { #[primary_span] - #[help(hir_analysis_span_help)] + #[help( + "alternatively add `#[rustc_has_incoherent_inherent_impls]` to the type and `#[rustc_allow_incoherent_impl]` to the relevant impl items" + )] pub span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_dispatch_from_dyn_repr, code = E0378)] +#[diag("structs implementing `DispatchFromDyn` may not have `#[repr(packed)]` or `#[repr(C)]`", code = E0378)] pub(crate) struct DispatchFromDynRepr { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_coerce_pointee_not_struct, code = E0802)] +#[diag("`derive(CoercePointee)` is only applicable to `struct`, instead of `{$kind}`", code = E0802)] pub(crate) struct CoercePointeeNotStruct { #[primary_span] pub span: Span, @@ -1073,65 +1184,65 @@ pub(crate) struct CoercePointeeNotStruct { } #[derive(Diagnostic)] -#[diag(hir_analysis_coerce_pointee_not_concrete_ty, code = E0802)] +#[diag("`derive(CoercePointee)` is only applicable to `struct`", code = E0802)] pub(crate) struct CoercePointeeNotConcreteType { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_coerce_pointee_no_user_validity_assertion, code = E0802)] +#[diag("asserting applicability of `derive(CoercePointee)` on a target data is forbidden", code = E0802)] pub(crate) struct CoercePointeeNoUserValidityAssertion { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_coerce_pointee_not_transparent, code = E0802)] +#[diag("`derive(CoercePointee)` is only applicable to `struct` with `repr(transparent)` layout", code = E0802)] pub(crate) struct CoercePointeeNotTransparent { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_coerce_pointee_no_field, code = E0802)] +#[diag("`CoercePointee` can only be derived on `struct`s with at least one field", code = E0802)] pub(crate) struct CoercePointeeNoField { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_inherent_ty_outside_relevant, code = E0390)] -#[help] +#[diag("cannot define inherent `impl` for a type outside of the crate where the type is defined", code = E0390)] +#[help("consider moving this inherent impl into the crate defining the type if possible")] pub(crate) struct InherentTyOutsideRelevant { #[primary_span] pub span: Span, - #[help(hir_analysis_span_help)] + #[help("alternatively add `#[rustc_allow_incoherent_impl]` to the relevant impl items")] pub help_span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_inherent_ty_outside_new, code = E0116)] -#[note] +#[diag("cannot define inherent `impl` for a type outside of the crate where the type is defined", code = E0116)] +#[note("define and implement a trait or new type instead")] pub(crate) struct InherentTyOutsideNew { #[primary_span] - #[label] + #[label("impl for type defined outside of crate")] pub span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_inherent_ty_outside_primitive, code = E0390)] -#[help] +#[diag("cannot define inherent `impl` for primitive types outside of `core`", code = E0390)] +#[help("consider moving this inherent impl into `core` if possible")] pub(crate) struct InherentTyOutsidePrimitive { #[primary_span] pub span: Span, - #[help(hir_analysis_span_help)] + #[help("alternatively add `#[rustc_allow_incoherent_impl]` to the relevant impl items")] pub help_span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_inherent_primitive_ty, code = E0390)] -#[help] +#[diag("cannot define inherent `impl` for primitive types", code = E0390)] +#[help("consider using an extension trait instead")] pub(crate) struct InherentPrimitiveTy<'a> { #[primary_span] pub span: Span, @@ -1140,32 +1251,34 @@ pub(crate) struct InherentPrimitiveTy<'a> { } #[derive(Subdiagnostic)] -#[note(hir_analysis_inherent_primitive_ty_note)] +#[note( + "you could also try moving the reference to uses of `{$subty}` (such as `self`) within the implementation" +)] pub(crate) struct InherentPrimitiveTyNote<'a> { pub subty: Ty<'a>, } #[derive(Diagnostic)] -#[diag(hir_analysis_inherent_dyn, code = E0785)] -#[note] +#[diag("cannot define inherent `impl` for a dyn auto trait", code = E0785)] +#[note("define and implement a new trait or type instead")] pub(crate) struct InherentDyn { #[primary_span] - #[label] + #[label("impl requires at least one non-auto trait")] pub span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_inherent_nominal, code = E0118)] -#[note] +#[diag("no nominal type found for inherent implementation", code = E0118)] +#[note("either implement a trait on it or create a newtype to wrap it instead")] pub(crate) struct InherentNominal { #[primary_span] - #[label] + #[label("impl requires a nominal type")] pub span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_dispatch_from_dyn_zst, code = E0378)] -#[note] +#[diag("the trait `DispatchFromDyn` may only be implemented for structs containing the field being coerced, ZST fields with 1 byte alignment that don't mention type/const generics, and nothing else", code = E0378)] +#[note("extra field `{$name}` of type `{$ty}` is not allowed")] pub(crate) struct DispatchFromDynZST<'a> { #[primary_span] pub span: Span, @@ -1174,28 +1287,30 @@ pub(crate) struct DispatchFromDynZST<'a> { } #[derive(Diagnostic)] -#[diag(hir_analysis_coerce_zero, code = E0374)] +#[diag("implementing `{$trait_name}` requires a field to be coerced", code = E0374)] pub(crate) struct CoerceNoField { #[primary_span] pub span: Span, pub trait_name: &'static str, - #[note(hir_analysis_coercion_between_struct_single_note)] + #[note("expected a single field to be coerced, none found")] pub note: bool, } #[derive(Diagnostic)] -#[diag(hir_analysis_coerce_multi, code = E0375)] +#[diag("implementing `{$trait_name}` does not allow multiple fields to be coerced", code = E0375)] pub(crate) struct CoerceMulti { pub trait_name: &'static str, #[primary_span] pub span: Span, pub number: usize, - #[note] + #[note( + "the trait `{$trait_name}` may only be implemented when a single field is being coerced" + )] pub fields: MultiSpan, } #[derive(Diagnostic)] -#[diag(hir_analysis_coerce_unsized_may, code = E0377)] +#[diag("the trait `{$trait_name}` may only be implemented for a coercion between structures", code = E0377)] pub(crate) struct CoerceUnsizedNonStruct { #[primary_span] pub span: Span, @@ -1203,7 +1318,7 @@ pub(crate) struct CoerceUnsizedNonStruct { } #[derive(Diagnostic)] -#[diag(hir_analysis_coerce_same_pat_kind)] +#[diag("only pattern types with the same pattern can be coerced between each other")] pub(crate) struct CoerceSamePatKind { #[primary_span] pub span: Span, @@ -1213,43 +1328,49 @@ pub(crate) struct CoerceSamePatKind { } #[derive(Diagnostic)] -#[diag(hir_analysis_coerce_unsized_may, code = E0377)] +#[diag("the trait `{$trait_name}` may only be implemented for a coercion between structures", code = E0377)] pub(crate) struct CoerceSameStruct { #[primary_span] pub span: Span, pub trait_name: &'static str, - #[note(hir_analysis_coercion_between_struct_same_note)] + #[note( + "expected coercion between the same definition; expected `{$source_path}`, found `{$target_path}`" + )] pub note: bool, pub source_path: String, pub target_path: String, } #[derive(Diagnostic)] -#[diag(hir_analysis_coerce_unsized_field_validity)] +#[diag( + "for `{$ty}` to have a valid implementation of `{$trait_name}`, it must be possible to coerce the field of type `{$field_ty}`" +)] pub(crate) struct CoerceFieldValidity<'tcx> { #[primary_span] pub span: Span, pub ty: Ty<'tcx>, pub trait_name: &'static str, - #[label] + #[label( + "`{$field_ty}` must be a pointer, reference, or smart pointer that is allowed to be unsized" + )] pub field_span: Span, pub field_ty: Ty<'tcx>, } #[derive(Diagnostic)] -#[diag(hir_analysis_trait_cannot_impl_for_ty, code = E0204)] +#[diag("the trait `{$trait_name}` cannot be implemented for this type", code = E0204)] pub(crate) struct TraitCannotImplForTy { #[primary_span] pub span: Span, pub trait_name: String, - #[label] + #[label("this field does not implement `{$trait_name}`")] pub label_spans: Vec, #[subdiagnostic] pub notes: Vec, } #[derive(Subdiagnostic)] -#[note(hir_analysis_requires_note)] +#[note("the `{$trait_name}` impl for `{$ty}` requires that `{$error_predicate}`")] pub(crate) struct ImplForTyRequires { #[primary_span] pub span: MultiSpan, @@ -1259,8 +1380,10 @@ pub(crate) struct ImplForTyRequires { } #[derive(Diagnostic)] -#[diag(hir_analysis_traits_with_default_impl, code = E0321)] -#[note] +#[diag("traits with a default impl, like `{$traits}`, cannot be implemented for {$problematic_kind} `{$self_ty}`", code = E0321)] +#[note( + "a trait object implements `{$traits}` if and only if `{$traits}` is one of the trait object's trait bounds" +)] pub(crate) struct TraitsWithDefaultImpl<'a> { #[primary_span] pub span: Span, @@ -1270,26 +1393,26 @@ pub(crate) struct TraitsWithDefaultImpl<'a> { } #[derive(Diagnostic)] -#[diag(hir_analysis_cross_crate_traits, code = E0321)] +#[diag("cross-crate traits with a default impl, like `{$traits}`, can only be implemented for a struct/enum type, not `{$self_ty}`", code = E0321)] pub(crate) struct CrossCrateTraits<'a> { #[primary_span] - #[label] + #[label("can't implement cross-crate trait with a default impl for non-struct/enum type")] pub span: Span, pub traits: String, pub self_ty: Ty<'a>, } #[derive(Diagnostic)] -#[diag(hir_analysis_cross_crate_traits_defined, code = E0321)] +#[diag("cross-crate traits with a default impl, like `{$traits}`, can only be implemented for a struct/enum type defined in the current crate", code = E0321)] pub(crate) struct CrossCrateTraitsDefined { #[primary_span] - #[label] + #[label("can't implement cross-crate trait for type in another crate")] pub span: Span, pub traits: String, } #[derive(Diagnostic)] -#[diag(hir_analysis_no_variant_named, code = E0599)] +#[diag("no variant named `{$ident}` found for enum `{$ty}`", code = E0599)] pub struct NoVariantNamed<'tcx> { #[primary_span] pub span: Span, @@ -1300,99 +1423,123 @@ pub struct NoVariantNamed<'tcx> { // FIXME(fmease): Deduplicate: #[derive(Diagnostic)] -#[diag(hir_analysis_ty_param_first_local, code = E0210)] -#[note] +#[diag("type parameter `{$param}` must be covered by another type when it appears before the first local type (`{$local_type}`)", code = E0210)] +#[note( + "implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type" +)] pub(crate) struct TyParamFirstLocal<'tcx> { #[primary_span] - #[label] + #[label( + "type parameter `{$param}` must be covered by another type when it appears before the first local type (`{$local_type}`)" + )] pub span: Span, - #[note(hir_analysis_case_note)] + #[note( + "in this case, 'before' refers to the following order: `impl<..> ForeignTrait for T0`, where `T0` is the first and `Tn` is the last" + )] pub note: (), pub param: Ident, pub local_type: Ty<'tcx>, } #[derive(LintDiagnostic)] -#[diag(hir_analysis_ty_param_first_local, code = E0210)] -#[note] +#[diag("type parameter `{$param}` must be covered by another type when it appears before the first local type (`{$local_type}`)", code = E0210)] +#[note( + "implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type" +)] pub(crate) struct TyParamFirstLocalLint<'tcx> { - #[label] + #[label( + "type parameter `{$param}` must be covered by another type when it appears before the first local type (`{$local_type}`)" + )] pub span: Span, - #[note(hir_analysis_case_note)] + #[note( + "in this case, 'before' refers to the following order: `impl<..> ForeignTrait for T0`, where `T0` is the first and `Tn` is the last" + )] pub note: (), pub param: Ident, pub local_type: Ty<'tcx>, } #[derive(Diagnostic)] -#[diag(hir_analysis_ty_param_some, code = E0210)] -#[note] +#[diag("type parameter `{$param}` must be used as the type parameter for some local type (e.g., `MyStruct<{$param}>`)", code = E0210)] +#[note( + "implementing a foreign trait is only possible if at least one of the types for which it is implemented is local" +)] pub(crate) struct TyParamSome { #[primary_span] - #[label] + #[label("type parameter `{$param}` must be used as the type parameter for some local type")] pub span: Span, - #[note(hir_analysis_only_note)] + #[note("only traits defined in the current crate can be implemented for a type parameter")] pub note: (), pub param: Ident, } #[derive(LintDiagnostic)] -#[diag(hir_analysis_ty_param_some, code = E0210)] -#[note] +#[diag("type parameter `{$param}` must be used as the type parameter for some local type (e.g., `MyStruct<{$param}>`)", code = E0210)] +#[note( + "implementing a foreign trait is only possible if at least one of the types for which it is implemented is local" +)] pub(crate) struct TyParamSomeLint { - #[label] + #[label("type parameter `{$param}` must be used as the type parameter for some local type")] pub span: Span, - #[note(hir_analysis_only_note)] + #[note("only traits defined in the current crate can be implemented for a type parameter")] pub note: (), pub param: Ident, } #[derive(Diagnostic)] pub(crate) enum OnlyCurrentTraits { - #[diag(hir_analysis_only_current_traits_outside, code = E0117)] + #[diag("only traits defined in the current crate can be implemented for types defined outside of the crate", code = E0117)] Outside { #[primary_span] span: Span, - #[note(hir_analysis_only_current_traits_note_uncovered)] - #[note(hir_analysis_only_current_traits_note_more_info)] - #[note(hir_analysis_only_current_traits_note)] + #[note("impl doesn't have any local type before any uncovered type parameters")] + #[note( + "for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules" + )] + #[note("define and implement a trait or new type instead")] note: (), }, - #[diag(hir_analysis_only_current_traits_primitive, code = E0117)] + #[diag("only traits defined in the current crate can be implemented for primitive types", code = E0117)] Primitive { #[primary_span] span: Span, - #[note(hir_analysis_only_current_traits_note_uncovered)] - #[note(hir_analysis_only_current_traits_note_more_info)] - #[note(hir_analysis_only_current_traits_note)] + #[note("impl doesn't have any local type before any uncovered type parameters")] + #[note( + "for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules" + )] + #[note("define and implement a trait or new type instead")] note: (), }, - #[diag(hir_analysis_only_current_traits_arbitrary, code = E0117)] + #[diag("only traits defined in the current crate can be implemented for arbitrary types", code = E0117)] Arbitrary { #[primary_span] span: Span, - #[note(hir_analysis_only_current_traits_note_uncovered)] - #[note(hir_analysis_only_current_traits_note_more_info)] - #[note(hir_analysis_only_current_traits_note)] + #[note("impl doesn't have any local type before any uncovered type parameters")] + #[note( + "for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules" + )] + #[note("define and implement a trait or new type instead")] note: (), }, } #[derive(Subdiagnostic)] -#[label(hir_analysis_only_current_traits_opaque)] +#[label( + "type alias impl trait is treated as if it were foreign, because its hidden type could be from a foreign crate" +)] pub(crate) struct OnlyCurrentTraitsOpaque { #[primary_span] pub span: Span, } #[derive(Subdiagnostic)] -#[label(hir_analysis_only_current_traits_foreign)] +#[label("this is not defined in the current crate because this is a foreign trait")] pub(crate) struct OnlyCurrentTraitsForeign { #[primary_span] pub span: Span, } #[derive(Subdiagnostic)] -#[label(hir_analysis_only_current_traits_name)] +#[label("this is not defined in the current crate because {$name} are always foreign")] pub(crate) struct OnlyCurrentTraitsName<'a> { #[primary_span] pub span: Span, @@ -1400,7 +1547,7 @@ pub(crate) struct OnlyCurrentTraitsName<'a> { } #[derive(Subdiagnostic)] -#[label(hir_analysis_only_current_traits_pointer)] +#[label("`{$pointer}` is not defined in the current crate because raw pointers are always foreign")] pub(crate) struct OnlyCurrentTraitsPointer<'a> { #[primary_span] pub span: Span, @@ -1408,7 +1555,7 @@ pub(crate) struct OnlyCurrentTraitsPointer<'a> { } #[derive(Subdiagnostic)] -#[label(hir_analysis_only_current_traits_ty)] +#[label("`{$ty}` is not defined in the current crate")] pub(crate) struct OnlyCurrentTraitsTy<'a> { #[primary_span] pub span: Span, @@ -1416,7 +1563,7 @@ pub(crate) struct OnlyCurrentTraitsTy<'a> { } #[derive(Subdiagnostic)] -#[label(hir_analysis_only_current_traits_adt)] +#[label("`{$name}` is not defined in the current crate")] pub(crate) struct OnlyCurrentTraitsAdt { #[primary_span] pub span: Span, @@ -1425,7 +1572,7 @@ pub(crate) struct OnlyCurrentTraitsAdt { #[derive(Subdiagnostic)] #[multipart_suggestion( - hir_analysis_only_current_traits_pointer_sugg, + "consider introducing a new wrapper type", applicability = "maybe-incorrect" )] pub(crate) struct OnlyCurrentTraitsPointerSugg<'a> { @@ -1438,104 +1585,120 @@ pub(crate) struct OnlyCurrentTraitsPointerSugg<'a> { } #[derive(Diagnostic)] -#[diag(hir_analysis_not_supported_delegation)] +#[diag("{$descr}")] pub(crate) struct UnsupportedDelegation<'a> { #[primary_span] pub span: Span, pub descr: &'a str, - #[label] + #[label("callee defined here")] pub callee_span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_method_should_return_future)] +#[diag("method should be `async` or return a future, but it is synchronous")] pub(crate) struct MethodShouldReturnFuture { #[primary_span] pub span: Span, pub method_name: Ident, - #[note] + #[note("this method is `async` so it expects a future to be returned")] pub trait_item_span: Option, } #[derive(Diagnostic)] -#[diag(hir_analysis_unused_generic_parameter)] +#[diag("{$param_def_kind} `{$param_name}` is never used")] pub(crate) struct UnusedGenericParameter { #[primary_span] - #[label] + #[label("unused {$param_def_kind}")] pub span: Span, pub param_name: Ident, pub param_def_kind: &'static str, - #[label(hir_analysis_usage_spans)] + #[label("`{$param_name}` is named here, but is likely unused in the containing type")] pub usage_spans: Vec, #[subdiagnostic] pub help: UnusedGenericParameterHelp, - #[help(hir_analysis_const_param_help)] + #[help( + "if you intended `{$param_name}` to be a const parameter, use `const {$param_name}: /* Type */` instead" + )] pub const_param_help: bool, } #[derive(Diagnostic)] -#[diag(hir_analysis_recursive_generic_parameter)] +#[diag("{$param_def_kind} `{$param_name}` is only used recursively")] pub(crate) struct RecursiveGenericParameter { #[primary_span] pub spans: Vec, - #[label] + #[label("{$param_def_kind} must be used non-recursively in the definition")] pub param_span: Span, pub param_name: Ident, pub param_def_kind: &'static str, #[subdiagnostic] pub help: UnusedGenericParameterHelp, - #[note] + #[note( + "all type parameters must be used in a non-recursive way in order to constrain their variance" + )] pub note: (), } #[derive(Subdiagnostic)] pub(crate) enum UnusedGenericParameterHelp { - #[help(hir_analysis_unused_generic_parameter_adt_help)] + #[help( + "consider removing `{$param_name}`, referring to it in a field, or using a marker such as `{$phantom_data}`" + )] Adt { param_name: Ident, phantom_data: String }, - #[help(hir_analysis_unused_generic_parameter_adt_no_phantom_data_help)] + #[help("consider removing `{$param_name}` or referring to it in a field")] AdtNoPhantomData { param_name: Ident }, - #[help(hir_analysis_unused_generic_parameter_ty_alias_help)] + #[help("consider removing `{$param_name}` or referring to it in the body of the type alias")] TyAlias { param_name: Ident }, } #[derive(Diagnostic)] -#[diag(hir_analysis_unconstrained_generic_parameter)] +#[diag( + "the {$param_def_kind} `{$param_name}` is not constrained by the impl trait, self type, or predicates" +)] pub(crate) struct UnconstrainedGenericParameter { #[primary_span] - #[label] + #[label("unconstrained {$param_def_kind}")] pub span: Span, pub param_name: Ident, pub param_def_kind: &'static str, - #[note(hir_analysis_const_param_note)] + #[note("expressions using a const parameter must map each value to a distinct output value")] pub const_param_note: bool, - #[note(hir_analysis_const_param_note2)] + #[note( + "proving the result of expressions other than the parameter are unique is not supported" + )] pub const_param_note2: bool, } #[derive(Diagnostic)] -#[diag(hir_analysis_opaque_captures_higher_ranked_lifetime, code = E0657)] +#[diag("`impl Trait` cannot capture {$bad_place}", code = E0657)] pub(crate) struct OpaqueCapturesHigherRankedLifetime { #[primary_span] pub span: MultiSpan, - #[label] + #[label("`impl Trait` implicitly captures all lifetimes in scope")] pub label: Option, - #[note] + #[note("lifetime declared here")] pub decl_span: MultiSpan, pub bad_place: &'static str, } #[derive(Subdiagnostic)] pub(crate) enum InvalidReceiverTyHint { - #[note(hir_analysis_invalid_receiver_ty_help_weak_note)] + #[note( + "`Weak` does not implement `Receiver` because it has methods that may shadow the referent; consider wrapping your `Weak` in a newtype wrapper for which you implement `Receiver`" + )] Weak, - #[note(hir_analysis_invalid_receiver_ty_help_nonnull_note)] + #[note( + "`NonNull` does not implement `Receiver` because it has methods that may shadow the referent; consider wrapping your `NonNull` in a newtype wrapper for which you implement `Receiver`" + )] NonNull, } #[derive(Diagnostic)] -#[diag(hir_analysis_invalid_receiver_ty_no_arbitrary_self_types, code = E0307)] -#[note] -#[help(hir_analysis_invalid_receiver_ty_help_no_arbitrary_self_types)] +#[diag("invalid `self` parameter type: `{$receiver_ty}`", code = E0307)] +#[note("type of `self` must be `Self` or a type that dereferences to it")] +#[help( + "consider changing to `self`, `&self`, `&mut self`, `self: Box`, `self: Rc`, `self: Arc`, or `self: Pin

` (where P is one of the previous types except `Self`)" +)] pub(crate) struct InvalidReceiverTyNoArbitrarySelfTypes<'tcx> { #[primary_span] pub span: Span, @@ -1543,9 +1706,11 @@ pub(crate) struct InvalidReceiverTyNoArbitrarySelfTypes<'tcx> { } #[derive(Diagnostic)] -#[diag(hir_analysis_invalid_receiver_ty, code = E0307)] -#[note] -#[help(hir_analysis_invalid_receiver_ty_help)] +#[diag("invalid `self` parameter type: `{$receiver_ty}`", code = E0307)] +#[note("type of `self` must be `Self` or some type implementing `Receiver`")] +#[help( + "consider changing to `self`, `&self`, `&mut self`, or a type implementing `Receiver` such as `self: Box`, `self: Rc`, or `self: Arc`" +)] pub(crate) struct InvalidReceiverTy<'tcx> { #[primary_span] pub span: Span, @@ -1555,9 +1720,11 @@ pub(crate) struct InvalidReceiverTy<'tcx> { } #[derive(Diagnostic)] -#[diag(hir_analysis_invalid_generic_receiver_ty, code = E0801)] -#[note] -#[help(hir_analysis_invalid_generic_receiver_ty_help)] +#[diag("invalid generic `self` parameter type: `{$receiver_ty}`", code = E0801)] +#[note("type of `self` must not be a method generic parameter type")] +#[help( + "use a concrete type such as `self`, `&self`, `&mut self`, `self: Box`, `self: Rc`, `self: Arc`, or `self: Pin

` (where P is one of the previous types except `Self`)" +)] pub(crate) struct InvalidGenericReceiverTy<'tcx> { #[primary_span] pub span: Span, @@ -1565,28 +1732,32 @@ pub(crate) struct InvalidGenericReceiverTy<'tcx> { } #[derive(Diagnostic)] -#[diag(hir_analysis_cmse_inputs_stack_spill, code = E0798)] -#[note] +#[diag("arguments for `{$abi}` function too large to pass via registers", code = E0798)] +#[note( + "functions with the `{$abi}` ABI must pass all their arguments via the 4 32-bit argument registers" +)] pub(crate) struct CmseInputsStackSpill { #[primary_span] - #[label] + #[label("does not fit in the available registers")] pub spans: Vec, pub abi: ExternAbi, } #[derive(Diagnostic)] -#[diag(hir_analysis_cmse_output_stack_spill, code = E0798)] -#[note(hir_analysis_note1)] -#[note(hir_analysis_note2)] +#[diag("return value of `{$abi}` function too large to pass via registers", code = E0798)] +#[note("functions with the `{$abi}` ABI must pass their result via the available return registers")] +#[note( + "the result must either be a (transparently wrapped) i64, u64 or f64, or be at most 4 bytes in size" +)] pub(crate) struct CmseOutputStackSpill { #[primary_span] - #[label] + #[label("this type doesn't fit in the available registers")] pub span: Span, pub abi: ExternAbi, } #[derive(Diagnostic)] -#[diag(hir_analysis_cmse_generic, code = E0798)] +#[diag("generics are not allowed in `extern {$abi}` signatures", code = E0798)] pub(crate) struct CmseGeneric { #[primary_span] pub span: Span, @@ -1594,7 +1765,7 @@ pub(crate) struct CmseGeneric { } #[derive(Diagnostic)] -#[diag(hir_analysis_cmse_impl_trait, code = E0798)] +#[diag("`impl Trait` is not allowed in `extern {$abi}` signatures", code = E0798)] pub(crate) struct CmseImplTrait { #[primary_span] pub span: Span, @@ -1602,14 +1773,14 @@ pub(crate) struct CmseImplTrait { } #[derive(Diagnostic)] -#[diag(hir_analysis_bad_return_type_notation_position)] +#[diag("return type notation not allowed in this position yet")] pub(crate) struct BadReturnTypeNotation { #[primary_span] pub span: Span, } #[derive(LintDiagnostic)] -#[diag(hir_analysis_supertrait_item_shadowing)] +#[diag("trait item `{$item}` from `{$subtrait}` shadows identically named item from supertrait")] pub(crate) struct SupertraitItemShadowing { pub item: Symbol, pub subtrait: Symbol, @@ -1619,13 +1790,13 @@ pub(crate) struct SupertraitItemShadowing { #[derive(Subdiagnostic)] pub(crate) enum SupertraitItemShadowee { - #[note(hir_analysis_supertrait_item_shadowee)] + #[note("item from `{$supertrait}` is shadowed by a subtrait item")] Labeled { #[primary_span] span: Span, supertrait: Symbol, }, - #[note(hir_analysis_supertrait_item_multiple_shadowee)] + #[note("items from several supertraits are shadowed: {$traits}")] Several { #[primary_span] spans: MultiSpan, @@ -1634,23 +1805,25 @@ pub(crate) enum SupertraitItemShadowee { } #[derive(Diagnostic)] -#[diag(hir_analysis_dyn_trait_assoc_item_binding_mentions_self)] +#[diag("{$kind} binding in trait object type mentions `Self`")] pub(crate) struct DynTraitAssocItemBindingMentionsSelf { #[primary_span] - #[label] + #[label("contains a mention of `Self`")] pub span: Span, pub kind: &'static str, - #[label(hir_analysis_binding_label)] + #[label("this binding mentions `Self`")] pub binding: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_abi_custom_clothed_function)] +#[diag( + "items with the \"custom\" ABI can only be declared externally or defined via naked functions" +)] pub(crate) struct AbiCustomClothedFunction { #[primary_span] pub span: Span, #[suggestion( - hir_analysis_suggestion, + "convert this to an `#[unsafe(naked)]` function", applicability = "maybe-incorrect", code = "#[unsafe(naked)]\n", style = "short" @@ -1659,47 +1832,49 @@ pub(crate) struct AbiCustomClothedFunction { } #[derive(Diagnostic)] -#[diag(hir_analysis_async_drop_without_sync_drop)] -#[help] +#[diag("`AsyncDrop` impl without `Drop` impl")] +#[help( + "type implementing `AsyncDrop` trait must also implement `Drop` trait to be used in sync context and unwinds" +)] pub(crate) struct AsyncDropWithoutSyncDrop { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_lifetimes_or_bounds_mismatch_on_eii)] +#[diag("lifetime parameters or bounds of `{$ident}` do not match the declaration")] pub(crate) struct LifetimesOrBoundsMismatchOnEii { #[primary_span] - #[label] + #[label("lifetimes do not match")] pub span: Span, - #[label(hir_analysis_generics_label)] + #[label("lifetimes in impl do not match this signature")] pub generics_span: Span, - #[label(hir_analysis_where_label)] + #[label("this `where` clause might not match the one in the trait")] pub where_span: Option, - #[label(hir_analysis_bounds_label)] + #[label("this bound might be missing in the impl")] pub bounds_span: Vec, pub ident: Symbol, } #[derive(Diagnostic)] -#[diag(hir_analysis_eii_with_generics)] -#[help] +#[diag("`{$impl_name}` cannot have generic parameters other than lifetimes")] +#[help("`#[{$eii_name}]` marks the implementation of an \"externally implementable item\"")] pub(crate) struct EiiWithGenerics { #[primary_span] pub span: Span, - #[label] + #[label("required by this attribute")] pub attr: Span, pub eii_name: Symbol, pub impl_name: Symbol, } #[derive(Diagnostic)] -#[diag(hir_analysis_impl_unpin_for_pin_projected_type)] +#[diag("explicit impls for the `Unpin` trait are not permitted for structurally pinned types")] pub(crate) struct ImplUnpinForPinProjectedType { #[primary_span] - #[label] + #[label("impl of `Unpin` not allowed")] pub span: Span, - #[help] + #[help("`{$adt_name}` is structurally pinned because it is marked as `#[pin_v2]`")] pub adt_span: Span, pub adt_name: Symbol, } diff --git a/compiler/rustc_hir_analysis/src/errors/precise_captures.rs b/compiler/rustc_hir_analysis/src/errors/precise_captures.rs index 8a83866b7fa46..f9e62b8ebcf87 100644 --- a/compiler/rustc_hir_analysis/src/errors/precise_captures.rs +++ b/compiler/rustc_hir_analysis/src/errors/precise_captures.rs @@ -3,48 +3,54 @@ use rustc_macros::Diagnostic; use rustc_span::{Span, Symbol}; #[derive(Diagnostic)] -#[diag(hir_analysis_param_not_captured)] -#[note] +#[diag("`impl Trait` must mention all {$kind} parameters in scope in `use<...>`")] +#[note( + "currently, all {$kind} parameters are required to be mentioned in the precise captures list" +)] pub(crate) struct ParamNotCaptured { #[primary_span] pub opaque_span: Span, - #[label] + #[label("{$kind} parameter is implicitly captured by this `impl Trait`")] pub param_span: Span, pub kind: &'static str, } #[derive(Diagnostic)] -#[diag(hir_analysis_self_ty_not_captured)] -#[note] +#[diag("`impl Trait` must mention the `Self` type of the trait in `use<...>`")] +#[note("currently, all type parameters are required to be mentioned in the precise captures list")] pub(crate) struct SelfTyNotCaptured { #[primary_span] pub opaque_span: Span, - #[label] + #[label("`Self` type parameter is implicitly captured by this `impl Trait`")] pub trait_span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_lifetime_not_captured)] +#[diag( + "`impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list" +)] pub(crate) struct LifetimeNotCaptured { #[primary_span] pub use_span: Span, - #[label(hir_analysis_param_label)] + #[label("this lifetime parameter is captured")] pub param_span: Span, - #[label] + #[label("lifetime captured due to being mentioned in the bounds of the `impl Trait`")] pub opaque_span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_lifetime_implicitly_captured)] +#[diag( + "`impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list" +)] pub(crate) struct LifetimeImplicitlyCaptured { #[primary_span] pub opaque_span: Span, - #[label(hir_analysis_param_label)] + #[label("all lifetime parameters originating from a trait are captured implicitly")] pub param_span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_bad_precise_capture)] +#[diag("expected {$kind} parameter in `use<...>` precise captures list, found {$found}")] pub(crate) struct BadPreciseCapture { #[primary_span] pub span: Span, @@ -53,31 +59,31 @@ pub(crate) struct BadPreciseCapture { } #[derive(Diagnostic)] -#[diag(hir_analysis_precise_capture_self_alias, code = E0799)] +#[diag("`Self` can't be captured in `use<...>` precise captures list, since it is an alias", code = E0799)] pub(crate) struct PreciseCaptureSelfAlias { #[primary_span] pub span: Span, - #[label] + #[label("`Self` is not a generic argument, but an alias to the type of the {$what}")] pub self_span: Span, pub what: &'static str, } #[derive(Diagnostic)] -#[diag(hir_analysis_duplicate_precise_capture)] +#[diag("cannot capture parameter `{$name}` twice")] pub(crate) struct DuplicatePreciseCapture { #[primary_span] pub first_span: Span, pub name: Symbol, - #[label] + #[label("parameter captured again here")] pub second_span: Span, } #[derive(Diagnostic)] -#[diag(hir_analysis_lifetime_must_be_first)] +#[diag("lifetime parameter `{$name}` must be listed before non-lifetime parameters")] pub(crate) struct LifetimesMustBeFirst { #[primary_span] pub lifetime_span: Span, pub name: Symbol, - #[label] + #[label("move the lifetime before this parameter")] pub other_span: Span, } diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs index d114691b25e82..36dae4c2798e9 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs @@ -3,8 +3,8 @@ use rustc_data_structures::sorted_map::SortedMap; use rustc_data_structures::unord::UnordMap; use rustc_errors::codes::*; use rustc_errors::{ - Applicability, Diag, ErrorGuaranteed, MultiSpan, SuggestionStyle, listify, pluralize, - struct_span_code_err, + Applicability, Diag, ErrorGuaranteed, MultiSpan, SuggestionStyle, inline_fluent, listify, + pluralize, struct_span_code_err, }; use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def_id::DefId; @@ -31,7 +31,6 @@ use crate::errors::{ self, AssocItemConstraintsNotAllowedHere, ManualImplementation, ParenthesizedFnTraitExpansion, TraitObjectDeclaredWithNoTraits, }; -use crate::fluent_generated as fluent; use crate::hir_ty_lowering::{AssocItemQSelf, HirTyLowerer}; impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { @@ -305,7 +304,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { // was also not an exact match, so we also suggest changing it. err.span_suggestion_verbose( assoc_ident.span, - fluent::hir_analysis_assoc_item_not_found_similar_in_other_trait_with_bound_sugg, + inline_fluent!("...and changing the associated {$assoc_kind} name"), suggested_name, Applicability::MaybeIncorrect, ); diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index f7a1434359593..37c8cece1bf02 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -102,8 +102,6 @@ use rustc_trait_selection::traits; pub use crate::collect::suggest_impl_trait; use crate::hir_ty_lowering::HirTyLowerer; -rustc_fluent_macro::fluent_messages! { "../messages.ftl" } - fn check_c_variadic_abi(tcx: TyCtxt<'_>, decl: &hir::FnDecl<'_>, abi: ExternAbi, span: Span) { if !decl.c_variadic { // Not even a variadic function.