Skip to content

Commit 3cc6579

Browse files
committed
Mark all diagnostic structs with #[must_use]
To prevent bugs like 118972.
1 parent a4ea4be commit 3cc6579

File tree

36 files changed

+1190
-5
lines changed

36 files changed

+1190
-5
lines changed

compiler/rustc_ast_lowering/src/errors.rs

+35
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rustc_span::{symbol::Ident, Span, Symbol};
44

55
#[derive(Diagnostic, Clone, Copy)]
66
#[diag(ast_lowering_generic_type_with_parentheses, code = "E0214")]
7+
#[must_use]
78
pub struct GenericTypeWithParentheses {
89
#[primary_span]
910
#[label]
@@ -24,6 +25,7 @@ pub struct UseAngleBrackets {
2425
#[derive(Diagnostic)]
2526
#[diag(ast_lowering_invalid_abi, code = "E0703")]
2627
#[note]
28+
#[must_use]
2729
pub struct InvalidAbi {
2830
#[primary_span]
2931
#[label]
@@ -65,6 +67,7 @@ pub struct InvalidAbiSuggestion {
6567

6668
#[derive(Diagnostic, Clone, Copy)]
6769
#[diag(ast_lowering_assoc_ty_parentheses)]
70+
#[must_use]
6871
pub struct AssocTyParentheses {
6972
#[primary_span]
7073
pub span: Span,
@@ -90,6 +93,7 @@ pub enum AssocTyParenthesesSub {
9093

9194
#[derive(Diagnostic)]
9295
#[diag(ast_lowering_misplaced_impl_trait, code = "E0562")]
96+
#[must_use]
9397
pub struct MisplacedImplTrait<'a> {
9498
#[primary_span]
9599
pub span: Span,
@@ -98,6 +102,7 @@ pub struct MisplacedImplTrait<'a> {
98102

99103
#[derive(Diagnostic)]
100104
#[diag(ast_lowering_misplaced_assoc_ty_binding)]
105+
#[must_use]
101106
pub struct MisplacedAssocTyBinding<'a> {
102107
#[primary_span]
103108
pub span: Span,
@@ -106,6 +111,7 @@ pub struct MisplacedAssocTyBinding<'a> {
106111

107112
#[derive(Diagnostic, Clone, Copy)]
108113
#[diag(ast_lowering_underscore_expr_lhs_assign)]
114+
#[must_use]
109115
pub struct UnderscoreExprLhsAssign {
110116
#[primary_span]
111117
#[label]
@@ -114,6 +120,7 @@ pub struct UnderscoreExprLhsAssign {
114120

115121
#[derive(Diagnostic, Clone, Copy)]
116122
#[diag(ast_lowering_base_expression_double_dot)]
123+
#[must_use]
117124
pub struct BaseExpressionDoubleDot {
118125
#[primary_span]
119126
#[label]
@@ -122,6 +129,7 @@ pub struct BaseExpressionDoubleDot {
122129

123130
#[derive(Diagnostic, Clone, Copy)]
124131
#[diag(ast_lowering_await_only_in_async_fn_and_blocks, code = "E0728")]
132+
#[must_use]
125133
pub struct AwaitOnlyInAsyncFnAndBlocks {
126134
#[primary_span]
127135
#[label]
@@ -132,13 +140,15 @@ pub struct AwaitOnlyInAsyncFnAndBlocks {
132140

133141
#[derive(Diagnostic, Clone, Copy)]
134142
#[diag(ast_lowering_coroutine_too_many_parameters, code = "E0628")]
143+
#[must_use]
135144
pub struct CoroutineTooManyParameters {
136145
#[primary_span]
137146
pub fn_decl_span: Span,
138147
}
139148

140149
#[derive(Diagnostic, Clone, Copy)]
141150
#[diag(ast_lowering_closure_cannot_be_static, code = "E0697")]
151+
#[must_use]
142152
pub struct ClosureCannotBeStatic {
143153
#[primary_span]
144154
pub fn_decl_span: Span,
@@ -147,13 +157,15 @@ pub struct ClosureCannotBeStatic {
147157
#[derive(Diagnostic, Clone, Copy)]
148158
#[help]
149159
#[diag(ast_lowering_async_non_move_closure_not_supported, code = "E0708")]
160+
#[must_use]
150161
pub struct AsyncNonMoveClosureNotSupported {
151162
#[primary_span]
152163
pub fn_decl_span: Span,
153164
}
154165

155166
#[derive(Diagnostic, Clone, Copy)]
156167
#[diag(ast_lowering_functional_record_update_destructuring_assignment)]
168+
#[must_use]
157169
pub struct FunctionalRecordUpdateDestructuringAssignment {
158170
#[primary_span]
159171
#[suggestion(code = "", applicability = "machine-applicable")]
@@ -162,27 +174,31 @@ pub struct FunctionalRecordUpdateDestructuringAssignment {
162174

163175
#[derive(Diagnostic, Clone, Copy)]
164176
#[diag(ast_lowering_async_coroutines_not_supported, code = "E0727")]
177+
#[must_use]
165178
pub struct AsyncCoroutinesNotSupported {
166179
#[primary_span]
167180
pub span: Span,
168181
}
169182

170183
#[derive(Diagnostic, Clone, Copy)]
171184
#[diag(ast_lowering_inline_asm_unsupported_target, code = "E0472")]
185+
#[must_use]
172186
pub struct InlineAsmUnsupportedTarget {
173187
#[primary_span]
174188
pub span: Span,
175189
}
176190

177191
#[derive(Diagnostic, Clone, Copy)]
178192
#[diag(ast_lowering_att_syntax_only_x86)]
193+
#[must_use]
179194
pub struct AttSyntaxOnlyX86 {
180195
#[primary_span]
181196
pub span: Span,
182197
}
183198

184199
#[derive(Diagnostic, Clone, Copy)]
185200
#[diag(ast_lowering_abi_specified_multiple_times)]
201+
#[must_use]
186202
pub struct AbiSpecifiedMultipleTimes {
187203
#[primary_span]
188204
pub abi_span: Span,
@@ -195,6 +211,7 @@ pub struct AbiSpecifiedMultipleTimes {
195211

196212
#[derive(Diagnostic, Clone, Copy)]
197213
#[diag(ast_lowering_clobber_abi_not_supported)]
214+
#[must_use]
198215
pub struct ClobberAbiNotSupported {
199216
#[primary_span]
200217
pub abi_span: Span,
@@ -203,6 +220,7 @@ pub struct ClobberAbiNotSupported {
203220
#[derive(Diagnostic)]
204221
#[note]
205222
#[diag(ast_lowering_invalid_abi_clobber_abi)]
223+
#[must_use]
206224
pub struct InvalidAbiClobberAbi {
207225
#[primary_span]
208226
pub abi_span: Span,
@@ -211,6 +229,7 @@ pub struct InvalidAbiClobberAbi {
211229

212230
#[derive(Diagnostic, Clone, Copy)]
213231
#[diag(ast_lowering_invalid_register)]
232+
#[must_use]
214233
pub struct InvalidRegister<'a> {
215234
#[primary_span]
216235
pub op_span: Span,
@@ -220,6 +239,7 @@ pub struct InvalidRegister<'a> {
220239

221240
#[derive(Diagnostic, Clone, Copy)]
222241
#[diag(ast_lowering_invalid_register_class)]
242+
#[must_use]
223243
pub struct InvalidRegisterClass<'a> {
224244
#[primary_span]
225245
pub op_span: Span,
@@ -229,6 +249,7 @@ pub struct InvalidRegisterClass<'a> {
229249

230250
#[derive(Diagnostic)]
231251
#[diag(ast_lowering_invalid_asm_template_modifier_reg_class)]
252+
#[must_use]
232253
pub struct InvalidAsmTemplateModifierRegClass {
233254
#[primary_span]
234255
#[label(ast_lowering_template_modifier)]
@@ -249,6 +270,7 @@ pub enum InvalidAsmTemplateModifierRegClassSub {
249270

250271
#[derive(Diagnostic, Clone, Copy)]
251272
#[diag(ast_lowering_invalid_asm_template_modifier_const)]
273+
#[must_use]
252274
pub struct InvalidAsmTemplateModifierConst {
253275
#[primary_span]
254276
#[label(ast_lowering_template_modifier)]
@@ -259,6 +281,7 @@ pub struct InvalidAsmTemplateModifierConst {
259281

260282
#[derive(Diagnostic, Clone, Copy)]
261283
#[diag(ast_lowering_invalid_asm_template_modifier_sym)]
284+
#[must_use]
262285
pub struct InvalidAsmTemplateModifierSym {
263286
#[primary_span]
264287
#[label(ast_lowering_template_modifier)]
@@ -269,6 +292,7 @@ pub struct InvalidAsmTemplateModifierSym {
269292

270293
#[derive(Diagnostic, Clone, Copy)]
271294
#[diag(ast_lowering_register_class_only_clobber)]
295+
#[must_use]
272296
pub struct RegisterClassOnlyClobber {
273297
#[primary_span]
274298
pub op_span: Span,
@@ -277,6 +301,7 @@ pub struct RegisterClassOnlyClobber {
277301

278302
#[derive(Diagnostic, Clone, Copy)]
279303
#[diag(ast_lowering_register_conflict)]
304+
#[must_use]
280305
pub struct RegisterConflict<'a> {
281306
#[primary_span]
282307
#[label(ast_lowering_register1)]
@@ -292,6 +317,7 @@ pub struct RegisterConflict<'a> {
292317
#[derive(Diagnostic, Clone, Copy)]
293318
#[help]
294319
#[diag(ast_lowering_sub_tuple_binding)]
320+
#[must_use]
295321
pub struct SubTupleBinding<'a> {
296322
#[primary_span]
297323
#[label]
@@ -309,6 +335,7 @@ pub struct SubTupleBinding<'a> {
309335

310336
#[derive(Diagnostic, Clone, Copy)]
311337
#[diag(ast_lowering_extra_double_dot)]
338+
#[must_use]
312339
pub struct ExtraDoubleDot<'a> {
313340
#[primary_span]
314341
#[label]
@@ -321,27 +348,31 @@ pub struct ExtraDoubleDot<'a> {
321348
#[derive(Diagnostic, Clone, Copy)]
322349
#[note]
323350
#[diag(ast_lowering_misplaced_double_dot)]
351+
#[must_use]
324352
pub struct MisplacedDoubleDot {
325353
#[primary_span]
326354
pub span: Span,
327355
}
328356

329357
#[derive(Diagnostic, Clone, Copy)]
330358
#[diag(ast_lowering_misplaced_relax_trait_bound)]
359+
#[must_use]
331360
pub struct MisplacedRelaxTraitBound {
332361
#[primary_span]
333362
pub span: Span,
334363
}
335364

336365
#[derive(Diagnostic, Clone, Copy)]
337366
#[diag(ast_lowering_not_supported_for_lifetime_binder_async_closure)]
367+
#[must_use]
338368
pub struct NotSupportedForLifetimeBinderAsyncClosure {
339369
#[primary_span]
340370
pub span: Span,
341371
}
342372

343373
#[derive(Diagnostic)]
344374
#[diag(ast_lowering_match_arm_with_no_body)]
375+
#[must_use]
345376
pub struct MatchArmWithNoBody {
346377
#[primary_span]
347378
pub span: Span,
@@ -351,6 +382,7 @@ pub struct MatchArmWithNoBody {
351382

352383
#[derive(Diagnostic)]
353384
#[diag(ast_lowering_never_pattern_with_body)]
385+
#[must_use]
354386
pub struct NeverPatternWithBody {
355387
#[primary_span]
356388
#[label]
@@ -360,6 +392,7 @@ pub struct NeverPatternWithBody {
360392

361393
#[derive(Diagnostic)]
362394
#[diag(ast_lowering_never_pattern_with_guard)]
395+
#[must_use]
363396
pub struct NeverPatternWithGuard {
364397
#[primary_span]
365398
#[suggestion(code = "", applicability = "maybe-incorrect")]
@@ -368,13 +401,15 @@ pub struct NeverPatternWithGuard {
368401

369402
#[derive(Diagnostic, Clone, Copy)]
370403
#[diag(ast_lowering_arbitrary_expression_in_pattern)]
404+
#[must_use]
371405
pub struct ArbitraryExpressionInPattern {
372406
#[primary_span]
373407
pub span: Span,
374408
}
375409

376410
#[derive(Diagnostic, Clone, Copy)]
377411
#[diag(ast_lowering_inclusive_range_with_no_end)]
412+
#[must_use]
378413
pub struct InclusiveRangeWithNoEnd {
379414
#[primary_span]
380415
pub span: Span,

0 commit comments

Comments
 (0)