]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_trait_selection/src/errors.rs
Rollup merge of #103855 - notriddle:notriddle/mobile-item-table, r=GuillaumeGomez
[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_session::Limit;
5 use rustc_span::{Span, Symbol};
6
7 #[derive(Diagnostic)]
8 #[diag(trait_selection_dump_vtable_entries)]
9 pub struct DumpVTableEntries<'a> {
10     #[primary_span]
11     pub span: Span,
12     pub trait_ref: PolyTraitRef<'a>,
13     pub entries: String,
14 }
15
16 #[derive(Diagnostic)]
17 #[diag(trait_selection_unable_to_construct_constant_value)]
18 pub struct UnableToConstructConstantValue<'a> {
19     #[primary_span]
20     pub span: Span,
21     pub unevaluated: ty::UnevaluatedConst<'a>,
22 }
23
24 #[derive(Diagnostic)]
25 #[help]
26 #[diag(trait_selection_auto_deref_reached_recursion_limit, code = "E0055")]
27 pub struct AutoDerefReachedRecursionLimit<'a> {
28     #[primary_span]
29     #[label]
30     pub span: Span,
31     pub ty: Ty<'a>,
32     pub suggested_limit: Limit,
33     pub crate_name: Symbol,
34 }
35
36 #[derive(Diagnostic)]
37 #[diag(trait_selection_empty_on_clause_in_rustc_on_unimplemented, code = "E0232")]
38 pub struct EmptyOnClauseInOnUnimplemented {
39     #[primary_span]
40     #[label]
41     pub span: Span,
42 }
43
44 #[derive(Diagnostic)]
45 #[diag(trait_selection_invalid_on_clause_in_rustc_on_unimplemented, code = "E0232")]
46 pub struct InvalidOnClauseInOnUnimplemented {
47     #[primary_span]
48     #[label]
49     pub span: Span,
50 }
51
52 #[derive(Diagnostic)]
53 #[diag(trait_selection_no_value_in_rustc_on_unimplemented, code = "E0232")]
54 #[note]
55 pub struct NoValueInOnUnimplemented {
56     #[primary_span]
57     #[label]
58     pub span: Span,
59 }
60
61 pub struct NegativePositiveConflict<'a> {
62     pub impl_span: Span,
63     pub trait_desc: &'a str,
64     pub self_desc: &'a Option<String>,
65     pub negative_impl_span: Result<Span, Symbol>,
66     pub positive_impl_span: Result<Span, Symbol>,
67 }
68
69 impl IntoDiagnostic<'_> for NegativePositiveConflict<'_> {
70     #[track_caller]
71     fn into_diagnostic(
72         self,
73         handler: &Handler,
74     ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
75         let mut diag = handler.struct_err(fluent::trait_selection_negative_positive_conflict);
76         diag.set_arg("trait_desc", self.trait_desc);
77         diag.set_arg(
78             "self_desc",
79             self.self_desc.clone().map_or_else(|| String::from("none"), |ty| ty),
80         );
81         diag.set_span(self.impl_span);
82         diag.code(rustc_errors::error_code!(E0751));
83         match self.negative_impl_span {
84             Ok(span) => {
85                 diag.span_label(span, fluent::negative_implementation_here);
86             }
87             Err(cname) => {
88                 diag.note(fluent::negative_implementation_in_crate);
89                 diag.set_arg("negative_impl_cname", cname.to_string());
90             }
91         }
92         match self.positive_impl_span {
93             Ok(span) => {
94                 diag.span_label(span, fluent::positive_implementation_here);
95             }
96             Err(cname) => {
97                 diag.note(fluent::positive_implementation_in_crate);
98                 diag.set_arg("positive_impl_cname", cname.to_string());
99             }
100         }
101         diag
102     }
103 }