2022-10-20 17:51:37 +02:00
|
|
|
//! Errors emitted by `rustc_hir_analysis`.
|
2022-09-28 10:21:33 +01:00
|
|
|
|
2022-09-18 11:45:41 -04:00
|
|
|
use rustc_errors::IntoDiagnostic;
|
2022-09-05 00:15:50 -04:00
|
|
|
use rustc_errors::{error_code, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler};
|
2022-10-20 17:51:37 +02:00
|
|
|
use rustc_macros::{Diagnostic, LintDiagnostic};
|
2022-04-07 22:46:53 +04:00
|
|
|
use rustc_middle::ty::Ty;
|
2022-09-05 17:26:57 -04:00
|
|
|
use rustc_span::{symbol::Ident, Span, Symbol};
|
2020-08-27 20:09:22 +10:00
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(hir_analysis_unrecognized_atomic_operation, code = "E0092")]
|
2020-08-27 20:09:22 +10:00
|
|
|
pub struct UnrecognizedAtomicOperation<'a> {
|
2022-03-31 08:50:45 +01:00
|
|
|
#[primary_span]
|
2022-03-31 10:24:46 +01:00
|
|
|
#[label]
|
2020-08-27 20:09:22 +10:00
|
|
|
pub span: Span,
|
|
|
|
pub op: &'a str,
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(hir_analysis_wrong_number_of_generic_arguments_to_intrinsic, code = "E0094")]
|
2021-07-01 13:52:44 +02:00
|
|
|
pub struct WrongNumberOfGenericArgumentsToIntrinsic<'a> {
|
2022-03-31 08:50:45 +01:00
|
|
|
#[primary_span]
|
2022-03-31 10:24:46 +01:00
|
|
|
#[label]
|
2020-08-27 20:09:22 +10:00
|
|
|
pub span: Span,
|
|
|
|
pub found: usize,
|
|
|
|
pub expected: usize,
|
2021-06-08 20:38:43 +02:00
|
|
|
pub descr: &'a str,
|
2020-08-27 20:09:22 +10:00
|
|
|
}
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(hir_analysis_unrecognized_intrinsic_function, code = "E0093")]
|
2020-08-27 20:09:22 +10:00
|
|
|
pub struct UnrecognizedIntrinsicFunction {
|
2022-03-31 08:50:45 +01:00
|
|
|
#[primary_span]
|
2022-03-31 10:24:46 +01:00
|
|
|
#[label]
|
2020-08-27 20:09:22 +10:00
|
|
|
pub span: Span,
|
|
|
|
pub name: Symbol,
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(hir_analysis_lifetimes_or_bounds_mismatch_on_trait, code = "E0195")]
|
2020-08-27 20:09:22 +10:00
|
|
|
pub struct LifetimesOrBoundsMismatchOnTrait {
|
2022-03-31 08:50:45 +01:00
|
|
|
#[primary_span]
|
2022-03-31 10:24:46 +01:00
|
|
|
#[label]
|
2020-08-27 20:09:22 +10:00
|
|
|
pub span: Span,
|
2022-10-22 11:07:54 +02:00
|
|
|
#[label(generics_label)]
|
2020-08-27 20:09:22 +10:00
|
|
|
pub generics_span: Option<Span>,
|
|
|
|
pub item_kind: &'static str,
|
|
|
|
pub ident: Ident,
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(hir_analysis_drop_impl_on_wrong_item, code = "E0120")]
|
2020-08-27 20:09:22 +10:00
|
|
|
pub struct DropImplOnWrongItem {
|
2022-03-31 08:50:45 +01:00
|
|
|
#[primary_span]
|
2022-03-31 10:24:46 +01:00
|
|
|
#[label]
|
2020-08-27 20:09:22 +10:00
|
|
|
pub span: Span,
|
|
|
|
}
|
2020-08-27 20:00:21 +10:00
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(hir_analysis_field_already_declared, code = "E0124")]
|
2020-08-27 20:00:21 +10:00
|
|
|
pub struct FieldAlreadyDeclared {
|
|
|
|
pub field_name: Ident,
|
2022-03-31 08:50:45 +01:00
|
|
|
#[primary_span]
|
2022-03-31 10:24:46 +01:00
|
|
|
#[label]
|
2020-08-27 20:00:21 +10:00
|
|
|
pub span: Span,
|
2022-10-22 11:07:54 +02:00
|
|
|
#[label(previous_decl_label)]
|
2020-08-27 20:00:21 +10:00
|
|
|
pub prev_span: Span,
|
|
|
|
}
|
2020-08-27 20:09:22 +10:00
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(hir_analysis_copy_impl_on_type_with_dtor, code = "E0184")]
|
2020-08-27 20:09:22 +10:00
|
|
|
pub struct CopyImplOnTypeWithDtor {
|
2022-03-31 08:50:45 +01:00
|
|
|
#[primary_span]
|
2022-03-31 10:24:46 +01:00
|
|
|
#[label]
|
2020-08-27 20:09:22 +10:00
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(hir_analysis_multiple_relaxed_default_bounds, code = "E0203")]
|
2020-08-27 20:09:22 +10:00
|
|
|
pub struct MultipleRelaxedDefaultBounds {
|
2022-03-31 08:50:45 +01:00
|
|
|
#[primary_span]
|
2020-08-27 20:09:22 +10:00
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(hir_analysis_copy_impl_on_non_adt, code = "E0206")]
|
2020-08-27 20:09:22 +10:00
|
|
|
pub struct CopyImplOnNonAdt {
|
2022-03-31 08:50:45 +01:00
|
|
|
#[primary_span]
|
2022-03-31 10:24:46 +01:00
|
|
|
#[label]
|
2020-08-27 20:09:22 +10:00
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(hir_analysis_trait_object_declared_with_no_traits, code = "E0224")]
|
2020-08-27 20:09:22 +10:00
|
|
|
pub struct TraitObjectDeclaredWithNoTraits {
|
2022-03-31 08:50:45 +01:00
|
|
|
#[primary_span]
|
2020-08-27 20:09:22 +10:00
|
|
|
pub span: Span,
|
2022-10-22 11:07:54 +02:00
|
|
|
#[label(alias_span)]
|
2022-05-09 19:03:37 +02:00
|
|
|
pub trait_alias_span: Option<Span>,
|
2020-08-27 20:09:22 +10:00
|
|
|
}
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(hir_analysis_ambiguous_lifetime_bound, code = "E0227")]
|
2020-08-27 20:09:22 +10:00
|
|
|
pub struct AmbiguousLifetimeBound {
|
2022-03-31 08:50:45 +01:00
|
|
|
#[primary_span]
|
2020-08-27 20:09:22 +10:00
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(hir_analysis_assoc_type_binding_not_allowed, code = "E0229")]
|
2020-08-27 20:09:22 +10:00
|
|
|
pub struct AssocTypeBindingNotAllowed {
|
2022-03-31 08:50:45 +01:00
|
|
|
#[primary_span]
|
2022-03-31 10:24:46 +01:00
|
|
|
#[label]
|
2020-08-27 20:09:22 +10:00
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(hir_analysis_typeof_reserved_keyword_used, code = "E0516")]
|
2022-04-07 22:46:53 +04:00
|
|
|
pub struct TypeofReservedKeywordUsed<'tcx> {
|
|
|
|
pub ty: Ty<'tcx>,
|
2022-03-31 08:50:45 +01:00
|
|
|
#[primary_span]
|
2022-03-31 10:24:46 +01:00
|
|
|
#[label]
|
2020-08-27 20:09:22 +10:00
|
|
|
pub span: Span,
|
2022-04-21 04:03:13 +01:00
|
|
|
#[suggestion_verbose(code = "{ty}")]
|
2022-04-07 22:46:53 +04:00
|
|
|
pub opt_sugg: Option<(Span, Applicability)>,
|
2020-08-27 20:09:22 +10:00
|
|
|
}
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(hir_analysis_value_of_associated_struct_already_specified, code = "E0719")]
|
2020-08-27 20:09:22 +10:00
|
|
|
pub struct ValueOfAssociatedStructAlreadySpecified {
|
2022-03-31 08:50:45 +01:00
|
|
|
#[primary_span]
|
2022-03-31 10:24:46 +01:00
|
|
|
#[label]
|
2020-08-27 20:09:22 +10:00
|
|
|
pub span: Span,
|
2022-10-22 11:07:54 +02:00
|
|
|
#[label(previous_bound_label)]
|
2020-08-27 20:09:22 +10:00
|
|
|
pub prev_span: Span,
|
|
|
|
pub item_name: Ident,
|
|
|
|
pub def_path: String,
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(hir_analysis_unconstrained_opaque_type)]
|
2022-05-04 07:27:12 +01:00
|
|
|
#[note]
|
|
|
|
pub struct UnconstrainedOpaqueType {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub name: Symbol,
|
|
|
|
}
|
2022-05-06 03:46:12 +01:00
|
|
|
|
2022-09-05 17:26:57 -04:00
|
|
|
pub struct MissingTypeParams {
|
2022-05-07 07:32:01 +01:00
|
|
|
pub span: Span,
|
|
|
|
pub def_span: Span,
|
2022-09-05 17:26:57 -04:00
|
|
|
pub span_snippet: Option<String>,
|
2022-07-25 22:40:00 +09:00
|
|
|
pub missing_type_params: Vec<Symbol>,
|
2022-05-07 07:32:01 +01:00
|
|
|
pub empty_generic_args: bool,
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
// Manual implementation of `IntoDiagnostic` to be able to call `span_to_snippet`.
|
2022-09-18 11:45:41 -04:00
|
|
|
impl<'a> IntoDiagnostic<'a> for MissingTypeParams {
|
2022-09-05 00:15:50 -04:00
|
|
|
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
|
|
|
let mut err = handler.struct_span_err_with_code(
|
2022-05-07 07:32:01 +01:00
|
|
|
self.span,
|
2022-10-22 11:07:54 +02:00
|
|
|
rustc_errors::fluent::hir_analysis_missing_type_params,
|
2022-05-07 07:32:01 +01:00
|
|
|
error_code!(E0393),
|
|
|
|
);
|
|
|
|
err.set_arg("parameterCount", self.missing_type_params.len());
|
|
|
|
err.set_arg(
|
|
|
|
"parameters",
|
|
|
|
self.missing_type_params
|
|
|
|
.iter()
|
|
|
|
.map(|n| format!("`{}`", n))
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
.join(", "),
|
|
|
|
);
|
|
|
|
|
2022-10-22 11:07:54 +02:00
|
|
|
err.span_label(self.def_span, rustc_errors::fluent::label);
|
2022-05-07 07:32:01 +01:00
|
|
|
|
|
|
|
let mut suggested = false;
|
2022-09-05 17:32:23 -04:00
|
|
|
// Don't suggest setting the type params if there are some already: the order is
|
|
|
|
// tricky to get right and the user will already know what the syntax is.
|
|
|
|
if let Some(snippet) = self.span_snippet && self.empty_generic_args {
|
2022-05-07 07:32:01 +01:00
|
|
|
if snippet.ends_with('>') {
|
|
|
|
// The user wrote `Trait<'a, T>` or similar. To provide an accurate suggestion
|
|
|
|
// we would have to preserve the right order. For now, as clearly the user is
|
|
|
|
// aware of the syntax, we do nothing.
|
|
|
|
} else {
|
|
|
|
// The user wrote `Iterator`, so we don't have a type we can suggest, but at
|
|
|
|
// least we can clue them to the correct syntax `Iterator<Type>`.
|
|
|
|
err.span_suggestion(
|
|
|
|
self.span,
|
2022-10-22 11:07:54 +02:00
|
|
|
rustc_errors::fluent::suggestion,
|
2022-07-25 22:40:00 +09:00
|
|
|
format!(
|
|
|
|
"{}<{}>",
|
|
|
|
snippet,
|
|
|
|
self.missing_type_params
|
|
|
|
.iter()
|
|
|
|
.map(|n| n.to_string())
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
.join(", ")
|
|
|
|
),
|
2022-05-07 07:32:01 +01:00
|
|
|
Applicability::HasPlaceholders,
|
|
|
|
);
|
|
|
|
suggested = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !suggested {
|
2022-10-22 11:07:54 +02:00
|
|
|
err.span_label(self.span, rustc_errors::fluent::no_suggestion_label);
|
2022-05-07 07:32:01 +01:00
|
|
|
}
|
|
|
|
|
2022-10-22 11:07:54 +02:00
|
|
|
err.note(rustc_errors::fluent::note);
|
2022-05-07 07:32:01 +01:00
|
|
|
err
|
|
|
|
}
|
|
|
|
}
|
2022-05-07 07:50:01 +01:00
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(hir_analysis_manual_implementation, code = "E0183")]
|
2022-05-07 07:50:01 +01:00
|
|
|
#[help]
|
|
|
|
pub struct ManualImplementation {
|
|
|
|
#[primary_span]
|
|
|
|
#[label]
|
|
|
|
pub span: Span,
|
|
|
|
pub trait_name: String,
|
|
|
|
}
|
2022-05-07 08:14:48 +01:00
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(hir_analysis_substs_on_overridden_impl)]
|
2022-05-07 08:14:48 +01:00
|
|
|
pub struct SubstsOnOverriddenImpl {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
2022-08-17 17:47:44 +08:00
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(hir_analysis_unused_extern_crate)]
|
2022-08-17 17:47:44 +08:00
|
|
|
pub struct UnusedExternCrate {
|
|
|
|
#[suggestion(applicability = "machine-applicable", code = "")]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(hir_analysis_extern_crate_not_idiomatic)]
|
2022-08-17 17:47:44 +08:00
|
|
|
pub struct ExternCrateNotIdiomatic {
|
2022-08-17 20:45:18 +08:00
|
|
|
#[suggestion_short(applicability = "machine-applicable", code = "{suggestion_code}")]
|
2022-08-17 17:47:44 +08:00
|
|
|
pub span: Span,
|
|
|
|
pub msg_code: String,
|
|
|
|
pub suggestion_code: String,
|
|
|
|
}
|
2022-08-18 08:14:21 -04:00
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(hir_analysis_expected_used_symbol)]
|
2022-08-18 08:14:21 -04:00
|
|
|
pub struct ExpectedUsedSymbol {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
2022-10-25 18:28:04 +00:00
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(hir_analysis_const_impl_for_non_const_trait)]
|
|
|
|
pub struct ConstImplForNonConstTrait {
|
|
|
|
#[primary_span]
|
|
|
|
pub trait_ref_span: Span,
|
|
|
|
pub trait_name: String,
|
|
|
|
#[suggestion(applicability = "machine-applicable", code = "#[const_trait]")]
|
|
|
|
pub local_trait_span: Option<Span>,
|
|
|
|
#[note]
|
|
|
|
pub marking: (),
|
|
|
|
#[note(adding)]
|
|
|
|
pub adding: (),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(hir_analysis_const_bound_for_non_const_trait)]
|
|
|
|
pub struct ConstBoundForNonConstTrait {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
}
|