]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_trait_selection/src/errors.rs
remove the `Subst` trait, always use `EarlyBinder`
[rust.git] / compiler / rustc_trait_selection / src / errors.rs
1 use rustc_errors::{fluent, ErrorGuaranteed, Handler};
2 use rustc_macros::SessionDiagnostic;
3 use rustc_middle::ty::{PolyTraitRef, Ty, Unevaluated};
4 use rustc_session::{Limit, SessionDiagnostic};
5 use rustc_span::{Span, Symbol};
6
7 #[derive(SessionDiagnostic)]
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(SessionDiagnostic)]
17 #[diag(trait_selection::unable_to_construct_constant_value)]
18 pub struct UnableToConstructConstantValue<'a> {
19     #[primary_span]
20     pub span: Span,
21     pub unevaluated: Unevaluated<'a>,
22 }
23
24 #[derive(SessionDiagnostic)]
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(SessionDiagnostic)]
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(SessionDiagnostic)]
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(SessionDiagnostic)]
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 SessionDiagnostic<'_> for NegativePositiveConflict<'_> {
70     fn into_diagnostic(
71         self,
72         handler: &Handler,
73     ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
74         let mut diag = handler.struct_err(fluent::trait_selection::negative_positive_conflict);
75         diag.set_arg("trait_desc", self.trait_desc);
76         diag.set_arg(
77             "self_desc",
78             self.self_desc.clone().map_or_else(|| String::from("none"), |ty| ty),
79         );
80         diag.set_span(self.impl_span);
81         diag.code(rustc_errors::error_code!(E0751));
82         match self.negative_impl_span {
83             Ok(span) => {
84                 diag.span_label(span, fluent::trait_selection::negative_implementation_here);
85             }
86             Err(cname) => {
87                 diag.note(fluent::trait_selection::negative_implementation_in_crate);
88                 diag.set_arg("negative_impl_cname", cname.to_string());
89             }
90         }
91         match self.positive_impl_span {
92             Ok(span) => {
93                 diag.span_label(span, fluent::trait_selection::positive_implementation_here);
94             }
95             Err(cname) => {
96                 diag.note(fluent::trait_selection::positive_implementation_in_crate);
97                 diag.set_arg("positive_impl_cname", cname.to_string());
98             }
99         }
100         diag
101     }
102 }