diff options
| author | bors <bors@rust-lang.org> | 2022-09-21 19:58:39 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-09-21 19:58:39 +0000 |
| commit | 9062b780b32d2eab060b4432863e085d9504ca5c (patch) | |
| tree | 5b2ed54bf5b205ef5a580b3afa387f5a7532d209 /compiler/rustc_parse/src/parser | |
| parent | db4b4d3becf257e7b1c051540fc7e317958d8d2d (diff) | |
| parent | e52e2344dc574922ce4f8ddfd508f8bfdec3f404 (diff) | |
| download | rust-9062b780b32d2eab060b4432863e085d9504ca5c.tar.gz rust-9062b780b32d2eab060b4432863e085d9504ca5c.zip | |
Auto merge of #101558 - JhonnyBillM:session-diagnostic-to-diagnostic-handler-refactor, r=davidtwco
Move and rename `SessionDiagnostic` & `SessionSubdiagnostic` traits and macros
After PR #101434, we want to:
- [x] Move `SessionDiagnostic` to `rustc_errors`.
- [x] Add `emit_` methods that accept `impl SessionDiagnostic` to `Handler`.
- [x] _(optional)_ Rename trait `SessionDiagnostic` to `DiagnosticHandler`.
- [x] _(optional)_ Rename macro `SessionDiagnostic` to `DiagnosticHandler`.
- [x] Update Rustc Dev Guide and Docs to reflect these changes. https://github.com/rust-lang/rustc-dev-guide/pull/1460
Now I am having build issues getting the compiler to build when trying to rename the macro.
<details>
<summary>See diagnostics errors and context when building.</summary>
```
error: diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
--> compiler/rustc_attr/src/session_diagnostics.rs:13:10
|
13 | #[derive(DiagnosticHandler)]
| ^^^^^^^^^^^^^^^^^ in this derive macro expansion
|
::: /Users/jhonny/.cargo/registry/src/github.com-1ecc6299db9ec823/synstructure-0.12.6/src/macros.rs:94:9
|
94 | / pub fn $derives(
95 | | i: $crate::macros::TokenStream
96 | | ) -> $crate::macros::TokenStream {
| |________________________________________- in this expansion of `#[derive(DiagnosticHandler)]`
|
note: the lint level is defined here
--> compiler/rustc_attr/src/lib.rs:10:9
|
10 | #![deny(rustc::diagnostic_outside_of_impl)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
And also this one:
```
error: diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
--> compiler/rustc_attr/src/session_diagnostics.rs:213:32
|
213 | let mut diag = handler.struct_span_err_with_code(
| ^^^^^^^^^^^^^^^^^^^^^^^^^
```
> **Note**
> Can't find where this message is coming from, because you can see in [this experimental branch](https://github.com/JhonnyBillM/rust/tree/experimental/trying-to-rename-session-diagnostic-macro) that I updated all errors and diags to say:
> error: diagnostics should only be created in **`DiagnosticHandler`**/`AddSubdiagnostic` impls
> and not:
> error: diagnostics should only be created in **`SessionDiagnostic`**/`AddSubdiagnostic` impls
</details>
I tried building the compiler in different ways (playing with the stages etc), but nothing worked.
## Question
**Do we need to build or do something different when renaming a macro and identifiers?**
For context, see experimental commit https://github.com/JhonnyBillM/rust/commit/f2193a98b44db3f2af77a878824b152cdf0d34a5 where the macro and symbols are renamed, but it doesn't compile.
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 100 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 2 |
2 files changed, 51 insertions, 51 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index a65f523a0f4..dcea11eadcb 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -20,7 +20,7 @@ use rustc_errors::{ fluent, Applicability, DiagnosticBuilder, DiagnosticMessage, Handler, MultiSpan, PResult, }; use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed}; -use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic}; +use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::{Span, SpanSnippetError, DUMMY_SP}; @@ -242,7 +242,7 @@ impl MultiSugg { } } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::maybe_report_ambiguous_plus)] struct AmbiguousPlus { pub sum_ty: String, @@ -251,7 +251,7 @@ struct AmbiguousPlus { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::maybe_recover_from_bad_type_plus, code = "E0178")] struct BadTypePlus { pub ty: String, @@ -261,7 +261,7 @@ struct BadTypePlus { pub sub: BadTypePlusSub, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub enum BadTypePlusSub { #[suggestion( parser::add_paren, @@ -285,7 +285,7 @@ pub enum BadTypePlusSub { }, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::maybe_recover_from_bad_qpath_stage_2)] struct BadQPathStage2 { #[primary_span] @@ -294,7 +294,7 @@ struct BadQPathStage2 { ty: String, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::incorrect_semicolon)] struct IncorrectSemicolon<'a> { #[primary_span] @@ -305,7 +305,7 @@ struct IncorrectSemicolon<'a> { name: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::incorrect_use_of_await)] struct IncorrectUseOfAwait { #[primary_span] @@ -313,7 +313,7 @@ struct IncorrectUseOfAwait { span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::incorrect_use_of_await)] struct IncorrectAwait { #[primary_span] @@ -324,7 +324,7 @@ struct IncorrectAwait { question_mark: &'static str, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::in_in_typo)] struct InInTypo { #[primary_span] @@ -333,7 +333,7 @@ struct InInTypo { sugg_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::invalid_variable_declaration)] pub struct InvalidVariableDeclaration { #[primary_span] @@ -342,7 +342,7 @@ pub struct InvalidVariableDeclaration { pub sub: InvalidVariableDeclarationSub, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub enum InvalidVariableDeclarationSub { #[suggestion( parser::switch_mut_let_order, @@ -362,7 +362,7 @@ pub enum InvalidVariableDeclarationSub { UseLetNotVar(#[primary_span] Span), } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::invalid_comparison_operator)] pub(crate) struct InvalidComparisonOperator { #[primary_span] @@ -372,7 +372,7 @@ pub(crate) struct InvalidComparisonOperator { pub sub: InvalidComparisonOperatorSub, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub(crate) enum InvalidComparisonOperatorSub { #[suggestion_short( parser::use_instead, @@ -389,7 +389,7 @@ pub(crate) enum InvalidComparisonOperatorSub { Spaceship(#[primary_span] Span), } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::invalid_logical_operator)] #[note] pub(crate) struct InvalidLogicalOperator { @@ -400,7 +400,7 @@ pub(crate) struct InvalidLogicalOperator { pub sub: InvalidLogicalOperatorSub, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub(crate) enum InvalidLogicalOperatorSub { #[suggestion_short( parser::use_amp_amp_for_conjunction, @@ -416,7 +416,7 @@ pub(crate) enum InvalidLogicalOperatorSub { Disjunction(#[primary_span] Span), } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::tilde_is_not_unary_operator)] pub(crate) struct TildeAsUnaryOperator( #[primary_span] @@ -424,7 +424,7 @@ pub(crate) struct TildeAsUnaryOperator( pub Span, ); -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::unexpected_token_after_not)] pub(crate) struct NotAsNegationOperator { #[primary_span] @@ -434,7 +434,7 @@ pub(crate) struct NotAsNegationOperator { pub sub: NotAsNegationOperatorSub, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub enum NotAsNegationOperatorSub { #[suggestion_short( parser::unexpected_token_after_not_default, @@ -458,7 +458,7 @@ pub enum NotAsNegationOperatorSub { SuggestNotLogical(#[primary_span] Span), } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::malformed_loop_label)] pub(crate) struct MalformedLoopLabel { #[primary_span] @@ -467,7 +467,7 @@ pub(crate) struct MalformedLoopLabel { pub correct_label: Ident, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::lifetime_in_borrow_expression)] pub(crate) struct LifetimeInBorrowExpression { #[primary_span] @@ -477,15 +477,15 @@ pub(crate) struct LifetimeInBorrowExpression { pub lifetime_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::field_expression_with_generic)] pub(crate) struct FieldExpressionWithGeneric(#[primary_span] pub Span); -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::macro_invocation_with_qualified_path)] pub(crate) struct MacroInvocationWithQualifiedPath(#[primary_span] pub Span); -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::unexpected_token_after_label)] pub(crate) struct UnexpectedTokenAfterLabel( #[primary_span] @@ -493,7 +493,7 @@ pub(crate) struct UnexpectedTokenAfterLabel( pub Span, ); -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::require_colon_after_labeled_expression)] #[note] pub(crate) struct RequireColonAfterLabeledExpression { @@ -505,7 +505,7 @@ pub(crate) struct RequireColonAfterLabeledExpression { pub label_end: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::do_catch_syntax_removed)] #[note] pub(crate) struct DoCatchSyntaxRemoved { @@ -514,7 +514,7 @@ pub(crate) struct DoCatchSyntaxRemoved { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::float_literal_requires_integer_part)] pub(crate) struct FloatLiteralRequiresIntegerPart { #[primary_span] @@ -523,7 +523,7 @@ pub(crate) struct FloatLiteralRequiresIntegerPart { pub correct: String, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::invalid_int_literal_width)] #[help] pub(crate) struct InvalidIntLiteralWidth { @@ -532,7 +532,7 @@ pub(crate) struct InvalidIntLiteralWidth { pub width: String, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::invalid_num_literal_base_prefix)] #[note] pub(crate) struct InvalidNumLiteralBasePrefix { @@ -542,7 +542,7 @@ pub(crate) struct InvalidNumLiteralBasePrefix { pub fixed: String, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::invalid_num_literal_suffix)] #[help] pub(crate) struct InvalidNumLiteralSuffix { @@ -552,7 +552,7 @@ pub(crate) struct InvalidNumLiteralSuffix { pub suffix: String, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::invalid_float_literal_width)] #[help] pub(crate) struct InvalidFloatLiteralWidth { @@ -561,7 +561,7 @@ pub(crate) struct InvalidFloatLiteralWidth { pub width: String, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::invalid_float_literal_suffix)] #[help] pub(crate) struct InvalidFloatLiteralSuffix { @@ -571,14 +571,14 @@ pub(crate) struct InvalidFloatLiteralSuffix { pub suffix: String, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::int_literal_too_large)] pub(crate) struct IntLiteralTooLarge { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::missing_semicolon_before_array)] pub(crate) struct MissingSemicolonBeforeArray { #[primary_span] @@ -587,7 +587,7 @@ pub(crate) struct MissingSemicolonBeforeArray { pub semicolon: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::invalid_block_macro_segment)] pub(crate) struct InvalidBlockMacroSegment { #[primary_span] @@ -596,7 +596,7 @@ pub(crate) struct InvalidBlockMacroSegment { pub context: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::if_expression_missing_then_block)] pub(crate) struct IfExpressionMissingThenBlock { #[primary_span] @@ -605,7 +605,7 @@ pub(crate) struct IfExpressionMissingThenBlock { pub sub: IfExpressionMissingThenBlockSub, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub(crate) enum IfExpressionMissingThenBlockSub { #[help(parser::condition_possibly_unfinished)] UnfinishedCondition(#[primary_span] Span), @@ -613,7 +613,7 @@ pub(crate) enum IfExpressionMissingThenBlockSub { AddThenBlock(#[primary_span] Span), } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::if_expression_missing_condition)] pub(crate) struct IfExpressionMissingCondition { #[primary_span] @@ -623,14 +623,14 @@ pub(crate) struct IfExpressionMissingCondition { pub block_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::expected_expression_found_let)] pub(crate) struct ExpectedExpressionFoundLet { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::expected_else_block)] pub(crate) struct ExpectedElseBlock { #[primary_span] @@ -642,7 +642,7 @@ pub(crate) struct ExpectedElseBlock { pub condition_start: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::outer_attribute_not_allowed_on_if_else)] pub(crate) struct OuterAttributeNotAllowedOnIfElse { #[primary_span] @@ -659,7 +659,7 @@ pub(crate) struct OuterAttributeNotAllowedOnIfElse { pub attributes: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::missing_in_in_for_loop)] pub(crate) struct MissingInInForLoop { #[primary_span] @@ -668,7 +668,7 @@ pub(crate) struct MissingInInForLoop { pub sub: MissingInInForLoopSub, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub(crate) enum MissingInInForLoopSub { // Has been misleading, at least in the past (closed Issue #48492), thus maybe-incorrect #[suggestion_short(parser::use_in_not_of, applicability = "maybe-incorrect", code = "in")] @@ -677,7 +677,7 @@ pub(crate) enum MissingInInForLoopSub { AddIn(#[primary_span] Span), } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::missing_comma_after_match_arm)] pub(crate) struct MissingCommaAfterMatchArm { #[primary_span] @@ -685,7 +685,7 @@ pub(crate) struct MissingCommaAfterMatchArm { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::catch_after_try)] #[help] pub(crate) struct CatchAfterTry { @@ -693,7 +693,7 @@ pub(crate) struct CatchAfterTry { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::comma_after_base_struct)] #[note] pub(crate) struct CommaAfterBaseStruct { @@ -703,7 +703,7 @@ pub(crate) struct CommaAfterBaseStruct { pub comma: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::eq_field_init)] pub(crate) struct EqFieldInit { #[primary_span] @@ -712,7 +712,7 @@ pub(crate) struct EqFieldInit { pub eq: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::dotdotdot)] pub(crate) struct DotDotDot { #[primary_span] @@ -721,7 +721,7 @@ pub(crate) struct DotDotDot { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::left_arrow_operator)] pub(crate) struct LeftArrowOperator { #[primary_span] @@ -729,7 +729,7 @@ pub(crate) struct LeftArrowOperator { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::remove_let)] pub(crate) struct RemoveLet { #[primary_span] @@ -737,7 +737,7 @@ pub(crate) struct RemoveLet { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::use_eq_instead)] pub(crate) struct UseEqInstead { #[primary_span] diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index f4f75f71e72..ae77961b7bc 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -36,10 +36,10 @@ use rustc_ast::{AnonConst, BinOp, BinOpKind, FnDecl, FnRetTy, MacCall, Param, Ty use rustc_ast::{Arm, Async, BlockCheckMode, Expr, ExprKind, Label, Movability, RangeLimits}; use rustc_ast::{ClosureBinder, StmtKind}; use rustc_ast_pretty::pprust; +use rustc_errors::IntoDiagnostic; use rustc_errors::{Applicability, Diagnostic, PResult}; use rustc_session::lint::builtin::BREAK_WITH_LABEL_AND_LOOP; use rustc_session::lint::BuiltinLintDiagnostics; -use rustc_session::SessionDiagnostic; use rustc_span::source_map::{self, Span, Spanned}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{BytePos, Pos}; |
