diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:06:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:06:31 +0000 |
commit | 2ff14448863ac1a1dd9533461708e29aae170c2d (patch) | |
tree | 85b9fea2bbfe3f06473cfa381eed11f273b57c5c /compiler/rustc_typeck/src/errors.rs | |
parent | Adding debian version 1.64.0+dfsg1-1. (diff) | |
download | rustc-2ff14448863ac1a1dd9533461708e29aae170c2d.tar.xz rustc-2ff14448863ac1a1dd9533461708e29aae170c2d.zip |
Adding debian version 1.65.0+dfsg1-2.debian/1.65.0+dfsg1-2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_typeck/src/errors.rs')
-rw-r--r-- | compiler/rustc_typeck/src/errors.rs | 95 |
1 files changed, 58 insertions, 37 deletions
diff --git a/compiler/rustc_typeck/src/errors.rs b/compiler/rustc_typeck/src/errors.rs index 0438ac02e..0d2e66745 100644 --- a/compiler/rustc_typeck/src/errors.rs +++ b/compiler/rustc_typeck/src/errors.rs @@ -1,12 +1,12 @@ //! Errors emitted by typeck. -use rustc_errors::{error_code, Applicability, DiagnosticBuilder, ErrorGuaranteed}; -use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic}; +use rustc_errors::{error_code, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler}; +use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic}; use rustc_middle::ty::Ty; -use rustc_session::{parse::ParseSess, SessionDiagnostic}; +use rustc_session::SessionDiagnostic; use rustc_span::{symbol::Ident, Span, Symbol}; #[derive(SessionDiagnostic)] -#[error(typeck::field_multiply_specified_in_initializer, code = "E0062")] +#[diag(typeck::field_multiply_specified_in_initializer, code = "E0062")] pub struct FieldMultiplySpecifiedInInitializer { #[primary_span] #[label] @@ -17,7 +17,7 @@ pub struct FieldMultiplySpecifiedInInitializer { } #[derive(SessionDiagnostic)] -#[error(typeck::unrecognized_atomic_operation, code = "E0092")] +#[diag(typeck::unrecognized_atomic_operation, code = "E0092")] pub struct UnrecognizedAtomicOperation<'a> { #[primary_span] #[label] @@ -26,7 +26,7 @@ pub struct UnrecognizedAtomicOperation<'a> { } #[derive(SessionDiagnostic)] -#[error(typeck::wrong_number_of_generic_arguments_to_intrinsic, code = "E0094")] +#[diag(typeck::wrong_number_of_generic_arguments_to_intrinsic, code = "E0094")] pub struct WrongNumberOfGenericArgumentsToIntrinsic<'a> { #[primary_span] #[label] @@ -37,7 +37,7 @@ pub struct WrongNumberOfGenericArgumentsToIntrinsic<'a> { } #[derive(SessionDiagnostic)] -#[error(typeck::unrecognized_intrinsic_function, code = "E0093")] +#[diag(typeck::unrecognized_intrinsic_function, code = "E0093")] pub struct UnrecognizedIntrinsicFunction { #[primary_span] #[label] @@ -46,7 +46,7 @@ pub struct UnrecognizedIntrinsicFunction { } #[derive(SessionDiagnostic)] -#[error(typeck::lifetimes_or_bounds_mismatch_on_trait, code = "E0195")] +#[diag(typeck::lifetimes_or_bounds_mismatch_on_trait, code = "E0195")] pub struct LifetimesOrBoundsMismatchOnTrait { #[primary_span] #[label] @@ -58,7 +58,7 @@ pub struct LifetimesOrBoundsMismatchOnTrait { } #[derive(SessionDiagnostic)] -#[error(typeck::drop_impl_on_wrong_item, code = "E0120")] +#[diag(typeck::drop_impl_on_wrong_item, code = "E0120")] pub struct DropImplOnWrongItem { #[primary_span] #[label] @@ -66,7 +66,7 @@ pub struct DropImplOnWrongItem { } #[derive(SessionDiagnostic)] -#[error(typeck::field_already_declared, code = "E0124")] +#[diag(typeck::field_already_declared, code = "E0124")] pub struct FieldAlreadyDeclared { pub field_name: Ident, #[primary_span] @@ -77,7 +77,7 @@ pub struct FieldAlreadyDeclared { } #[derive(SessionDiagnostic)] -#[error(typeck::copy_impl_on_type_with_dtor, code = "E0184")] +#[diag(typeck::copy_impl_on_type_with_dtor, code = "E0184")] pub struct CopyImplOnTypeWithDtor { #[primary_span] #[label] @@ -85,14 +85,14 @@ pub struct CopyImplOnTypeWithDtor { } #[derive(SessionDiagnostic)] -#[error(typeck::multiple_relaxed_default_bounds, code = "E0203")] +#[diag(typeck::multiple_relaxed_default_bounds, code = "E0203")] pub struct MultipleRelaxedDefaultBounds { #[primary_span] pub span: Span, } #[derive(SessionDiagnostic)] -#[error(typeck::copy_impl_on_non_adt, code = "E0206")] +#[diag(typeck::copy_impl_on_non_adt, code = "E0206")] pub struct CopyImplOnNonAdt { #[primary_span] #[label] @@ -100,7 +100,7 @@ pub struct CopyImplOnNonAdt { } #[derive(SessionDiagnostic)] -#[error(typeck::trait_object_declared_with_no_traits, code = "E0224")] +#[diag(typeck::trait_object_declared_with_no_traits, code = "E0224")] pub struct TraitObjectDeclaredWithNoTraits { #[primary_span] pub span: Span, @@ -109,14 +109,14 @@ pub struct TraitObjectDeclaredWithNoTraits { } #[derive(SessionDiagnostic)] -#[error(typeck::ambiguous_lifetime_bound, code = "E0227")] +#[diag(typeck::ambiguous_lifetime_bound, code = "E0227")] pub struct AmbiguousLifetimeBound { #[primary_span] pub span: Span, } #[derive(SessionDiagnostic)] -#[error(typeck::assoc_type_binding_not_allowed, code = "E0229")] +#[diag(typeck::assoc_type_binding_not_allowed, code = "E0229")] pub struct AssocTypeBindingNotAllowed { #[primary_span] #[label] @@ -124,14 +124,14 @@ pub struct AssocTypeBindingNotAllowed { } #[derive(SessionDiagnostic)] -#[error(typeck::functional_record_update_on_non_struct, code = "E0436")] +#[diag(typeck::functional_record_update_on_non_struct, code = "E0436")] pub struct FunctionalRecordUpdateOnNonStruct { #[primary_span] pub span: Span, } #[derive(SessionDiagnostic)] -#[error(typeck::typeof_reserved_keyword_used, code = "E0516")] +#[diag(typeck::typeof_reserved_keyword_used, code = "E0516")] pub struct TypeofReservedKeywordUsed<'tcx> { pub ty: Ty<'tcx>, #[primary_span] @@ -142,7 +142,7 @@ pub struct TypeofReservedKeywordUsed<'tcx> { } #[derive(SessionDiagnostic)] -#[error(typeck::return_stmt_outside_of_fn_body, code = "E0572")] +#[diag(typeck::return_stmt_outside_of_fn_body, code = "E0572")] pub struct ReturnStmtOutsideOfFnBody { #[primary_span] pub span: Span, @@ -153,14 +153,14 @@ pub struct ReturnStmtOutsideOfFnBody { } #[derive(SessionDiagnostic)] -#[error(typeck::yield_expr_outside_of_generator, code = "E0627")] +#[diag(typeck::yield_expr_outside_of_generator, code = "E0627")] pub struct YieldExprOutsideOfGenerator { #[primary_span] pub span: Span, } #[derive(SessionDiagnostic)] -#[error(typeck::struct_expr_non_exhaustive, code = "E0639")] +#[diag(typeck::struct_expr_non_exhaustive, code = "E0639")] pub struct StructExprNonExhaustive { #[primary_span] pub span: Span, @@ -168,14 +168,14 @@ pub struct StructExprNonExhaustive { } #[derive(SessionDiagnostic)] -#[error(typeck::method_call_on_unknown_type, code = "E0699")] +#[diag(typeck::method_call_on_unknown_type, code = "E0699")] pub struct MethodCallOnUnknownType { #[primary_span] pub span: Span, } #[derive(SessionDiagnostic)] -#[error(typeck::value_of_associated_struct_already_specified, code = "E0719")] +#[diag(typeck::value_of_associated_struct_already_specified, code = "E0719")] pub struct ValueOfAssociatedStructAlreadySpecified { #[primary_span] #[label] @@ -187,7 +187,7 @@ pub struct ValueOfAssociatedStructAlreadySpecified { } #[derive(SessionDiagnostic)] -#[error(typeck::address_of_temporary_taken, code = "E0745")] +#[diag(typeck::address_of_temporary_taken, code = "E0745")] pub struct AddressOfTemporaryTaken { #[primary_span] #[label] @@ -195,7 +195,7 @@ pub struct AddressOfTemporaryTaken { } #[derive(SessionSubdiagnostic)] -pub enum AddReturnTypeSuggestion<'tcx> { +pub enum AddReturnTypeSuggestion { #[suggestion( typeck::add_return_type_add, code = "-> {found} ", @@ -204,7 +204,7 @@ pub enum AddReturnTypeSuggestion<'tcx> { Add { #[primary_span] span: Span, - found: Ty<'tcx>, + found: String, }, #[suggestion( typeck::add_return_type_missing_here, @@ -233,7 +233,7 @@ pub enum ExpectedReturnTypeLabel<'tcx> { } #[derive(SessionDiagnostic)] -#[error(typeck::unconstrained_opaque_type)] +#[diag(typeck::unconstrained_opaque_type)] #[note] pub struct UnconstrainedOpaqueType { #[primary_span] @@ -244,14 +244,15 @@ pub struct UnconstrainedOpaqueType { pub struct MissingTypeParams { pub span: Span, pub def_span: Span, + pub span_snippet: Option<String>, pub missing_type_params: Vec<Symbol>, pub empty_generic_args: bool, } // Manual implementation of `SessionDiagnostic` to be able to call `span_to_snippet`. impl<'a> SessionDiagnostic<'a> for MissingTypeParams { - fn into_diagnostic(self, sess: &'a ParseSess) -> DiagnosticBuilder<'a, ErrorGuaranteed> { - let mut err = sess.span_diagnostic.struct_span_err_with_code( + fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> { + let mut err = handler.struct_span_err_with_code( self.span, rustc_errors::fluent::typeck::missing_type_params, error_code!(E0393), @@ -269,12 +270,9 @@ impl<'a> SessionDiagnostic<'a> for MissingTypeParams { err.span_label(self.def_span, rustc_errors::fluent::typeck::label); let mut suggested = false; - if let (Ok(snippet), true) = ( - sess.source_map().span_to_snippet(self.span), - // 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. - self.empty_generic_args, - ) { + // 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 { 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 @@ -309,7 +307,7 @@ impl<'a> SessionDiagnostic<'a> for MissingTypeParams { } #[derive(SessionDiagnostic)] -#[error(typeck::manual_implementation, code = "E0183")] +#[diag(typeck::manual_implementation, code = "E0183")] #[help] pub struct ManualImplementation { #[primary_span] @@ -319,8 +317,31 @@ pub struct ManualImplementation { } #[derive(SessionDiagnostic)] -#[error(typeck::substs_on_overridden_impl)] +#[diag(typeck::substs_on_overridden_impl)] pub struct SubstsOnOverriddenImpl { #[primary_span] pub span: Span, } + +#[derive(LintDiagnostic)] +#[diag(typeck::unused_extern_crate)] +pub struct UnusedExternCrate { + #[suggestion(applicability = "machine-applicable", code = "")] + pub span: Span, +} + +#[derive(LintDiagnostic)] +#[diag(typeck::extern_crate_not_idiomatic)] +pub struct ExternCrateNotIdiomatic { + #[suggestion_short(applicability = "machine-applicable", code = "{suggestion_code}")] + pub span: Span, + pub msg_code: String, + pub suggestion_code: String, +} + +#[derive(SessionDiagnostic)] +#[diag(typeck::expected_used_symbol)] +pub struct ExpectedUsedSymbol { + #[primary_span] + pub span: Span, +} |