]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_borrowck/src/session_diagnostics.rs
Rollup merge of #103464 - JakobDegen:mir-parsing, r=oli-obk
[rust.git] / compiler / rustc_borrowck / src / session_diagnostics.rs
1 use rustc_errors::{IntoDiagnosticArg, MultiSpan};
2 use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
3 use rustc_middle::ty::Ty;
4 use rustc_span::Span;
5
6 use crate::diagnostics::RegionName;
7
8 #[derive(Diagnostic)]
9 #[diag(borrowck_move_unsized, code = "E0161")]
10 pub(crate) struct MoveUnsized<'tcx> {
11     pub ty: Ty<'tcx>,
12     #[primary_span]
13     #[label]
14     pub span: Span,
15 }
16
17 #[derive(Diagnostic)]
18 #[diag(borrowck_higher_ranked_lifetime_error)]
19 pub(crate) struct HigherRankedLifetimeError {
20     #[subdiagnostic]
21     pub cause: Option<HigherRankedErrorCause>,
22     #[primary_span]
23     pub span: Span,
24 }
25
26 #[derive(Subdiagnostic)]
27 pub(crate) enum HigherRankedErrorCause {
28     #[note(borrowck_could_not_prove)]
29     CouldNotProve { predicate: String },
30     #[note(borrowck_could_not_normalize)]
31     CouldNotNormalize { value: String },
32 }
33
34 #[derive(Diagnostic)]
35 #[diag(borrowck_higher_ranked_subtype_error)]
36 pub(crate) struct HigherRankedSubtypeError {
37     #[primary_span]
38     pub span: Span,
39 }
40
41 #[derive(Diagnostic)]
42 #[diag(borrowck_generic_does_not_live_long_enough)]
43 pub(crate) struct GenericDoesNotLiveLongEnough {
44     pub kind: String,
45     #[primary_span]
46     pub span: Span,
47 }
48
49 #[derive(LintDiagnostic)]
50 #[diag(borrowck_var_does_not_need_mut)]
51 pub(crate) struct VarNeedNotMut {
52     #[suggestion(style = "short", applicability = "machine-applicable", code = "")]
53     pub span: Span,
54 }
55 #[derive(Diagnostic)]
56 #[diag(borrowck_var_cannot_escape_closure)]
57 #[note]
58 #[note(cannot_escape)]
59 pub(crate) struct FnMutError {
60     #[primary_span]
61     pub span: Span,
62     #[subdiagnostic]
63     pub ty_err: FnMutReturnTypeErr,
64 }
65
66 #[derive(Subdiagnostic)]
67 pub(crate) enum VarHereDenote {
68     #[label(borrowck_var_here_captured)]
69     Captured {
70         #[primary_span]
71         span: Span,
72     },
73     #[label(borrowck_var_here_defined)]
74     Defined {
75         #[primary_span]
76         span: Span,
77     },
78     #[label(borrowck_closure_inferred_mut)]
79     FnMutInferred {
80         #[primary_span]
81         span: Span,
82     },
83 }
84
85 #[derive(Subdiagnostic)]
86 pub(crate) enum FnMutReturnTypeErr {
87     #[label(borrowck_returned_closure_escaped)]
88     ReturnClosure {
89         #[primary_span]
90         span: Span,
91     },
92     #[label(borrowck_returned_async_block_escaped)]
93     ReturnAsyncBlock {
94         #[primary_span]
95         span: Span,
96     },
97     #[label(borrowck_returned_ref_escaped)]
98     ReturnRef {
99         #[primary_span]
100         span: Span,
101     },
102 }
103
104 #[derive(Diagnostic)]
105 #[diag(borrowck_lifetime_constraints_error)]
106 pub(crate) struct LifetimeOutliveErr {
107     #[primary_span]
108     pub span: Span,
109 }
110
111 #[derive(Subdiagnostic)]
112 pub(crate) enum LifetimeReturnCategoryErr<'a> {
113     #[label(borrowck_returned_lifetime_wrong)]
114     WrongReturn {
115         #[primary_span]
116         span: Span,
117         mir_def_name: &'a str,
118         outlived_fr_name: RegionName,
119         fr_name: &'a RegionName,
120     },
121     #[label(borrowck_returned_lifetime_short)]
122     ShortReturn {
123         #[primary_span]
124         span: Span,
125         category_desc: &'static str,
126         free_region_name: &'a RegionName,
127         outlived_fr_name: RegionName,
128     },
129 }
130
131 impl IntoDiagnosticArg for &RegionName {
132     fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
133         format!("{}", self).into_diagnostic_arg()
134     }
135 }
136
137 impl IntoDiagnosticArg for RegionName {
138     fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
139         format!("{}", self).into_diagnostic_arg()
140     }
141 }
142
143 #[derive(Subdiagnostic)]
144 pub(crate) enum RequireStaticErr {
145     #[note(borrowck_used_impl_require_static)]
146     UsedImpl {
147         #[primary_span]
148         multi_span: MultiSpan,
149     },
150 }
151
152 #[derive(Subdiagnostic)]
153 #[label(borrowck_capture_kind_label)]
154 pub(crate) struct CaptureVarKind {
155     pub kind_desc: String,
156     #[primary_span]
157     pub kind_span: Span,
158 }
159
160 #[derive(Subdiagnostic)]
161 pub(crate) enum CaptureVarCause {
162     #[label(borrowck_var_borrow_by_use_place)]
163     BorrowUsePlace {
164         place: String,
165         #[primary_span]
166         var_span: Span,
167     },
168     #[label(borrowck_var_borrow_by_use_place_in_generator)]
169     BorrowUsePlaceGenerator {
170         place: String,
171         #[primary_span]
172         var_span: Span,
173     },
174     #[label(borrowck_var_borrow_by_use_place_in_closure)]
175     BorrowUsePlaceClosure {
176         place: String,
177         #[primary_span]
178         var_span: Span,
179     },
180 }