]> git.proxmox.com Git - rustc.git/blob - compiler/rustc_mir_build/src/errors.rs
New upstream version 1.76.0+dfsg1
[rustc.git] / compiler / rustc_mir_build / src / errors.rs
1 use crate::fluent_generated as fluent;
2 use rustc_errors::DiagnosticArgValue;
3 use rustc_errors::{
4 error_code, AddToDiagnostic, Applicability, DiagCtxt, Diagnostic, DiagnosticBuilder,
5 ErrorGuaranteed, IntoDiagnostic, MultiSpan, SubdiagnosticMessage,
6 };
7 use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
8 use rustc_middle::ty::{self, Ty};
9 use rustc_pattern_analysis::{errors::Uncovered, rustc::RustcMatchCheckCtxt};
10 use rustc_span::symbol::Symbol;
11 use rustc_span::Span;
12
13 #[derive(LintDiagnostic)]
14 #[diag(mir_build_unconditional_recursion)]
15 #[help]
16 pub struct UnconditionalRecursion {
17 #[label]
18 pub span: Span,
19 #[label(mir_build_unconditional_recursion_call_site_label)]
20 pub call_sites: Vec<Span>,
21 }
22
23 #[derive(LintDiagnostic)]
24 #[diag(mir_build_unsafe_op_in_unsafe_fn_call_to_unsafe_fn_requires_unsafe)]
25 #[note]
26 pub struct UnsafeOpInUnsafeFnCallToUnsafeFunctionRequiresUnsafe<'a> {
27 #[label]
28 pub span: Span,
29 pub function: &'a str,
30 #[subdiagnostic]
31 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedLintNote>,
32 }
33
34 #[derive(LintDiagnostic)]
35 #[diag(mir_build_unsafe_op_in_unsafe_fn_call_to_unsafe_fn_requires_unsafe_nameless)]
36 #[note]
37 pub struct UnsafeOpInUnsafeFnCallToUnsafeFunctionRequiresUnsafeNameless {
38 #[label]
39 pub span: Span,
40 #[subdiagnostic]
41 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedLintNote>,
42 }
43
44 #[derive(LintDiagnostic)]
45 #[diag(mir_build_unsafe_op_in_unsafe_fn_inline_assembly_requires_unsafe)]
46 #[note]
47 pub struct UnsafeOpInUnsafeFnUseOfInlineAssemblyRequiresUnsafe {
48 #[label]
49 pub span: Span,
50 #[subdiagnostic]
51 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedLintNote>,
52 }
53
54 #[derive(LintDiagnostic)]
55 #[diag(mir_build_unsafe_op_in_unsafe_fn_initializing_type_with_requires_unsafe)]
56 #[note]
57 pub struct UnsafeOpInUnsafeFnInitializingTypeWithRequiresUnsafe {
58 #[label]
59 pub span: Span,
60 #[subdiagnostic]
61 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedLintNote>,
62 }
63
64 #[derive(LintDiagnostic)]
65 #[diag(mir_build_unsafe_op_in_unsafe_fn_mutable_static_requires_unsafe)]
66 #[note]
67 pub struct UnsafeOpInUnsafeFnUseOfMutableStaticRequiresUnsafe {
68 #[label]
69 pub span: Span,
70 #[subdiagnostic]
71 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedLintNote>,
72 }
73
74 #[derive(LintDiagnostic)]
75 #[diag(mir_build_unsafe_op_in_unsafe_fn_extern_static_requires_unsafe)]
76 #[note]
77 pub struct UnsafeOpInUnsafeFnUseOfExternStaticRequiresUnsafe {
78 #[label]
79 pub span: Span,
80 #[subdiagnostic]
81 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedLintNote>,
82 }
83
84 #[derive(LintDiagnostic)]
85 #[diag(mir_build_unsafe_op_in_unsafe_fn_deref_raw_pointer_requires_unsafe)]
86 #[note]
87 pub struct UnsafeOpInUnsafeFnDerefOfRawPointerRequiresUnsafe {
88 #[label]
89 pub span: Span,
90 #[subdiagnostic]
91 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedLintNote>,
92 }
93
94 #[derive(LintDiagnostic)]
95 #[diag(mir_build_unsafe_op_in_unsafe_fn_union_field_requires_unsafe)]
96 #[note]
97 pub struct UnsafeOpInUnsafeFnAccessToUnionFieldRequiresUnsafe {
98 #[label]
99 pub span: Span,
100 #[subdiagnostic]
101 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedLintNote>,
102 }
103
104 #[derive(LintDiagnostic)]
105 #[diag(mir_build_unsafe_op_in_unsafe_fn_mutation_of_layout_constrained_field_requires_unsafe)]
106 #[note]
107 pub struct UnsafeOpInUnsafeFnMutationOfLayoutConstrainedFieldRequiresUnsafe {
108 #[label]
109 pub span: Span,
110 #[subdiagnostic]
111 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedLintNote>,
112 }
113
114 #[derive(LintDiagnostic)]
115 #[diag(mir_build_unsafe_op_in_unsafe_fn_borrow_of_layout_constrained_field_requires_unsafe)]
116 pub struct UnsafeOpInUnsafeFnBorrowOfLayoutConstrainedFieldRequiresUnsafe {
117 #[label]
118 pub span: Span,
119 #[subdiagnostic]
120 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedLintNote>,
121 }
122
123 #[derive(LintDiagnostic)]
124 #[diag(mir_build_unsafe_op_in_unsafe_fn_call_to_fn_with_requires_unsafe)]
125 #[help]
126 pub struct UnsafeOpInUnsafeFnCallToFunctionWithRequiresUnsafe<'a> {
127 #[label]
128 pub span: Span,
129 pub function: &'a str,
130 pub missing_target_features: DiagnosticArgValue<'a>,
131 pub missing_target_features_count: usize,
132 #[note]
133 pub note: Option<()>,
134 pub build_target_features: DiagnosticArgValue<'a>,
135 pub build_target_features_count: usize,
136 #[subdiagnostic]
137 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedLintNote>,
138 }
139
140 #[derive(Diagnostic)]
141 #[diag(mir_build_call_to_unsafe_fn_requires_unsafe, code = "E0133")]
142 #[note]
143 pub struct CallToUnsafeFunctionRequiresUnsafe<'a> {
144 #[primary_span]
145 #[label]
146 pub span: Span,
147 pub function: &'a str,
148 #[subdiagnostic]
149 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
150 }
151
152 #[derive(Diagnostic)]
153 #[diag(mir_build_call_to_unsafe_fn_requires_unsafe_nameless, code = "E0133")]
154 #[note]
155 pub struct CallToUnsafeFunctionRequiresUnsafeNameless {
156 #[primary_span]
157 #[label]
158 pub span: Span,
159 #[subdiagnostic]
160 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
161 }
162
163 #[derive(Diagnostic)]
164 #[diag(mir_build_call_to_unsafe_fn_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = "E0133")]
165 #[note]
166 pub struct CallToUnsafeFunctionRequiresUnsafeUnsafeOpInUnsafeFnAllowed<'a> {
167 #[primary_span]
168 #[label]
169 pub span: Span,
170 pub function: &'a str,
171 #[subdiagnostic]
172 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
173 }
174
175 #[derive(Diagnostic)]
176 #[diag(
177 mir_build_call_to_unsafe_fn_requires_unsafe_nameless_unsafe_op_in_unsafe_fn_allowed,
178 code = "E0133"
179 )]
180 #[note]
181 pub struct CallToUnsafeFunctionRequiresUnsafeNamelessUnsafeOpInUnsafeFnAllowed {
182 #[primary_span]
183 #[label]
184 pub span: Span,
185 #[subdiagnostic]
186 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
187 }
188
189 #[derive(Diagnostic)]
190 #[diag(mir_build_inline_assembly_requires_unsafe, code = "E0133")]
191 #[note]
192 pub struct UseOfInlineAssemblyRequiresUnsafe {
193 #[primary_span]
194 #[label]
195 pub span: Span,
196 #[subdiagnostic]
197 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
198 }
199
200 #[derive(Diagnostic)]
201 #[diag(mir_build_inline_assembly_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = "E0133")]
202 #[note]
203 pub struct UseOfInlineAssemblyRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
204 #[primary_span]
205 #[label]
206 pub span: Span,
207 #[subdiagnostic]
208 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
209 }
210
211 #[derive(Diagnostic)]
212 #[diag(mir_build_initializing_type_with_requires_unsafe, code = "E0133")]
213 #[note]
214 pub struct InitializingTypeWithRequiresUnsafe {
215 #[primary_span]
216 #[label]
217 pub span: Span,
218 #[subdiagnostic]
219 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
220 }
221
222 #[derive(Diagnostic)]
223 #[diag(
224 mir_build_initializing_type_with_requires_unsafe_unsafe_op_in_unsafe_fn_allowed,
225 code = "E0133"
226 )]
227 #[note]
228 pub struct InitializingTypeWithRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
229 #[primary_span]
230 #[label]
231 pub span: Span,
232 #[subdiagnostic]
233 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
234 }
235
236 #[derive(Diagnostic)]
237 #[diag(mir_build_mutable_static_requires_unsafe, code = "E0133")]
238 #[note]
239 pub struct UseOfMutableStaticRequiresUnsafe {
240 #[primary_span]
241 #[label]
242 pub span: Span,
243 #[subdiagnostic]
244 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
245 }
246
247 #[derive(Diagnostic)]
248 #[diag(mir_build_mutable_static_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = "E0133")]
249 #[note]
250 pub struct UseOfMutableStaticRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
251 #[primary_span]
252 #[label]
253 pub span: Span,
254 #[subdiagnostic]
255 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
256 }
257
258 #[derive(Diagnostic)]
259 #[diag(mir_build_extern_static_requires_unsafe, code = "E0133")]
260 #[note]
261 pub struct UseOfExternStaticRequiresUnsafe {
262 #[primary_span]
263 #[label]
264 pub span: Span,
265 #[subdiagnostic]
266 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
267 }
268
269 #[derive(Diagnostic)]
270 #[diag(mir_build_extern_static_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = "E0133")]
271 #[note]
272 pub struct UseOfExternStaticRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
273 #[primary_span]
274 #[label]
275 pub span: Span,
276 #[subdiagnostic]
277 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
278 }
279
280 #[derive(Diagnostic)]
281 #[diag(mir_build_deref_raw_pointer_requires_unsafe, code = "E0133")]
282 #[note]
283 pub struct DerefOfRawPointerRequiresUnsafe {
284 #[primary_span]
285 #[label]
286 pub span: Span,
287 #[subdiagnostic]
288 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
289 }
290
291 #[derive(Diagnostic)]
292 #[diag(mir_build_deref_raw_pointer_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = "E0133")]
293 #[note]
294 pub struct DerefOfRawPointerRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
295 #[primary_span]
296 #[label]
297 pub span: Span,
298 #[subdiagnostic]
299 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
300 }
301
302 #[derive(Diagnostic)]
303 #[diag(mir_build_union_field_requires_unsafe, code = "E0133")]
304 #[note]
305 pub struct AccessToUnionFieldRequiresUnsafe {
306 #[primary_span]
307 #[label]
308 pub span: Span,
309 #[subdiagnostic]
310 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
311 }
312
313 #[derive(Diagnostic)]
314 #[diag(mir_build_union_field_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = "E0133")]
315 #[note]
316 pub struct AccessToUnionFieldRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
317 #[primary_span]
318 #[label]
319 pub span: Span,
320 #[subdiagnostic]
321 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
322 }
323
324 #[derive(Diagnostic)]
325 #[diag(mir_build_mutation_of_layout_constrained_field_requires_unsafe, code = "E0133")]
326 #[note]
327 pub struct MutationOfLayoutConstrainedFieldRequiresUnsafe {
328 #[primary_span]
329 #[label]
330 pub span: Span,
331 #[subdiagnostic]
332 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
333 }
334
335 #[derive(Diagnostic)]
336 #[diag(
337 mir_build_mutation_of_layout_constrained_field_requires_unsafe_unsafe_op_in_unsafe_fn_allowed,
338 code = "E0133"
339 )]
340 #[note]
341 pub struct MutationOfLayoutConstrainedFieldRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
342 #[primary_span]
343 #[label]
344 pub span: Span,
345 #[subdiagnostic]
346 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
347 }
348
349 #[derive(Diagnostic)]
350 #[diag(mir_build_borrow_of_layout_constrained_field_requires_unsafe, code = "E0133")]
351 #[note]
352 pub struct BorrowOfLayoutConstrainedFieldRequiresUnsafe {
353 #[primary_span]
354 #[label]
355 pub span: Span,
356 #[subdiagnostic]
357 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
358 }
359
360 #[derive(Diagnostic)]
361 #[diag(
362 mir_build_borrow_of_layout_constrained_field_requires_unsafe_unsafe_op_in_unsafe_fn_allowed,
363 code = "E0133"
364 )]
365 #[note]
366 pub struct BorrowOfLayoutConstrainedFieldRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
367 #[primary_span]
368 #[label]
369 pub span: Span,
370 #[subdiagnostic]
371 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
372 }
373
374 #[derive(Diagnostic)]
375 #[diag(mir_build_call_to_fn_with_requires_unsafe, code = "E0133")]
376 #[help]
377 pub struct CallToFunctionWithRequiresUnsafe<'a> {
378 #[primary_span]
379 #[label]
380 pub span: Span,
381 pub function: &'a str,
382 pub missing_target_features: DiagnosticArgValue<'a>,
383 pub missing_target_features_count: usize,
384 #[note]
385 pub note: Option<()>,
386 pub build_target_features: DiagnosticArgValue<'a>,
387 pub build_target_features_count: usize,
388 #[subdiagnostic]
389 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
390 }
391
392 #[derive(Diagnostic)]
393 #[diag(mir_build_call_to_fn_with_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = "E0133")]
394 #[help]
395 pub struct CallToFunctionWithRequiresUnsafeUnsafeOpInUnsafeFnAllowed<'a> {
396 #[primary_span]
397 #[label]
398 pub span: Span,
399 pub function: &'a str,
400 pub missing_target_features: DiagnosticArgValue<'a>,
401 pub missing_target_features_count: usize,
402 #[note]
403 pub note: Option<()>,
404 pub build_target_features: DiagnosticArgValue<'a>,
405 pub build_target_features_count: usize,
406 #[subdiagnostic]
407 pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
408 }
409
410 #[derive(Subdiagnostic)]
411 #[label(mir_build_unsafe_not_inherited)]
412 pub struct UnsafeNotInheritedNote {
413 #[primary_span]
414 pub span: Span,
415 }
416
417 pub struct UnsafeNotInheritedLintNote {
418 pub signature_span: Span,
419 pub body_span: Span,
420 }
421
422 impl AddToDiagnostic for UnsafeNotInheritedLintNote {
423 fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
424 where
425 F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
426 {
427 diag.span_note(self.signature_span, fluent::mir_build_unsafe_fn_safe_body);
428 let body_start = self.body_span.shrink_to_lo();
429 let body_end = self.body_span.shrink_to_hi();
430 diag.tool_only_multipart_suggestion(
431 fluent::mir_build_wrap_suggestion,
432 vec![(body_start, "{ unsafe ".into()), (body_end, "}".into())],
433 Applicability::MaybeIncorrect,
434 );
435 }
436 }
437
438 #[derive(LintDiagnostic)]
439 #[diag(mir_build_unused_unsafe)]
440 pub struct UnusedUnsafe {
441 #[label]
442 pub span: Span,
443 #[subdiagnostic]
444 pub enclosing: Option<UnusedUnsafeEnclosing>,
445 }
446
447 #[derive(Subdiagnostic)]
448 pub enum UnusedUnsafeEnclosing {
449 #[label(mir_build_unused_unsafe_enclosing_block_label)]
450 Block {
451 #[primary_span]
452 span: Span,
453 },
454 }
455
456 pub(crate) struct NonExhaustivePatternsTypeNotEmpty<'p, 'tcx, 'm> {
457 pub cx: &'m RustcMatchCheckCtxt<'p, 'tcx>,
458 pub expr_span: Span,
459 pub span: Span,
460 pub ty: Ty<'tcx>,
461 }
462
463 impl<'a> IntoDiagnostic<'a> for NonExhaustivePatternsTypeNotEmpty<'_, '_, '_> {
464 fn into_diagnostic(self, dcx: &'a DiagCtxt) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
465 let mut diag = dcx.struct_span_err_with_code(
466 self.span,
467 fluent::mir_build_non_exhaustive_patterns_type_not_empty,
468 error_code!(E0004),
469 );
470
471 let peeled_ty = self.ty.peel_refs();
472 diag.set_arg("ty", self.ty);
473 diag.set_arg("peeled_ty", peeled_ty);
474
475 if let ty::Adt(def, _) = peeled_ty.kind() {
476 let def_span = self
477 .cx
478 .tcx
479 .hir()
480 .get_if_local(def.did())
481 .and_then(|node| node.ident())
482 .map(|ident| ident.span)
483 .unwrap_or_else(|| self.cx.tcx.def_span(def.did()));
484
485 // workaround to make test pass
486 let mut span: MultiSpan = def_span.into();
487 span.push_span_label(def_span, "");
488
489 diag.span_note(span, fluent::mir_build_def_note);
490 }
491
492 let is_variant_list_non_exhaustive = matches!(self.ty.kind(),
493 ty::Adt(def, _) if def.is_variant_list_non_exhaustive() && !def.did().is_local());
494 if is_variant_list_non_exhaustive {
495 diag.note(fluent::mir_build_non_exhaustive_type_note);
496 } else {
497 diag.note(fluent::mir_build_type_note);
498 }
499
500 if let ty::Ref(_, sub_ty, _) = self.ty.kind() {
501 if !sub_ty.is_inhabited_from(self.cx.tcx, self.cx.module, self.cx.param_env) {
502 diag.note(fluent::mir_build_reference_note);
503 }
504 }
505
506 let mut suggestion = None;
507 let sm = self.cx.tcx.sess.source_map();
508 if self.span.eq_ctxt(self.expr_span) {
509 // Get the span for the empty match body `{}`.
510 let (indentation, more) = if let Some(snippet) = sm.indentation_before(self.span) {
511 (format!("\n{snippet}"), " ")
512 } else {
513 (" ".to_string(), "")
514 };
515 suggestion = Some((
516 self.span.shrink_to_hi().with_hi(self.expr_span.hi()),
517 format!(" {{{indentation}{more}_ => todo!(),{indentation}}}",),
518 ));
519 }
520
521 if let Some((span, sugg)) = suggestion {
522 diag.span_suggestion_verbose(
523 span,
524 fluent::mir_build_suggestion,
525 sugg,
526 Applicability::HasPlaceholders,
527 );
528 } else {
529 diag.help(fluent::mir_build_help);
530 }
531
532 diag
533 }
534 }
535
536 #[derive(Subdiagnostic)]
537 #[note(mir_build_non_exhaustive_match_all_arms_guarded)]
538 pub struct NonExhaustiveMatchAllArmsGuarded;
539
540 #[derive(Diagnostic)]
541 #[diag(mir_build_static_in_pattern, code = "E0158")]
542 pub struct StaticInPattern {
543 #[primary_span]
544 pub span: Span,
545 }
546
547 #[derive(Diagnostic)]
548 #[diag(mir_build_assoc_const_in_pattern, code = "E0158")]
549 pub struct AssocConstInPattern {
550 #[primary_span]
551 pub span: Span,
552 }
553
554 #[derive(Diagnostic)]
555 #[diag(mir_build_const_param_in_pattern, code = "E0158")]
556 pub struct ConstParamInPattern {
557 #[primary_span]
558 pub span: Span,
559 }
560
561 #[derive(Diagnostic)]
562 #[diag(mir_build_non_const_path, code = "E0080")]
563 pub struct NonConstPath {
564 #[primary_span]
565 pub span: Span,
566 }
567
568 #[derive(LintDiagnostic)]
569 #[diag(mir_build_unreachable_pattern)]
570 pub struct UnreachablePattern {
571 #[label]
572 pub span: Option<Span>,
573 #[label(mir_build_catchall_label)]
574 pub catchall: Option<Span>,
575 }
576
577 #[derive(Diagnostic)]
578 #[diag(mir_build_const_pattern_depends_on_generic_parameter)]
579 pub struct ConstPatternDependsOnGenericParameter {
580 #[primary_span]
581 pub span: Span,
582 }
583
584 #[derive(Diagnostic)]
585 #[diag(mir_build_could_not_eval_const_pattern)]
586 pub struct CouldNotEvalConstPattern {
587 #[primary_span]
588 pub span: Span,
589 }
590
591 #[derive(Diagnostic)]
592 #[diag(mir_build_lower_range_bound_must_be_less_than_or_equal_to_upper, code = "E0030")]
593 pub struct LowerRangeBoundMustBeLessThanOrEqualToUpper {
594 #[primary_span]
595 #[label]
596 pub span: Span,
597 #[note(mir_build_teach_note)]
598 pub teach: Option<()>,
599 }
600
601 #[derive(Diagnostic)]
602 #[diag(mir_build_literal_in_range_out_of_bounds)]
603 pub struct LiteralOutOfRange<'tcx> {
604 #[primary_span]
605 #[label]
606 pub span: Span,
607 pub ty: Ty<'tcx>,
608 pub min: i128,
609 pub max: u128,
610 }
611
612 #[derive(Diagnostic)]
613 #[diag(mir_build_lower_range_bound_must_be_less_than_upper, code = "E0579")]
614 pub struct LowerRangeBoundMustBeLessThanUpper {
615 #[primary_span]
616 pub span: Span,
617 }
618
619 #[derive(LintDiagnostic)]
620 #[diag(mir_build_leading_irrefutable_let_patterns)]
621 #[note]
622 #[help]
623 pub struct LeadingIrrefutableLetPatterns {
624 pub count: usize,
625 }
626
627 #[derive(LintDiagnostic)]
628 #[diag(mir_build_trailing_irrefutable_let_patterns)]
629 #[note]
630 #[help]
631 pub struct TrailingIrrefutableLetPatterns {
632 pub count: usize,
633 }
634
635 #[derive(LintDiagnostic)]
636 #[diag(mir_build_bindings_with_variant_name, code = "E0170")]
637 pub struct BindingsWithVariantName {
638 #[suggestion(code = "{ty_path}::{name}", applicability = "machine-applicable")]
639 pub suggestion: Option<Span>,
640 pub ty_path: String,
641 pub name: Symbol,
642 }
643
644 #[derive(LintDiagnostic)]
645 #[diag(mir_build_irrefutable_let_patterns_if_let)]
646 #[note]
647 #[help]
648 pub struct IrrefutableLetPatternsIfLet {
649 pub count: usize,
650 }
651
652 #[derive(LintDiagnostic)]
653 #[diag(mir_build_irrefutable_let_patterns_if_let_guard)]
654 #[note]
655 #[help]
656 pub struct IrrefutableLetPatternsIfLetGuard {
657 pub count: usize,
658 }
659
660 #[derive(LintDiagnostic)]
661 #[diag(mir_build_irrefutable_let_patterns_let_else)]
662 #[note]
663 #[help]
664 pub struct IrrefutableLetPatternsLetElse {
665 pub count: usize,
666 }
667
668 #[derive(LintDiagnostic)]
669 #[diag(mir_build_irrefutable_let_patterns_while_let)]
670 #[note]
671 #[help]
672 pub struct IrrefutableLetPatternsWhileLet {
673 pub count: usize,
674 }
675
676 #[derive(Diagnostic)]
677 #[diag(mir_build_borrow_of_moved_value)]
678 pub struct BorrowOfMovedValue<'tcx> {
679 #[primary_span]
680 #[label]
681 #[label(mir_build_occurs_because_label)]
682 pub binding_span: Span,
683 #[label(mir_build_value_borrowed_label)]
684 pub conflicts_ref: Vec<Span>,
685 pub name: Symbol,
686 pub ty: Ty<'tcx>,
687 #[suggestion(code = "ref ", applicability = "machine-applicable")]
688 pub suggest_borrowing: Option<Span>,
689 }
690
691 #[derive(Diagnostic)]
692 #[diag(mir_build_multiple_mut_borrows)]
693 pub struct MultipleMutBorrows {
694 #[primary_span]
695 pub span: Span,
696 #[subdiagnostic]
697 pub occurrences: Vec<Conflict>,
698 }
699
700 #[derive(Diagnostic)]
701 #[diag(mir_build_already_borrowed)]
702 pub struct AlreadyBorrowed {
703 #[primary_span]
704 pub span: Span,
705 #[subdiagnostic]
706 pub occurrences: Vec<Conflict>,
707 }
708
709 #[derive(Diagnostic)]
710 #[diag(mir_build_already_mut_borrowed)]
711 pub struct AlreadyMutBorrowed {
712 #[primary_span]
713 pub span: Span,
714 #[subdiagnostic]
715 pub occurrences: Vec<Conflict>,
716 }
717
718 #[derive(Diagnostic)]
719 #[diag(mir_build_moved_while_borrowed)]
720 pub struct MovedWhileBorrowed {
721 #[primary_span]
722 pub span: Span,
723 #[subdiagnostic]
724 pub occurrences: Vec<Conflict>,
725 }
726
727 #[derive(Subdiagnostic)]
728 pub enum Conflict {
729 #[label(mir_build_mutable_borrow)]
730 Mut {
731 #[primary_span]
732 span: Span,
733 name: Symbol,
734 },
735 #[label(mir_build_borrow)]
736 Ref {
737 #[primary_span]
738 span: Span,
739 name: Symbol,
740 },
741 #[label(mir_build_moved)]
742 Moved {
743 #[primary_span]
744 span: Span,
745 name: Symbol,
746 },
747 }
748
749 #[derive(Diagnostic)]
750 #[diag(mir_build_union_pattern)]
751 pub struct UnionPattern {
752 #[primary_span]
753 pub span: Span,
754 }
755
756 #[derive(Diagnostic)]
757 #[diag(mir_build_type_not_structural)]
758 #[note(mir_build_type_not_structural_tip)]
759 #[note(mir_build_type_not_structural_more_info)]
760 pub struct TypeNotStructural<'tcx> {
761 #[primary_span]
762 pub span: Span,
763 pub non_sm_ty: Ty<'tcx>,
764 }
765
766 #[derive(Diagnostic)]
767 #[diag(mir_build_invalid_pattern)]
768 pub struct InvalidPattern<'tcx> {
769 #[primary_span]
770 pub span: Span,
771 pub non_sm_ty: Ty<'tcx>,
772 }
773
774 #[derive(Diagnostic)]
775 #[diag(mir_build_unsized_pattern)]
776 pub struct UnsizedPattern<'tcx> {
777 #[primary_span]
778 pub span: Span,
779 pub non_sm_ty: Ty<'tcx>,
780 }
781
782 #[derive(LintDiagnostic)]
783 #[diag(mir_build_float_pattern)]
784 pub struct FloatPattern;
785
786 #[derive(LintDiagnostic)]
787 #[diag(mir_build_pointer_pattern)]
788 pub struct PointerPattern;
789
790 #[derive(LintDiagnostic)]
791 #[diag(mir_build_indirect_structural_match)]
792 #[note(mir_build_type_not_structural_tip)]
793 #[note(mir_build_type_not_structural_more_info)]
794 pub struct IndirectStructuralMatch<'tcx> {
795 pub non_sm_ty: Ty<'tcx>,
796 }
797
798 #[derive(LintDiagnostic)]
799 #[diag(mir_build_nontrivial_structural_match)]
800 #[note(mir_build_type_not_structural_tip)]
801 #[note(mir_build_type_not_structural_more_info)]
802 pub struct NontrivialStructuralMatch<'tcx> {
803 pub non_sm_ty: Ty<'tcx>,
804 }
805
806 #[derive(LintDiagnostic)]
807 #[diag(mir_build_non_partial_eq_match)]
808 pub struct NonPartialEqMatch<'tcx> {
809 pub non_peq_ty: Ty<'tcx>,
810 }
811
812 #[derive(Diagnostic)]
813 #[diag(mir_build_pattern_not_covered, code = "E0005")]
814 pub(crate) struct PatternNotCovered<'s, 'tcx> {
815 #[primary_span]
816 pub span: Span,
817 pub origin: &'s str,
818 #[subdiagnostic]
819 pub uncovered: Uncovered<'tcx>,
820 #[subdiagnostic]
821 pub inform: Option<Inform>,
822 #[subdiagnostic]
823 pub interpreted_as_const: Option<InterpretedAsConst>,
824 #[subdiagnostic]
825 pub adt_defined_here: Option<AdtDefinedHere<'tcx>>,
826 #[note(mir_build_privately_uninhabited)]
827 pub witness_1_is_privately_uninhabited: Option<()>,
828 #[note(mir_build_pattern_ty)]
829 pub _p: (),
830 pub pattern_ty: Ty<'tcx>,
831 #[subdiagnostic]
832 pub let_suggestion: Option<SuggestLet>,
833 #[subdiagnostic]
834 pub misc_suggestion: Option<MiscPatternSuggestion>,
835 }
836
837 #[derive(Subdiagnostic)]
838 #[note(mir_build_inform_irrefutable)]
839 #[note(mir_build_more_information)]
840 pub struct Inform;
841
842 pub struct AdtDefinedHere<'tcx> {
843 pub adt_def_span: Span,
844 pub ty: Ty<'tcx>,
845 pub variants: Vec<Variant>,
846 }
847
848 pub struct Variant {
849 pub span: Span,
850 }
851
852 impl<'tcx> AddToDiagnostic for AdtDefinedHere<'tcx> {
853 fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
854 where
855 F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
856 {
857 diag.set_arg("ty", self.ty);
858 let mut spans = MultiSpan::from(self.adt_def_span);
859
860 for Variant { span } in self.variants {
861 spans.push_span_label(span, fluent::mir_build_variant_defined_here);
862 }
863
864 diag.span_note(spans, fluent::mir_build_adt_defined_here);
865 }
866 }
867
868 #[derive(Subdiagnostic)]
869 #[suggestion(
870 mir_build_interpreted_as_const,
871 code = "{variable}_var",
872 applicability = "maybe-incorrect"
873 )]
874 #[label(mir_build_confused)]
875 pub struct InterpretedAsConst {
876 #[primary_span]
877 pub span: Span,
878 pub variable: String,
879 }
880
881 #[derive(Subdiagnostic)]
882 pub enum SuggestLet {
883 #[multipart_suggestion(mir_build_suggest_if_let, applicability = "has-placeholders")]
884 If {
885 #[suggestion_part(code = "if ")]
886 start_span: Span,
887 #[suggestion_part(code = " {{ todo!() }}")]
888 semi_span: Span,
889 count: usize,
890 },
891 #[suggestion(
892 mir_build_suggest_let_else,
893 code = " else {{ todo!() }}",
894 applicability = "has-placeholders"
895 )]
896 Else {
897 #[primary_span]
898 end_span: Span,
899 count: usize,
900 },
901 }
902
903 #[derive(Subdiagnostic)]
904 pub enum MiscPatternSuggestion {
905 #[suggestion(
906 mir_build_suggest_attempted_int_lit,
907 code = "_",
908 applicability = "maybe-incorrect"
909 )]
910 AttemptedIntegerLiteral {
911 #[primary_span]
912 start_span: Span,
913 },
914 }
915
916 #[derive(Diagnostic)]
917 #[diag(mir_build_rustc_box_attribute_error)]
918 pub struct RustcBoxAttributeError {
919 #[primary_span]
920 pub span: Span,
921 #[subdiagnostic]
922 pub reason: RustcBoxAttrReason,
923 }
924
925 #[derive(Subdiagnostic)]
926 pub enum RustcBoxAttrReason {
927 #[note(mir_build_attributes)]
928 Attributes,
929 #[note(mir_build_not_box)]
930 NotBoxNew,
931 #[note(mir_build_missing_box)]
932 MissingBox,
933 }