]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_borrowck/src/session_diagnostics.rs
New upstream version 1.67.1+dfsg1
[rustc.git] / compiler / rustc_borrowck / src / session_diagnostics.rs
CommitLineData
f2b60f7d 1use rustc_errors::{IntoDiagnosticArg, MultiSpan};
2b03887a 2use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
064997fb
FG
3use rustc_middle::ty::Ty;
4use rustc_span::Span;
5
f2b60f7d
FG
6use crate::diagnostics::RegionName;
7
2b03887a
FG
8#[derive(Diagnostic)]
9#[diag(borrowck_move_unsized, code = "E0161")]
064997fb
FG
10pub(crate) struct MoveUnsized<'tcx> {
11 pub ty: Ty<'tcx>,
12 #[primary_span]
13 #[label]
14 pub span: Span,
15}
16
2b03887a
FG
17#[derive(Diagnostic)]
18#[diag(borrowck_higher_ranked_lifetime_error)]
064997fb
FG
19pub(crate) struct HigherRankedLifetimeError {
20 #[subdiagnostic]
21 pub cause: Option<HigherRankedErrorCause>,
22 #[primary_span]
23 pub span: Span,
24}
25
2b03887a 26#[derive(Subdiagnostic)]
064997fb 27pub(crate) enum HigherRankedErrorCause {
2b03887a 28 #[note(borrowck_could_not_prove)]
064997fb 29 CouldNotProve { predicate: String },
2b03887a 30 #[note(borrowck_could_not_normalize)]
064997fb
FG
31 CouldNotNormalize { value: String },
32}
33
2b03887a
FG
34#[derive(Diagnostic)]
35#[diag(borrowck_higher_ranked_subtype_error)]
064997fb
FG
36pub(crate) struct HigherRankedSubtypeError {
37 #[primary_span]
38 pub span: Span,
39}
40
2b03887a
FG
41#[derive(Diagnostic)]
42#[diag(borrowck_generic_does_not_live_long_enough)]
064997fb
FG
43pub(crate) struct GenericDoesNotLiveLongEnough {
44 pub kind: String,
45 #[primary_span]
46 pub span: Span,
47}
f2b60f7d
FG
48
49#[derive(LintDiagnostic)]
2b03887a 50#[diag(borrowck_var_does_not_need_mut)]
f2b60f7d 51pub(crate) struct VarNeedNotMut {
487cf647 52 #[suggestion(style = "short", applicability = "machine-applicable", code = "")]
f2b60f7d
FG
53 pub span: Span,
54}
2b03887a
FG
55#[derive(Diagnostic)]
56#[diag(borrowck_var_cannot_escape_closure)]
f2b60f7d 57#[note]
2b03887a 58#[note(cannot_escape)]
f2b60f7d
FG
59pub(crate) struct FnMutError {
60 #[primary_span]
61 pub span: Span,
62 #[subdiagnostic]
63 pub ty_err: FnMutReturnTypeErr,
64}
65
2b03887a 66#[derive(Subdiagnostic)]
f2b60f7d 67pub(crate) enum VarHereDenote {
2b03887a 68 #[label(borrowck_var_here_captured)]
f2b60f7d
FG
69 Captured {
70 #[primary_span]
71 span: Span,
72 },
2b03887a 73 #[label(borrowck_var_here_defined)]
f2b60f7d
FG
74 Defined {
75 #[primary_span]
76 span: Span,
77 },
2b03887a 78 #[label(borrowck_closure_inferred_mut)]
f2b60f7d
FG
79 FnMutInferred {
80 #[primary_span]
81 span: Span,
82 },
83}
84
2b03887a 85#[derive(Subdiagnostic)]
f2b60f7d 86pub(crate) enum FnMutReturnTypeErr {
2b03887a 87 #[label(borrowck_returned_closure_escaped)]
f2b60f7d
FG
88 ReturnClosure {
89 #[primary_span]
90 span: Span,
91 },
2b03887a 92 #[label(borrowck_returned_async_block_escaped)]
f2b60f7d
FG
93 ReturnAsyncBlock {
94 #[primary_span]
95 span: Span,
96 },
2b03887a 97 #[label(borrowck_returned_ref_escaped)]
f2b60f7d
FG
98 ReturnRef {
99 #[primary_span]
100 span: Span,
101 },
102}
103
2b03887a
FG
104#[derive(Diagnostic)]
105#[diag(borrowck_lifetime_constraints_error)]
f2b60f7d
FG
106pub(crate) struct LifetimeOutliveErr {
107 #[primary_span]
108 pub span: Span,
109}
110
2b03887a 111#[derive(Subdiagnostic)]
f2b60f7d 112pub(crate) enum LifetimeReturnCategoryErr<'a> {
2b03887a 113 #[label(borrowck_returned_lifetime_wrong)]
f2b60f7d
FG
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 },
2b03887a 121 #[label(borrowck_returned_lifetime_short)]
f2b60f7d
FG
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
131impl IntoDiagnosticArg for &RegionName {
132 fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
133 format!("{}", self).into_diagnostic_arg()
134 }
135}
136
137impl IntoDiagnosticArg for RegionName {
138 fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
139 format!("{}", self).into_diagnostic_arg()
140 }
141}
142
2b03887a 143#[derive(Subdiagnostic)]
f2b60f7d 144pub(crate) enum RequireStaticErr {
2b03887a 145 #[note(borrowck_used_impl_require_static)]
f2b60f7d
FG
146 UsedImpl {
147 #[primary_span]
148 multi_span: MultiSpan,
149 },
150}
487cf647
FG
151
152#[derive(Subdiagnostic)]
153pub(crate) enum CaptureVarPathUseCause {
154 #[label(borrowck_borrow_due_to_use_generator)]
155 BorrowInGenerator {
156 #[primary_span]
157 path_span: Span,
158 },
159 #[label(borrowck_use_due_to_use_generator)]
160 UseInGenerator {
161 #[primary_span]
162 path_span: Span,
163 },
164 #[label(borrowck_assign_due_to_use_generator)]
165 AssignInGenerator {
166 #[primary_span]
167 path_span: Span,
168 },
169 #[label(borrowck_assign_part_due_to_use_generator)]
170 AssignPartInGenerator {
171 #[primary_span]
172 path_span: Span,
173 },
174 #[label(borrowck_borrow_due_to_use_closure)]
175 BorrowInClosure {
176 #[primary_span]
177 path_span: Span,
178 },
179 #[label(borrowck_use_due_to_use_closure)]
180 UseInClosure {
181 #[primary_span]
182 path_span: Span,
183 },
184 #[label(borrowck_assign_due_to_use_closure)]
185 AssignInClosure {
186 #[primary_span]
187 path_span: Span,
188 },
189 #[label(borrowck_assign_part_due_to_use_closure)]
190 AssignPartInClosure {
191 #[primary_span]
192 path_span: Span,
193 },
194}
195
196#[derive(Subdiagnostic)]
197pub(crate) enum CaptureVarKind {
198 #[label(borrowck_capture_immute)]
199 Immute {
200 #[primary_span]
201 kind_span: Span,
202 },
203 #[label(borrowck_capture_mut)]
204 Mut {
205 #[primary_span]
206 kind_span: Span,
207 },
208 #[label(borrowck_capture_move)]
209 Move {
210 #[primary_span]
211 kind_span: Span,
212 },
213}
214
215#[derive(Subdiagnostic)]
216pub(crate) enum CaptureVarCause {
217 #[label(borrowck_var_borrow_by_use_place_in_generator)]
218 BorrowUsePlaceGenerator {
219 place: String,
220 #[primary_span]
221 var_span: Span,
222 },
223 #[label(borrowck_var_borrow_by_use_place_in_closure)]
224 BorrowUsePlaceClosure {
225 place: String,
226 #[primary_span]
227 var_span: Span,
228 },
229}
230
231#[derive(Diagnostic)]
232#[diag(borrowck_cannot_move_when_borrowed, code = "E0505")]
233pub(crate) struct MoveBorrow<'a> {
234 pub place: &'a str,
235 pub borrow_place: &'a str,
236 pub value_place: &'a str,
237 #[primary_span]
238 #[label(move_label)]
239 pub span: Span,
240 #[label]
241 pub borrow_span: Span,
242}