Skip to content

Commit

Permalink
Auto merge of #119972 - nnethercote:add-ErrCode, r=oli-obk
Browse files Browse the repository at this point in the history
Add `ErrCode`

Error codes are integers, but `String` is used everywhere to represent them. Gross!

This commit introduces `ErrCode`, an integral newtype for error codes, replacing `String`. The commit also introduces constants like `E0123` for all the used error codes.

r? `@estebank`
  • Loading branch information
bors committed Jan 29, 2024
2 parents 6351247 + 5d9dfbd commit 8a0b5ae
Show file tree
Hide file tree
Showing 110 changed files with 1,632 additions and 1,579 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,6 @@ name = "error_index_generator"
version = "0.0.0"
dependencies = [
"mdbook",
"rustc_error_codes",
]

[[package]]
Expand Down Expand Up @@ -3701,7 +3700,6 @@ dependencies = [
"rustc_codegen_ssa",
"rustc_const_eval",
"rustc_data_structures",
"rustc_error_codes",
"rustc_errors",
"rustc_expand",
"rustc_feature",
Expand Down Expand Up @@ -3774,9 +3772,11 @@ dependencies = [
"rustc_ast",
"rustc_ast_pretty",
"rustc_data_structures",
"rustc_error_codes",
"rustc_error_messages",
"rustc_fluent_macro",
"rustc_hir",
"rustc_index",
"rustc_lint_defs",
"rustc_macros",
"rustc_serialize",
Expand Down
20 changes: 10 additions & 10 deletions compiler/rustc_ast_lowering/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use rustc_errors::DiagnosticArgFromDisplay;
use rustc_errors::{codes::*, DiagnosticArgFromDisplay};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{symbol::Ident, Span, Symbol};

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_generic_type_with_parentheses, code = "E0214")]
#[diag(ast_lowering_generic_type_with_parentheses, code = E0214)]
pub struct GenericTypeWithParentheses {
#[primary_span]
#[label]
Expand All @@ -22,7 +22,7 @@ pub struct UseAngleBrackets {
}

#[derive(Diagnostic)]
#[diag(ast_lowering_invalid_abi, code = "E0703")]
#[diag(ast_lowering_invalid_abi, code = E0703)]
#[note]
pub struct InvalidAbi {
#[primary_span]
Expand Down Expand Up @@ -89,7 +89,7 @@ pub enum AssocTyParenthesesSub {
}

#[derive(Diagnostic)]
#[diag(ast_lowering_misplaced_impl_trait, code = "E0562")]
#[diag(ast_lowering_misplaced_impl_trait, code = E0562)]
#[note]
pub struct MisplacedImplTrait<'a> {
#[primary_span]
Expand All @@ -114,15 +114,15 @@ pub struct UnderscoreExprLhsAssign {
}

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_base_expression_double_dot, code = "E0797")]
#[diag(ast_lowering_base_expression_double_dot, code = E0797)]
pub struct BaseExpressionDoubleDot {
#[primary_span]
#[suggestion(code = "/* expr */", applicability = "has-placeholders", style = "verbose")]
pub span: Span,
}

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_await_only_in_async_fn_and_blocks, code = "E0728")]
#[diag(ast_lowering_await_only_in_async_fn_and_blocks, code = E0728)]
pub struct AwaitOnlyInAsyncFnAndBlocks {
#[primary_span]
#[label]
Expand All @@ -132,14 +132,14 @@ pub struct AwaitOnlyInAsyncFnAndBlocks {
}

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_coroutine_too_many_parameters, code = "E0628")]
#[diag(ast_lowering_coroutine_too_many_parameters, code = E0628)]
pub struct CoroutineTooManyParameters {
#[primary_span]
pub fn_decl_span: Span,
}

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_closure_cannot_be_static, code = "E0697")]
#[diag(ast_lowering_closure_cannot_be_static, code = E0697)]
pub struct ClosureCannotBeStatic {
#[primary_span]
pub fn_decl_span: Span,
Expand All @@ -154,14 +154,14 @@ pub struct FunctionalRecordUpdateDestructuringAssignment {
}

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_async_coroutines_not_supported, code = "E0727")]
#[diag(ast_lowering_async_coroutines_not_supported, code = E0727)]
pub struct AsyncCoroutinesNotSupported {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_inline_asm_unsupported_target, code = "E0472")]
#[diag(ast_lowering_inline_asm_unsupported_target, code = E0472)]
pub struct InlineAsmUnsupportedTarget {
#[primary_span]
pub span: Span,
Expand Down
38 changes: 19 additions & 19 deletions compiler/rustc_ast_passes/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Errors emitted by ast_passes.

use rustc_ast::ParamKindOrd;
use rustc_errors::{AddToDiagnostic, Applicability};
use rustc_errors::{codes::*, AddToDiagnostic, Applicability};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{symbol::Ident, Span, Symbol};

Expand All @@ -23,7 +23,7 @@ pub struct InvalidLabel {
}

#[derive(Diagnostic)]
#[diag(ast_passes_visibility_not_permitted, code = "E0449")]
#[diag(ast_passes_visibility_not_permitted, code = E0449)]
pub struct VisibilityNotPermitted {
#[primary_span]
pub span: Span,
Expand All @@ -44,7 +44,7 @@ pub enum VisibilityNotPermittedNote {
}

#[derive(Diagnostic)]
#[diag(ast_passes_trait_fn_const, code = "E0379")]
#[diag(ast_passes_trait_fn_const, code = E0379)]
pub struct TraitFnConst {
#[primary_span]
#[label]
Expand Down Expand Up @@ -302,14 +302,14 @@ pub struct ItemUnderscore<'a> {
}

#[derive(Diagnostic)]
#[diag(ast_passes_nomangle_ascii, code = "E0754")]
#[diag(ast_passes_nomangle_ascii, code = E0754)]
pub struct NoMangleAscii {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(ast_passes_module_nonascii, code = "E0754")]
#[diag(ast_passes_module_nonascii, code = E0754)]
#[help]
pub struct ModuleNonAscii {
#[primary_span]
Expand All @@ -318,7 +318,7 @@ pub struct ModuleNonAscii {
}

#[derive(Diagnostic)]
#[diag(ast_passes_auto_generic, code = "E0567")]
#[diag(ast_passes_auto_generic, code = E0567)]
pub struct AutoTraitGeneric {
#[primary_span]
#[suggestion(code = "", applicability = "machine-applicable")]
Expand All @@ -328,7 +328,7 @@ pub struct AutoTraitGeneric {
}

#[derive(Diagnostic)]
#[diag(ast_passes_auto_super_lifetime, code = "E0568")]
#[diag(ast_passes_auto_super_lifetime, code = E0568)]
pub struct AutoTraitBounds {
#[primary_span]
#[suggestion(code = "", applicability = "machine-applicable")]
Expand All @@ -338,7 +338,7 @@ pub struct AutoTraitBounds {
}

#[derive(Diagnostic)]
#[diag(ast_passes_auto_items, code = "E0380")]
#[diag(ast_passes_auto_items, code = E0380)]
pub struct AutoTraitItems {
#[primary_span]
pub spans: Vec<Span>,
Expand Down Expand Up @@ -384,28 +384,28 @@ impl AddToDiagnostic for EmptyLabelManySpans {
}

#[derive(Diagnostic)]
#[diag(ast_passes_pattern_in_fn_pointer, code = "E0561")]
#[diag(ast_passes_pattern_in_fn_pointer, code = E0561)]
pub struct PatternFnPointer {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(ast_passes_trait_object_single_bound, code = "E0226")]
#[diag(ast_passes_trait_object_single_bound, code = E0226)]
pub struct TraitObjectBound {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(ast_passes_impl_trait_path, code = "E0667")]
#[diag(ast_passes_impl_trait_path, code = E0667)]
pub struct ImplTraitPath {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(ast_passes_nested_impl_trait, code = "E0666")]
#[diag(ast_passes_nested_impl_trait, code = E0666)]
pub struct NestedImplTrait {
#[primary_span]
pub span: Span,
Expand Down Expand Up @@ -443,7 +443,7 @@ pub struct ObsoleteAuto {
}

#[derive(Diagnostic)]
#[diag(ast_passes_unsafe_negative_impl, code = "E0198")]
#[diag(ast_passes_unsafe_negative_impl, code = E0198)]
pub struct UnsafeNegativeImpl {
#[primary_span]
pub span: Span,
Expand All @@ -468,7 +468,7 @@ pub struct InherentImplCannot<'a> {
}

#[derive(Diagnostic)]
#[diag(ast_passes_inherent_cannot_be, code = "E0197")]
#[diag(ast_passes_inherent_cannot_be, code = E0197)]
pub struct InherentImplCannotUnsafe<'a> {
#[primary_span]
pub span: Span,
Expand Down Expand Up @@ -536,7 +536,7 @@ pub struct GenericDefaultTrailing {
}

#[derive(Diagnostic)]
#[diag(ast_passes_nested_lifetimes, code = "E0316")]
#[diag(ast_passes_nested_lifetimes, code = E0316)]
pub struct NestedLifetimes {
#[primary_span]
pub span: Span,
Expand Down Expand Up @@ -655,15 +655,15 @@ pub struct ConstAndCVariadic {
}

#[derive(Diagnostic)]
#[diag(ast_passes_pattern_in_foreign, code = "E0130")]
#[diag(ast_passes_pattern_in_foreign, code = E0130)]
pub struct PatternInForeign {
#[primary_span]
#[label]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(ast_passes_pattern_in_bodiless, code = "E0642")]
#[diag(ast_passes_pattern_in_bodiless, code = E0642)]
pub struct PatternInBodiless {
#[primary_span]
#[label]
Expand Down Expand Up @@ -711,14 +711,14 @@ pub struct AssociatedSuggestion2 {
}

#[derive(Diagnostic)]
#[diag(ast_passes_stability_outside_std, code = "E0734")]
#[diag(ast_passes_stability_outside_std, code = E0734)]
pub struct StabilityOutsideStd {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(ast_passes_feature_on_non_nightly, code = "E0554")]
#[diag(ast_passes_feature_on_non_nightly, code = E0554)]
pub struct FeatureOnNonNightly {
#[primary_span]
pub span: Span,
Expand Down
Loading

0 comments on commit 8a0b5ae

Please sign in to comment.