Skip to content

Commit 9062b78

Browse files
committed
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. rust-lang/rustc-dev-guide#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/gb.xjqchip.workers.dev-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 JhonnyBillM@f2193a9 where the macro and symbols are renamed, but it doesn't compile.
2 parents db4b4d3 + e52e234 commit 9062b78

File tree

56 files changed

+833
-792
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+833
-792
lines changed

compiler/rustc_ast_lowering/src/errors.rs

+38-38
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use rustc_errors::{fluent, AddSubdiagnostic, Applicability, Diagnostic, DiagnosticArgFromDisplay};
2-
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
1+
use rustc_errors::{fluent, AddToDiagnostic, Applicability, Diagnostic, DiagnosticArgFromDisplay};
2+
use rustc_macros::{Diagnostic, Subdiagnostic};
33
use rustc_span::{symbol::Ident, Span, Symbol};
44

5-
#[derive(SessionDiagnostic, Clone, Copy)]
5+
#[derive(Diagnostic, Clone, Copy)]
66
#[diag(ast_lowering::generic_type_with_parentheses, code = "E0214")]
77
pub struct GenericTypeWithParentheses {
88
#[primary_span]
@@ -18,7 +18,7 @@ pub struct UseAngleBrackets {
1818
pub close_param: Span,
1919
}
2020

21-
impl AddSubdiagnostic for UseAngleBrackets {
21+
impl AddToDiagnostic for UseAngleBrackets {
2222
fn add_to_diagnostic(self, diag: &mut Diagnostic) {
2323
diag.multipart_suggestion(
2424
fluent::ast_lowering::use_angle_brackets,
@@ -28,7 +28,7 @@ impl AddSubdiagnostic for UseAngleBrackets {
2828
}
2929
}
3030

31-
#[derive(SessionDiagnostic)]
31+
#[derive(Diagnostic)]
3232
#[help]
3333
#[diag(ast_lowering::invalid_abi, code = "E0703")]
3434
pub struct InvalidAbi {
@@ -39,7 +39,7 @@ pub struct InvalidAbi {
3939
pub valid_abis: String,
4040
}
4141

42-
#[derive(SessionDiagnostic, Clone, Copy)]
42+
#[derive(Diagnostic, Clone, Copy)]
4343
#[diag(ast_lowering::assoc_ty_parentheses)]
4444
pub struct AssocTyParentheses {
4545
#[primary_span]
@@ -54,7 +54,7 @@ pub enum AssocTyParenthesesSub {
5454
NotEmpty { open_param: Span, close_param: Span },
5555
}
5656

57-
impl AddSubdiagnostic for AssocTyParenthesesSub {
57+
impl AddToDiagnostic for AssocTyParenthesesSub {
5858
fn add_to_diagnostic(self, diag: &mut Diagnostic) {
5959
match self {
6060
Self::Empty { parentheses_span } => diag.multipart_suggestion(
@@ -71,38 +71,38 @@ impl AddSubdiagnostic for AssocTyParenthesesSub {
7171
}
7272
}
7373

74-
#[derive(SessionDiagnostic)]
74+
#[derive(Diagnostic)]
7575
#[diag(ast_lowering::misplaced_impl_trait, code = "E0562")]
7676
pub struct MisplacedImplTrait<'a> {
7777
#[primary_span]
7878
pub span: Span,
7979
pub position: DiagnosticArgFromDisplay<'a>,
8080
}
8181

82-
#[derive(SessionDiagnostic, Clone, Copy)]
82+
#[derive(Diagnostic, Clone, Copy)]
8383
#[diag(ast_lowering::rustc_box_attribute_error)]
8484
pub struct RustcBoxAttributeError {
8585
#[primary_span]
8686
pub span: Span,
8787
}
8888

89-
#[derive(SessionDiagnostic, Clone, Copy)]
89+
#[derive(Diagnostic, Clone, Copy)]
9090
#[diag(ast_lowering::underscore_expr_lhs_assign)]
9191
pub struct UnderscoreExprLhsAssign {
9292
#[primary_span]
9393
#[label]
9494
pub span: Span,
9595
}
9696

97-
#[derive(SessionDiagnostic, Clone, Copy)]
97+
#[derive(Diagnostic, Clone, Copy)]
9898
#[diag(ast_lowering::base_expression_double_dot)]
9999
pub struct BaseExpressionDoubleDot {
100100
#[primary_span]
101101
#[label]
102102
pub span: Span,
103103
}
104104

105-
#[derive(SessionDiagnostic, Clone, Copy)]
105+
#[derive(Diagnostic, Clone, Copy)]
106106
#[diag(ast_lowering::await_only_in_async_fn_and_blocks, code = "E0728")]
107107
pub struct AwaitOnlyInAsyncFnAndBlocks {
108108
#[primary_span]
@@ -112,58 +112,58 @@ pub struct AwaitOnlyInAsyncFnAndBlocks {
112112
pub item_span: Option<Span>,
113113
}
114114

115-
#[derive(SessionDiagnostic, Clone, Copy)]
115+
#[derive(Diagnostic, Clone, Copy)]
116116
#[diag(ast_lowering::generator_too_many_parameters, code = "E0628")]
117117
pub struct GeneratorTooManyParameters {
118118
#[primary_span]
119119
pub fn_decl_span: Span,
120120
}
121121

122-
#[derive(SessionDiagnostic, Clone, Copy)]
122+
#[derive(Diagnostic, Clone, Copy)]
123123
#[diag(ast_lowering::closure_cannot_be_static, code = "E0697")]
124124
pub struct ClosureCannotBeStatic {
125125
#[primary_span]
126126
pub fn_decl_span: Span,
127127
}
128128

129-
#[derive(SessionDiagnostic, Clone, Copy)]
129+
#[derive(Diagnostic, Clone, Copy)]
130130
#[help]
131131
#[diag(ast_lowering::async_non_move_closure_not_supported, code = "E0708")]
132132
pub struct AsyncNonMoveClosureNotSupported {
133133
#[primary_span]
134134
pub fn_decl_span: Span,
135135
}
136136

137-
#[derive(SessionDiagnostic, Clone, Copy)]
137+
#[derive(Diagnostic, Clone, Copy)]
138138
#[diag(ast_lowering::functional_record_update_destructuring_assignment)]
139139
pub struct FunctionalRecordUpdateDestructuringAssignemnt {
140140
#[primary_span]
141141
#[suggestion(code = "", applicability = "machine-applicable")]
142142
pub span: Span,
143143
}
144144

145-
#[derive(SessionDiagnostic, Clone, Copy)]
145+
#[derive(Diagnostic, Clone, Copy)]
146146
#[diag(ast_lowering::async_generators_not_supported, code = "E0727")]
147147
pub struct AsyncGeneratorsNotSupported {
148148
#[primary_span]
149149
pub span: Span,
150150
}
151151

152-
#[derive(SessionDiagnostic, Clone, Copy)]
152+
#[derive(Diagnostic, Clone, Copy)]
153153
#[diag(ast_lowering::inline_asm_unsupported_target, code = "E0472")]
154154
pub struct InlineAsmUnsupportedTarget {
155155
#[primary_span]
156156
pub span: Span,
157157
}
158158

159-
#[derive(SessionDiagnostic, Clone, Copy)]
159+
#[derive(Diagnostic, Clone, Copy)]
160160
#[diag(ast_lowering::att_syntax_only_x86)]
161161
pub struct AttSyntaxOnlyX86 {
162162
#[primary_span]
163163
pub span: Span,
164164
}
165165

166-
#[derive(SessionDiagnostic, Clone, Copy)]
166+
#[derive(Diagnostic, Clone, Copy)]
167167
#[diag(ast_lowering::abi_specified_multiple_times)]
168168
pub struct AbiSpecifiedMultipleTimes {
169169
#[primary_span]
@@ -175,14 +175,14 @@ pub struct AbiSpecifiedMultipleTimes {
175175
pub equivalent: Option<()>,
176176
}
177177

178-
#[derive(SessionDiagnostic, Clone, Copy)]
178+
#[derive(Diagnostic, Clone, Copy)]
179179
#[diag(ast_lowering::clobber_abi_not_supported)]
180180
pub struct ClobberAbiNotSupported {
181181
#[primary_span]
182182
pub abi_span: Span,
183183
}
184184

185-
#[derive(SessionDiagnostic)]
185+
#[derive(Diagnostic)]
186186
#[note]
187187
#[diag(ast_lowering::invalid_abi_clobber_abi)]
188188
pub struct InvalidAbiClobberAbi {
@@ -191,7 +191,7 @@ pub struct InvalidAbiClobberAbi {
191191
pub supported_abis: String,
192192
}
193193

194-
#[derive(SessionDiagnostic, Clone, Copy)]
194+
#[derive(Diagnostic, Clone, Copy)]
195195
#[diag(ast_lowering::invalid_register)]
196196
pub struct InvalidRegister<'a> {
197197
#[primary_span]
@@ -200,7 +200,7 @@ pub struct InvalidRegister<'a> {
200200
pub error: &'a str,
201201
}
202202

203-
#[derive(SessionDiagnostic, Clone, Copy)]
203+
#[derive(Diagnostic, Clone, Copy)]
204204
#[diag(ast_lowering::invalid_register_class)]
205205
pub struct InvalidRegisterClass<'a> {
206206
#[primary_span]
@@ -209,7 +209,7 @@ pub struct InvalidRegisterClass<'a> {
209209
pub error: &'a str,
210210
}
211211

212-
#[derive(SessionDiagnostic)]
212+
#[derive(Diagnostic)]
213213
#[diag(ast_lowering::invalid_asm_template_modifier_reg_class)]
214214
pub struct InvalidAsmTemplateModifierRegClass {
215215
#[primary_span]
@@ -221,15 +221,15 @@ pub struct InvalidAsmTemplateModifierRegClass {
221221
pub sub: InvalidAsmTemplateModifierRegClassSub,
222222
}
223223

224-
#[derive(SessionSubdiagnostic)]
224+
#[derive(Subdiagnostic)]
225225
pub enum InvalidAsmTemplateModifierRegClassSub {
226226
#[note(ast_lowering::support_modifiers)]
227227
SupportModifier { class_name: Symbol, modifiers: String },
228228
#[note(ast_lowering::does_not_support_modifiers)]
229229
DoesNotSupportModifier { class_name: Symbol },
230230
}
231231

232-
#[derive(SessionDiagnostic, Clone, Copy)]
232+
#[derive(Diagnostic, Clone, Copy)]
233233
#[diag(ast_lowering::invalid_asm_template_modifier_const)]
234234
pub struct InvalidAsmTemplateModifierConst {
235235
#[primary_span]
@@ -239,7 +239,7 @@ pub struct InvalidAsmTemplateModifierConst {
239239
pub op_span: Span,
240240
}
241241

242-
#[derive(SessionDiagnostic, Clone, Copy)]
242+
#[derive(Diagnostic, Clone, Copy)]
243243
#[diag(ast_lowering::invalid_asm_template_modifier_sym)]
244244
pub struct InvalidAsmTemplateModifierSym {
245245
#[primary_span]
@@ -249,15 +249,15 @@ pub struct InvalidAsmTemplateModifierSym {
249249
pub op_span: Span,
250250
}
251251

252-
#[derive(SessionDiagnostic, Clone, Copy)]
252+
#[derive(Diagnostic, Clone, Copy)]
253253
#[diag(ast_lowering::register_class_only_clobber)]
254254
pub struct RegisterClassOnlyClobber {
255255
#[primary_span]
256256
pub op_span: Span,
257257
pub reg_class_name: Symbol,
258258
}
259259

260-
#[derive(SessionDiagnostic, Clone, Copy)]
260+
#[derive(Diagnostic, Clone, Copy)]
261261
#[diag(ast_lowering::register_conflict)]
262262
pub struct RegisterConflict<'a> {
263263
#[primary_span]
@@ -271,7 +271,7 @@ pub struct RegisterConflict<'a> {
271271
pub in_out: Option<Span>,
272272
}
273273

274-
#[derive(SessionDiagnostic, Clone, Copy)]
274+
#[derive(Diagnostic, Clone, Copy)]
275275
#[help]
276276
#[diag(ast_lowering::sub_tuple_binding)]
277277
pub struct SubTupleBinding<'a> {
@@ -288,7 +288,7 @@ pub struct SubTupleBinding<'a> {
288288
pub ctx: &'a str,
289289
}
290290

291-
#[derive(SessionDiagnostic, Clone, Copy)]
291+
#[derive(Diagnostic, Clone, Copy)]
292292
#[diag(ast_lowering::extra_double_dot)]
293293
pub struct ExtraDoubleDot<'a> {
294294
#[primary_span]
@@ -299,43 +299,43 @@ pub struct ExtraDoubleDot<'a> {
299299
pub ctx: &'a str,
300300
}
301301

302-
#[derive(SessionDiagnostic, Clone, Copy)]
302+
#[derive(Diagnostic, Clone, Copy)]
303303
#[note]
304304
#[diag(ast_lowering::misplaced_double_dot)]
305305
pub struct MisplacedDoubleDot {
306306
#[primary_span]
307307
pub span: Span,
308308
}
309309

310-
#[derive(SessionDiagnostic, Clone, Copy)]
310+
#[derive(Diagnostic, Clone, Copy)]
311311
#[diag(ast_lowering::misplaced_relax_trait_bound)]
312312
pub struct MisplacedRelaxTraitBound {
313313
#[primary_span]
314314
pub span: Span,
315315
}
316316

317-
#[derive(SessionDiagnostic, Clone, Copy)]
317+
#[derive(Diagnostic, Clone, Copy)]
318318
#[diag(ast_lowering::not_supported_for_lifetime_binder_async_closure)]
319319
pub struct NotSupportedForLifetimeBinderAsyncClosure {
320320
#[primary_span]
321321
pub span: Span,
322322
}
323323

324-
#[derive(SessionDiagnostic, Clone, Copy)]
324+
#[derive(Diagnostic, Clone, Copy)]
325325
#[diag(ast_lowering::arbitrary_expression_in_pattern)]
326326
pub struct ArbitraryExpressionInPattern {
327327
#[primary_span]
328328
pub span: Span,
329329
}
330330

331-
#[derive(SessionDiagnostic, Clone, Copy)]
331+
#[derive(Diagnostic, Clone, Copy)]
332332
#[diag(ast_lowering::inclusive_range_with_no_end)]
333333
pub struct InclusiveRangeWithNoEnd {
334334
#[primary_span]
335335
pub span: Span,
336336
}
337337

338-
#[derive(SessionDiagnostic, Clone, Copy)]
338+
#[derive(Diagnostic, Clone, Copy)]
339339
#[diag(ast_lowering::trait_fn_async, code = "E0706")]
340340
#[note]
341341
#[note(ast_lowering::note2)]

0 commit comments

Comments
 (0)