]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_trait_selection/src/errors.rs
fix: use LocalDefId instead of HirId in trait res
[rust.git] / compiler / rustc_trait_selection / src / errors.rs
1 use rustc_errors::{fluent, ErrorGuaranteed, Handler, IntoDiagnostic};
2 use rustc_macros::Diagnostic;
3 use rustc_middle::ty::{self, PolyTraitRef, Ty};
4 use rustc_span::{Span, Symbol};
5
6 #[derive(Diagnostic)]
7 #[diag(trait_selection_dump_vtable_entries)]
8 pub struct DumpVTableEntries<'a> {
9     #[primary_span]
10     pub span: Span,
11     pub trait_ref: PolyTraitRef<'a>,
12     pub entries: String,
13 }
14
15 #[derive(Diagnostic)]
16 #[diag(trait_selection_unable_to_construct_constant_value)]
17 pub struct UnableToConstructConstantValue<'a> {
18     #[primary_span]
19     pub span: Span,
20     pub unevaluated: ty::UnevaluatedConst<'a>,
21 }
22
23 #[derive(Diagnostic)]
24 #[diag(trait_selection_empty_on_clause_in_rustc_on_unimplemented, code = "E0232")]
25 pub struct EmptyOnClauseInOnUnimplemented {
26     #[primary_span]
27     #[label]
28     pub span: Span,
29 }
30
31 #[derive(Diagnostic)]
32 #[diag(trait_selection_invalid_on_clause_in_rustc_on_unimplemented, code = "E0232")]
33 pub struct InvalidOnClauseInOnUnimplemented {
34     #[primary_span]
35     #[label]
36     pub span: Span,
37 }
38
39 #[derive(Diagnostic)]
40 #[diag(trait_selection_no_value_in_rustc_on_unimplemented, code = "E0232")]
41 #[note]
42 pub struct NoValueInOnUnimplemented {
43     #[primary_span]
44     #[label]
45     pub span: Span,
46 }
47
48 pub struct NegativePositiveConflict<'tcx> {
49     pub impl_span: Span,
50     pub trait_desc: ty::TraitRef<'tcx>,
51     pub self_ty: Option<Ty<'tcx>>,
52     pub negative_impl_span: Result<Span, Symbol>,
53     pub positive_impl_span: Result<Span, Symbol>,
54 }
55
56 impl IntoDiagnostic<'_> for NegativePositiveConflict<'_> {
57     #[track_caller]
58     fn into_diagnostic(
59         self,
60         handler: &Handler,
61     ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
62         let mut diag = handler.struct_err(fluent::trait_selection_negative_positive_conflict);
63         diag.set_arg("trait_desc", self.trait_desc.print_only_trait_path().to_string());
64         diag.set_arg(
65             "self_desc",
66             self.self_ty.map_or_else(|| "none".to_string(), |ty| ty.to_string()),
67         );
68         diag.set_span(self.impl_span);
69         diag.code(rustc_errors::error_code!(E0751));
70         match self.negative_impl_span {
71             Ok(span) => {
72                 diag.span_label(span, fluent::negative_implementation_here);
73             }
74             Err(cname) => {
75                 diag.note(fluent::negative_implementation_in_crate);
76                 diag.set_arg("negative_impl_cname", cname.to_string());
77             }
78         }
79         match self.positive_impl_span {
80             Ok(span) => {
81                 diag.span_label(span, fluent::positive_implementation_here);
82             }
83             Err(cname) => {
84                 diag.note(fluent::positive_implementation_in_crate);
85                 diag.set_arg("positive_impl_cname", cname.to_string());
86             }
87         }
88         diag
89     }
90 }