1use std::borrow::Cow;
4
5use rustc_errors::codes::*;
6use rustc_errors::{
7 Applicability, Diag, DiagArgValue, DiagSymbolList, EmissionGuarantee, IntoDiagArg, MultiSpan,
8 SubdiagMessageOp, Subdiagnostic,
9};
10use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
11use rustc_middle::ty::{self, Ty};
12use rustc_span::edition::{Edition, LATEST_STABLE_EDITION};
13use rustc_span::{Ident, Span, Symbol};
14
15use crate::fluent_generated as fluent;
16
17#[derive(Diagnostic)]
18#[diag(hir_typeck_base_expression_double_dot, code = E0797)]
19pub(crate) struct BaseExpressionDoubleDot {
20 #[primary_span]
21 pub span: Span,
22 #[suggestion(
23 hir_typeck_base_expression_double_dot_enable_default_field_values,
24 code = "#![feature(default_field_values)]\n",
25 applicability = "machine-applicable",
26 style = "verbose"
27 )]
28 pub default_field_values_suggestion: Option<Span>,
29 #[subdiagnostic]
30 pub default_field_values_help: Option<BaseExpressionDoubleDotEnableDefaultFieldValues>,
31 #[subdiagnostic]
32 pub add_expr: Option<BaseExpressionDoubleDotAddExpr>,
33 #[subdiagnostic]
34 pub remove_dots: Option<BaseExpressionDoubleDotRemove>,
35}
36
37#[derive(Subdiagnostic)]
38#[suggestion(
39 hir_typeck_base_expression_double_dot_remove,
40 code = "",
41 applicability = "machine-applicable",
42 style = "verbose"
43)]
44pub(crate) struct BaseExpressionDoubleDotRemove {
45 #[primary_span]
46 pub span: Span,
47}
48
49#[derive(Subdiagnostic)]
50#[suggestion(
51 hir_typeck_base_expression_double_dot_add_expr,
52 code = "/* expr */",
53 applicability = "has-placeholders",
54 style = "verbose"
55)]
56pub(crate) struct BaseExpressionDoubleDotAddExpr {
57 #[primary_span]
58 pub span: Span,
59}
60
61#[derive(Subdiagnostic)]
62#[help(hir_typeck_base_expression_double_dot_enable_default_field_values)]
63pub(crate) struct BaseExpressionDoubleDotEnableDefaultFieldValues;
64
65#[derive(Diagnostic)]
66#[diag(hir_typeck_field_multiply_specified_in_initializer, code = E0062)]
67pub(crate) struct FieldMultiplySpecifiedInInitializer {
68 #[primary_span]
69 #[label]
70 pub span: Span,
71 #[label(hir_typeck_previous_use_label)]
72 pub prev_span: Span,
73 pub ident: Ident,
74}
75
76#[derive(Diagnostic)]
77#[diag(hir_typeck_return_stmt_outside_of_fn_body, code = E0572)]
78pub(crate) struct ReturnStmtOutsideOfFnBody {
79 #[primary_span]
80 pub span: Span,
81 #[label(hir_typeck_encl_body_label)]
82 pub encl_body_span: Option<Span>,
83 #[label(hir_typeck_encl_fn_label)]
84 pub encl_fn_span: Option<Span>,
85 pub statement_kind: ReturnLikeStatementKind,
86}
87
88pub(crate) enum ReturnLikeStatementKind {
89 Return,
90 Become,
91}
92
93impl IntoDiagArg for ReturnLikeStatementKind {
94 fn into_diag_arg(self) -> DiagArgValue {
95 let kind = match self {
96 Self::Return => "return",
97 Self::Become => "become",
98 }
99 .into();
100
101 DiagArgValue::Str(kind)
102 }
103}
104
105#[derive(Diagnostic)]
106#[diag(hir_typeck_rustcall_incorrect_args)]
107pub(crate) struct RustCallIncorrectArgs {
108 #[primary_span]
109 pub span: Span,
110}
111
112#[derive(Diagnostic)]
113#[diag(hir_typeck_yield_expr_outside_of_coroutine, code = E0627)]
114pub(crate) struct YieldExprOutsideOfCoroutine {
115 #[primary_span]
116 pub span: Span,
117}
118
119#[derive(Diagnostic)]
120#[diag(hir_typeck_struct_expr_non_exhaustive, code = E0639)]
121pub(crate) struct StructExprNonExhaustive {
122 #[primary_span]
123 pub span: Span,
124 pub what: &'static str,
125}
126
127#[derive(Diagnostic)]
128#[diag(hir_typeck_functional_record_update_on_non_struct, code = E0436)]
129pub(crate) struct FunctionalRecordUpdateOnNonStruct {
130 #[primary_span]
131 pub span: Span,
132}
133
134#[derive(Diagnostic)]
135#[diag(hir_typeck_address_of_temporary_taken, code = E0745)]
136pub(crate) struct AddressOfTemporaryTaken {
137 #[primary_span]
138 #[label]
139 pub span: Span,
140}
141
142#[derive(Subdiagnostic)]
143pub(crate) enum AddReturnTypeSuggestion {
144 #[suggestion(
145 hir_typeck_add_return_type_add,
146 code = " -> {found}",
147 applicability = "machine-applicable"
148 )]
149 Add {
150 #[primary_span]
151 span: Span,
152 found: String,
153 },
154 #[suggestion(
155 hir_typeck_add_return_type_missing_here,
156 code = " -> _",
157 applicability = "has-placeholders"
158 )]
159 MissingHere {
160 #[primary_span]
161 span: Span,
162 },
163}
164
165#[derive(Subdiagnostic)]
166pub(crate) enum ExpectedReturnTypeLabel<'tcx> {
167 #[label(hir_typeck_expected_default_return_type)]
168 Unit {
169 #[primary_span]
170 span: Span,
171 },
172 #[label(hir_typeck_expected_return_type)]
173 Other {
174 #[primary_span]
175 span: Span,
176 expected: Ty<'tcx>,
177 },
178}
179
180#[derive(Diagnostic)]
181#[diag(hir_typeck_explicit_destructor, code = E0040)]
182pub(crate) struct ExplicitDestructorCall {
183 #[primary_span]
184 #[label]
185 pub span: Span,
186 #[subdiagnostic]
187 pub sugg: ExplicitDestructorCallSugg,
188}
189
190#[derive(Subdiagnostic)]
191pub(crate) enum ExplicitDestructorCallSugg {
192 #[suggestion(hir_typeck_suggestion, code = "drop", applicability = "maybe-incorrect")]
193 Empty(#[primary_span] Span),
194 #[multipart_suggestion(hir_typeck_suggestion, style = "short")]
195 Snippet {
196 #[suggestion_part(code = "drop(")]
197 lo: Span,
198 #[suggestion_part(code = ")")]
199 hi: Span,
200 },
201}
202
203#[derive(Diagnostic)]
204#[diag(hir_typeck_missing_parentheses_in_range, code = E0689)]
205pub(crate) struct MissingParenthesesInRange {
206 #[primary_span]
207 #[label(hir_typeck_missing_parentheses_in_range)]
208 pub span: Span,
209 pub ty_str: String,
210 pub method_name: String,
211 #[subdiagnostic]
212 pub add_missing_parentheses: Option<AddMissingParenthesesInRange>,
213}
214
215#[derive(LintDiagnostic)]
216pub(crate) enum NeverTypeFallbackFlowingIntoUnsafe {
217 #[help]
218 #[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_call)]
219 Call {
220 #[subdiagnostic]
221 sugg: SuggestAnnotations,
222 },
223 #[help]
224 #[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_method)]
225 Method {
226 #[subdiagnostic]
227 sugg: SuggestAnnotations,
228 },
229 #[help]
230 #[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_path)]
231 Path {
232 #[subdiagnostic]
233 sugg: SuggestAnnotations,
234 },
235 #[help]
236 #[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_union_field)]
237 UnionField {
238 #[subdiagnostic]
239 sugg: SuggestAnnotations,
240 },
241 #[help]
242 #[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_deref)]
243 Deref {
244 #[subdiagnostic]
245 sugg: SuggestAnnotations,
246 },
247}
248
249#[derive(LintDiagnostic)]
250#[help]
251#[diag(hir_typeck_dependency_on_unit_never_type_fallback)]
252pub(crate) struct DependencyOnUnitNeverTypeFallback<'tcx> {
253 #[note]
254 pub obligation_span: Span,
255 pub obligation: ty::Predicate<'tcx>,
256 #[subdiagnostic]
257 pub sugg: SuggestAnnotations,
258}
259
260#[derive(Clone)]
261pub(crate) enum SuggestAnnotation {
262 Unit(Span),
263 Path(Span),
264 Local(Span),
265 Turbo(Span, usize, usize),
266}
267
268#[derive(Clone)]
269pub(crate) struct SuggestAnnotations {
270 pub suggestions: Vec<SuggestAnnotation>,
271}
272impl Subdiagnostic for SuggestAnnotations {
273 fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
274 self,
275 diag: &mut Diag<'_, G>,
276 _: &F,
277 ) {
278 if self.suggestions.is_empty() {
279 return;
280 }
281
282 let mut suggestions = vec![];
283 for suggestion in self.suggestions {
284 match suggestion {
285 SuggestAnnotation::Unit(span) => {
286 suggestions.push((span, "()".to_string()));
287 }
288 SuggestAnnotation::Path(span) => {
289 suggestions.push((span.shrink_to_lo(), "<() as ".to_string()));
290 suggestions.push((span.shrink_to_hi(), ">".to_string()));
291 }
292 SuggestAnnotation::Local(span) => {
293 suggestions.push((span, ": ()".to_string()));
294 }
295 SuggestAnnotation::Turbo(span, n_args, idx) => suggestions.push((
296 span,
297 format!(
298 "::<{}>",
299 (0..n_args)
300 .map(|i| if i == idx { "()" } else { "_" })
301 .collect::<Vec<_>>()
302 .join(", "),
303 ),
304 )),
305 }
306 }
307
308 diag.multipart_suggestion_verbose(
309 "use `()` annotations to avoid fallback changes",
310 suggestions,
311 Applicability::MachineApplicable,
312 );
313 }
314}
315
316#[derive(Subdiagnostic)]
317#[multipart_suggestion(
318 hir_typeck_add_missing_parentheses_in_range,
319 style = "verbose",
320 applicability = "maybe-incorrect"
321)]
322pub(crate) struct AddMissingParenthesesInRange {
323 pub func_name: String,
324 #[suggestion_part(code = "(")]
325 pub left: Span,
326 #[suggestion_part(code = ")")]
327 pub right: Span,
328}
329
330pub(crate) struct TypeMismatchFruTypo {
331 pub expr_span: Span,
333 pub fru_span: Span,
335 pub expr: Option<String>,
337}
338
339impl Subdiagnostic for TypeMismatchFruTypo {
340 fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
341 self,
342 diag: &mut Diag<'_, G>,
343 _f: &F,
344 ) {
345 diag.arg("expr", self.expr.as_deref().unwrap_or("NONE"));
346
347 if self.expr_span.between(self.fru_span).is_empty() {
349 diag.span_note(self.expr_span.to(self.fru_span), fluent::hir_typeck_fru_note);
350 } else {
351 let mut multispan: MultiSpan = vec![self.expr_span, self.fru_span].into();
352 multispan.push_span_label(self.expr_span, fluent::hir_typeck_fru_expr);
353 multispan.push_span_label(self.fru_span, fluent::hir_typeck_fru_expr2);
354 diag.span_note(multispan, fluent::hir_typeck_fru_note);
355 }
356
357 diag.span_suggestion(
358 self.expr_span.shrink_to_hi(),
359 fluent::hir_typeck_fru_suggestion,
360 ", ",
361 Applicability::MaybeIncorrect,
362 );
363 }
364}
365
366#[derive(LintDiagnostic)]
367#[diag(hir_typeck_lossy_provenance_int2ptr)]
368#[help]
369pub(crate) struct LossyProvenanceInt2Ptr<'tcx> {
370 pub expr_ty: Ty<'tcx>,
371 pub cast_ty: Ty<'tcx>,
372 #[subdiagnostic]
373 pub sugg: LossyProvenanceInt2PtrSuggestion,
374}
375
376#[derive(LintDiagnostic)]
377#[diag(hir_typeck_ptr_cast_add_auto_to_object)]
378pub(crate) struct PtrCastAddAutoToObject {
379 pub traits_len: usize,
380 pub traits: DiagSymbolList<String>,
381}
382
383#[derive(Subdiagnostic)]
384#[multipart_suggestion(hir_typeck_suggestion, applicability = "has-placeholders")]
385pub(crate) struct LossyProvenanceInt2PtrSuggestion {
386 #[suggestion_part(code = "(...).with_addr(")]
387 pub lo: Span,
388 #[suggestion_part(code = ")")]
389 pub hi: Span,
390}
391
392#[derive(LintDiagnostic)]
393#[diag(hir_typeck_lossy_provenance_ptr2int)]
394#[help]
395pub(crate) struct LossyProvenancePtr2Int<'tcx> {
396 pub expr_ty: Ty<'tcx>,
397 pub cast_ty: Ty<'tcx>,
398 #[subdiagnostic]
399 pub sugg: LossyProvenancePtr2IntSuggestion<'tcx>,
400}
401
402#[derive(Subdiagnostic)]
403pub(crate) enum LossyProvenancePtr2IntSuggestion<'tcx> {
404 #[multipart_suggestion(hir_typeck_suggestion, applicability = "maybe-incorrect")]
405 NeedsParensCast {
406 #[suggestion_part(code = "(")]
407 expr_span: Span,
408 #[suggestion_part(code = ").addr() as {cast_ty}")]
409 cast_span: Span,
410 cast_ty: Ty<'tcx>,
411 },
412 #[multipart_suggestion(hir_typeck_suggestion, applicability = "maybe-incorrect")]
413 NeedsParens {
414 #[suggestion_part(code = "(")]
415 expr_span: Span,
416 #[suggestion_part(code = ").addr()")]
417 cast_span: Span,
418 },
419 #[suggestion(
420 hir_typeck_suggestion,
421 code = ".addr() as {cast_ty}",
422 applicability = "maybe-incorrect"
423 )]
424 NeedsCast {
425 #[primary_span]
426 cast_span: Span,
427 cast_ty: Ty<'tcx>,
428 },
429 #[suggestion(hir_typeck_suggestion, code = ".addr()", applicability = "maybe-incorrect")]
430 Other {
431 #[primary_span]
432 cast_span: Span,
433 },
434}
435
436#[derive(Subdiagnostic)]
437pub(crate) enum HelpUseLatestEdition {
438 #[help(hir_typeck_help_set_edition_cargo)]
439 #[note(hir_typeck_note_edition_guide)]
440 Cargo { edition: Edition },
441 #[help(hir_typeck_help_set_edition_standalone)]
442 #[note(hir_typeck_note_edition_guide)]
443 Standalone { edition: Edition },
444}
445
446impl HelpUseLatestEdition {
447 pub(crate) fn new() -> Self {
448 let edition = LATEST_STABLE_EDITION;
449 if rustc_session::utils::was_invoked_from_cargo() {
450 Self::Cargo { edition }
451 } else {
452 Self::Standalone { edition }
453 }
454 }
455}
456
457#[derive(Diagnostic)]
458#[diag(hir_typeck_invalid_callee, code = E0618)]
459pub(crate) struct InvalidCallee {
460 #[primary_span]
461 pub span: Span,
462 pub ty: String,
463}
464
465#[derive(Diagnostic)]
466#[diag(hir_typeck_int_to_fat, code = E0606)]
467pub(crate) struct IntToWide<'tcx> {
468 #[primary_span]
469 #[label(hir_typeck_int_to_fat_label)]
470 pub span: Span,
471 pub metadata: &'tcx str,
472 pub expr_ty: String,
473 pub cast_ty: Ty<'tcx>,
474 #[label(hir_typeck_int_to_fat_label_nightly)]
475 pub expr_if_nightly: Option<Span>,
476 pub known_wide: bool,
477}
478
479#[derive(Subdiagnostic)]
480pub(crate) enum OptionResultRefMismatch {
481 #[suggestion(
482 hir_typeck_option_result_copied,
483 code = ".copied()",
484 style = "verbose",
485 applicability = "machine-applicable"
486 )]
487 Copied {
488 #[primary_span]
489 span: Span,
490 def_path: String,
491 },
492 #[suggestion(
493 hir_typeck_option_result_cloned,
494 code = ".cloned()",
495 style = "verbose",
496 applicability = "machine-applicable"
497 )]
498 Cloned {
499 #[primary_span]
500 span: Span,
501 def_path: String,
502 },
503 }
518
519pub(crate) struct RemoveSemiForCoerce {
520 pub expr: Span,
521 pub ret: Span,
522 pub semi: Span,
523}
524
525impl Subdiagnostic for RemoveSemiForCoerce {
526 fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
527 self,
528 diag: &mut Diag<'_, G>,
529 _f: &F,
530 ) {
531 let mut multispan: MultiSpan = self.semi.into();
532 multispan.push_span_label(self.expr, fluent::hir_typeck_remove_semi_for_coerce_expr);
533 multispan.push_span_label(self.ret, fluent::hir_typeck_remove_semi_for_coerce_ret);
534 multispan.push_span_label(self.semi, fluent::hir_typeck_remove_semi_for_coerce_semi);
535 diag.span_note(multispan, fluent::hir_typeck_remove_semi_for_coerce);
536
537 diag.tool_only_span_suggestion(
538 self.semi,
539 fluent::hir_typeck_remove_semi_for_coerce_suggestion,
540 "",
541 Applicability::MaybeIncorrect,
542 );
543 }
544}
545
546#[derive(Diagnostic)]
547#[diag(hir_typeck_const_select_must_be_const)]
548#[help]
549pub(crate) struct ConstSelectMustBeConst {
550 #[primary_span]
551 pub span: Span,
552}
553
554#[derive(Diagnostic)]
555#[diag(hir_typeck_const_select_must_be_fn)]
556#[note]
557#[help]
558pub(crate) struct ConstSelectMustBeFn<'a> {
559 #[primary_span]
560 pub span: Span,
561 pub ty: Ty<'a>,
562}
563
564#[derive(Diagnostic)]
565#[diag(hir_typeck_union_pat_multiple_fields)]
566pub(crate) struct UnionPatMultipleFields {
567 #[primary_span]
568 pub span: Span,
569}
570
571#[derive(Diagnostic)]
572#[diag(hir_typeck_union_pat_dotdot)]
573pub(crate) struct UnionPatDotDot {
574 #[primary_span]
575 pub span: Span,
576}
577
578#[derive(Subdiagnostic)]
579#[multipart_suggestion(
580 hir_typeck_use_is_empty,
581 applicability = "maybe-incorrect",
582 style = "verbose"
583)]
584pub(crate) struct UseIsEmpty {
585 #[suggestion_part(code = "!")]
586 pub lo: Span,
587 #[suggestion_part(code = ".is_empty()")]
588 pub hi: Span,
589 pub expr_ty: String,
590}
591
592#[derive(Diagnostic)]
593#[diag(hir_typeck_arg_mismatch_indeterminate)]
594pub(crate) struct ArgMismatchIndeterminate {
595 #[primary_span]
596 pub span: Span,
597}
598
599#[derive(Subdiagnostic)]
600pub(crate) enum SuggestBoxing {
601 #[note(hir_typeck_suggest_boxing_note)]
602 #[multipart_suggestion(
603 hir_typeck_suggest_boxing_when_appropriate,
604 applicability = "machine-applicable"
605 )]
606 Unit {
607 #[suggestion_part(code = "Box::new(())")]
608 start: Span,
609 #[suggestion_part(code = "")]
610 end: Span,
611 },
612 #[note(hir_typeck_suggest_boxing_note)]
613 AsyncBody,
614 #[note(hir_typeck_suggest_boxing_note)]
615 #[multipart_suggestion(
616 hir_typeck_suggest_boxing_when_appropriate,
617 applicability = "machine-applicable"
618 )]
619 Other {
620 #[suggestion_part(code = "Box::new(")]
621 start: Span,
622 #[suggestion_part(code = ")")]
623 end: Span,
624 },
625}
626
627#[derive(Subdiagnostic)]
628#[suggestion(
629 hir_typeck_suggest_ptr_null_mut,
630 applicability = "maybe-incorrect",
631 style = "verbose",
632 code = "core::ptr::null_mut()"
633)]
634pub(crate) struct SuggestPtrNullMut {
635 #[primary_span]
636 pub span: Span,
637}
638
639#[derive(LintDiagnostic)]
640#[diag(hir_typeck_trivial_cast)]
641#[help]
642pub(crate) struct TrivialCast<'tcx> {
643 pub numeric: bool,
644 pub expr_ty: Ty<'tcx>,
645 pub cast_ty: Ty<'tcx>,
646}
647
648#[derive(Diagnostic)]
649#[diag(hir_typeck_no_associated_item, code = E0599)]
650pub(crate) struct NoAssociatedItem {
651 #[primary_span]
652 pub span: Span,
653 pub item_kind: &'static str,
654 pub item_name: Ident,
655 pub ty_prefix: Cow<'static, str>,
656 pub ty_str: String,
657 pub trait_missing_method: bool,
658}
659
660#[derive(Subdiagnostic)]
661#[note(hir_typeck_candidate_trait_note)]
662pub(crate) struct CandidateTraitNote {
663 #[primary_span]
664 pub span: Span,
665 pub trait_name: String,
666 pub item_name: Ident,
667 pub action_or_ty: String,
668}
669
670#[derive(Diagnostic)]
671#[diag(hir_typeck_cannot_cast_to_bool, code = E0054)]
672pub(crate) struct CannotCastToBool<'tcx> {
673 #[primary_span]
674 pub span: Span,
675 pub expr_ty: Ty<'tcx>,
676 #[subdiagnostic]
677 pub help: CannotCastToBoolHelp,
678}
679
680#[derive(Diagnostic)]
681#[diag(hir_typeck_cast_enum_drop)]
682pub(crate) struct CastEnumDrop<'tcx> {
683 #[primary_span]
684 pub span: Span,
685 pub expr_ty: Ty<'tcx>,
686 pub cast_ty: Ty<'tcx>,
687}
688
689#[derive(Diagnostic)]
690#[diag(hir_typeck_cast_unknown_pointer, code = E0641)]
691pub(crate) struct CastUnknownPointer {
692 #[primary_span]
693 pub span: Span,
694 pub to: bool,
695 #[subdiagnostic]
696 pub sub: CastUnknownPointerSub,
697}
698
699pub(crate) enum CastUnknownPointerSub {
700 To(Span),
701 From(Span),
702}
703
704impl rustc_errors::Subdiagnostic for CastUnknownPointerSub {
705 fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
706 self,
707 diag: &mut Diag<'_, G>,
708 f: &F,
709 ) {
710 match self {
711 CastUnknownPointerSub::To(span) => {
712 let msg = f(diag, crate::fluent_generated::hir_typeck_label_to);
713 diag.span_label(span, msg);
714 let msg = f(diag, crate::fluent_generated::hir_typeck_note);
715 diag.note(msg);
716 }
717 CastUnknownPointerSub::From(span) => {
718 let msg = f(diag, crate::fluent_generated::hir_typeck_label_from);
719 diag.span_label(span, msg);
720 }
721 }
722 }
723}
724
725#[derive(Subdiagnostic)]
726pub(crate) enum CannotCastToBoolHelp {
727 #[suggestion(
728 hir_typeck_suggestion,
729 applicability = "machine-applicable",
730 code = " != 0",
731 style = "verbose"
732 )]
733 Numeric(#[primary_span] Span),
734 #[label(hir_typeck_label)]
735 Unsupported(#[primary_span] Span),
736}
737
738#[derive(Diagnostic)]
739#[diag(hir_typeck_ctor_is_private, code = E0603)]
740pub(crate) struct CtorIsPrivate {
741 #[primary_span]
742 pub span: Span,
743 pub def: String,
744}
745
746#[derive(Subdiagnostic)]
747#[note(hir_typeck_deref_is_empty)]
748pub(crate) struct DerefImplsIsEmpty {
749 #[primary_span]
750 pub span: Span,
751 pub deref_ty: String,
752}
753
754#[derive(Subdiagnostic)]
755#[multipart_suggestion(
756 hir_typeck_convert_using_method,
757 applicability = "machine-applicable",
758 style = "verbose"
759)]
760pub(crate) struct SuggestConvertViaMethod<'tcx> {
761 #[suggestion_part(code = "{sugg}")]
762 pub span: Span,
763 #[suggestion_part(code = "")]
764 pub borrow_removal_span: Option<Span>,
765 pub sugg: String,
766 pub expected: Ty<'tcx>,
767 pub found: Ty<'tcx>,
768}
769
770#[derive(Subdiagnostic)]
771#[note(hir_typeck_note_caller_chooses_ty_for_ty_param)]
772pub(crate) struct NoteCallerChoosesTyForTyParam<'tcx> {
773 pub ty_param_name: Symbol,
774 pub found_ty: Ty<'tcx>,
775}
776
777#[derive(Subdiagnostic)]
778pub(crate) enum SuggestBoxingForReturnImplTrait {
779 #[multipart_suggestion(hir_typeck_rpit_change_return_type, applicability = "maybe-incorrect")]
780 ChangeReturnType {
781 #[suggestion_part(code = "Box<dyn")]
782 start_sp: Span,
783 #[suggestion_part(code = ">")]
784 end_sp: Span,
785 },
786 #[multipart_suggestion(hir_typeck_rpit_box_return_expr, applicability = "maybe-incorrect")]
787 BoxReturnExpr {
788 #[suggestion_part(code = "Box::new(")]
789 starts: Vec<Span>,
790 #[suggestion_part(code = ")")]
791 ends: Vec<Span>,
792 },
793}
794
795#[derive(Diagnostic)]
796#[diag(hir_typeck_self_ctor_from_outer_item, code = E0401)]
797pub(crate) struct SelfCtorFromOuterItem {
798 #[primary_span]
799 pub span: Span,
800 #[label]
801 pub impl_span: Span,
802 #[subdiagnostic]
803 pub sugg: Option<ReplaceWithName>,
804}
805
806#[derive(LintDiagnostic)]
807#[diag(hir_typeck_self_ctor_from_outer_item)]
808pub(crate) struct SelfCtorFromOuterItemLint {
809 #[label]
810 pub impl_span: Span,
811 #[subdiagnostic]
812 pub sugg: Option<ReplaceWithName>,
813}
814
815#[derive(Subdiagnostic)]
816#[suggestion(hir_typeck_suggestion, code = "{name}", applicability = "machine-applicable")]
817pub(crate) struct ReplaceWithName {
818 #[primary_span]
819 pub span: Span,
820 pub name: String,
821}
822
823#[derive(Diagnostic)]
824#[diag(hir_typeck_cast_thin_pointer_to_wide_pointer, code = E0607)]
825pub(crate) struct CastThinPointerToWidePointer<'tcx> {
826 #[primary_span]
827 pub span: Span,
828 pub expr_ty: Ty<'tcx>,
829 pub cast_ty: String,
830 #[note(hir_typeck_teach_help)]
831 pub(crate) teach: bool,
832}
833
834#[derive(Diagnostic)]
835#[diag(hir_typeck_pass_to_variadic_function, code = E0617)]
836pub(crate) struct PassToVariadicFunction<'a, 'tcx> {
837 #[primary_span]
838 pub span: Span,
839 pub ty: Ty<'tcx>,
840 pub cast_ty: &'a str,
841 #[suggestion(code = " as {cast_ty}", applicability = "machine-applicable", style = "verbose")]
842 pub sugg_span: Span,
843 #[note(hir_typeck_teach_help)]
844 pub(crate) teach: bool,
845}
846
847#[derive(Diagnostic)]
848#[diag(hir_typeck_fn_item_to_variadic_function, code = E0617)]
849#[help]
850#[note]
851pub(crate) struct PassFnItemToVariadicFunction {
852 #[primary_span]
853 pub span: Span,
854 #[suggestion(code = " as {replace}", applicability = "machine-applicable", style = "verbose")]
855 pub sugg_span: Span,
856 pub replace: String,
857}
858
859#[derive(Subdiagnostic)]
860#[suggestion(
861 hir_typeck_replace_comma_with_semicolon,
862 applicability = "machine-applicable",
863 style = "verbose",
864 code = "; "
865)]
866pub(crate) struct ReplaceCommaWithSemicolon {
867 #[primary_span]
868 pub comma_span: Span,
869 pub descr: &'static str,
870}
871
872#[derive(LintDiagnostic)]
873#[diag(hir_typeck_supertrait_item_shadowing)]
874pub(crate) struct SupertraitItemShadowing {
875 pub item: Symbol,
876 pub subtrait: Symbol,
877 #[subdiagnostic]
878 pub shadower: SupertraitItemShadower,
879 #[subdiagnostic]
880 pub shadowee: SupertraitItemShadowee,
881}
882
883#[derive(Subdiagnostic)]
884#[note(hir_typeck_supertrait_item_shadower)]
885pub(crate) struct SupertraitItemShadower {
886 pub subtrait: Symbol,
887 #[primary_span]
888 pub span: Span,
889}
890
891#[derive(Subdiagnostic)]
892pub(crate) enum SupertraitItemShadowee {
893 #[note(hir_typeck_supertrait_item_shadowee)]
894 Labeled {
895 #[primary_span]
896 span: Span,
897 supertrait: Symbol,
898 },
899 #[note(hir_typeck_supertrait_item_multiple_shadowee)]
900 Several {
901 #[primary_span]
902 spans: MultiSpan,
903 traits: DiagSymbolList,
904 },
905}