1use rustc_errors::MultiSpan;
2use rustc_errors::codes::*;
3use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
4use rustc_middle::ty::{GenericArg, Ty};
5use rustc_span::Span;
6
7use crate::diagnostics::RegionName;
8
9#[derive(Diagnostic)]
10#[diag(borrowck_move_unsized, code = E0161)]
11pub(crate) struct MoveUnsized<'tcx> {
12 pub ty: Ty<'tcx>,
13 #[primary_span]
14 #[label]
15 pub span: Span,
16}
17
18#[derive(Diagnostic)]
19#[diag(borrowck_higher_ranked_lifetime_error)]
20pub(crate) struct HigherRankedLifetimeError {
21 #[subdiagnostic]
22 pub cause: Option<HigherRankedErrorCause>,
23 #[primary_span]
24 pub span: Span,
25}
26
27#[derive(Subdiagnostic)]
28pub(crate) enum HigherRankedErrorCause {
29 #[note(borrowck_could_not_prove)]
30 CouldNotProve { predicate: String },
31 #[note(borrowck_could_not_normalize)]
32 CouldNotNormalize { value: String },
33}
34
35#[derive(Diagnostic)]
36#[diag(borrowck_higher_ranked_subtype_error)]
37pub(crate) struct HigherRankedSubtypeError {
38 #[primary_span]
39 pub span: Span,
40}
41
42#[derive(Diagnostic)]
43#[diag(borrowck_generic_does_not_live_long_enough)]
44pub(crate) struct GenericDoesNotLiveLongEnough {
45 pub kind: String,
46 #[primary_span]
47 pub span: Span,
48}
49
50#[derive(LintDiagnostic)]
51#[diag(borrowck_var_does_not_need_mut)]
52pub(crate) struct VarNeedNotMut {
53 #[suggestion(style = "short", applicability = "machine-applicable", code = "")]
54 pub span: Span,
55}
56#[derive(Diagnostic)]
57#[diag(borrowck_var_cannot_escape_closure)]
58#[note]
59#[note(borrowck_cannot_escape)]
60pub(crate) struct FnMutError {
61 #[primary_span]
62 pub span: Span,
63 #[subdiagnostic]
64 pub ty_err: FnMutReturnTypeErr,
65}
66
67#[derive(Subdiagnostic)]
68pub(crate) enum VarHereDenote {
69 #[label(borrowck_var_here_captured)]
70 Captured {
71 #[primary_span]
72 span: Span,
73 },
74 #[label(borrowck_var_here_defined)]
75 Defined {
76 #[primary_span]
77 span: Span,
78 },
79 #[label(borrowck_closure_inferred_mut)]
80 FnMutInferred {
81 #[primary_span]
82 span: Span,
83 },
84}
85
86#[derive(Subdiagnostic)]
87pub(crate) enum FnMutReturnTypeErr {
88 #[label(borrowck_returned_closure_escaped)]
89 ReturnClosure {
90 #[primary_span]
91 span: Span,
92 },
93 #[label(borrowck_returned_async_block_escaped)]
94 ReturnAsyncBlock {
95 #[primary_span]
96 span: Span,
97 },
98 #[label(borrowck_returned_ref_escaped)]
99 ReturnRef {
100 #[primary_span]
101 span: Span,
102 },
103}
104
105#[derive(Diagnostic)]
106#[diag(borrowck_lifetime_constraints_error)]
107pub(crate) struct LifetimeOutliveErr {
108 #[primary_span]
109 pub span: Span,
110}
111
112#[derive(Subdiagnostic)]
113pub(crate) enum LifetimeReturnCategoryErr<'a> {
114 #[label(borrowck_returned_lifetime_wrong)]
115 WrongReturn {
116 #[primary_span]
117 span: Span,
118 mir_def_name: &'a str,
119 outlived_fr_name: RegionName,
120 fr_name: &'a RegionName,
121 },
122 #[label(borrowck_returned_lifetime_short)]
123 ShortReturn {
124 #[primary_span]
125 span: Span,
126 category_desc: &'static str,
127 free_region_name: &'a RegionName,
128 outlived_fr_name: RegionName,
129 },
130}
131
132#[derive(Subdiagnostic)]
133pub(crate) enum RequireStaticErr {
134 #[note(borrowck_used_impl_require_static)]
135 UsedImpl {
136 #[primary_span]
137 multi_span: MultiSpan,
138 },
139}
140
141#[derive(Subdiagnostic)]
142pub(crate) enum CaptureVarPathUseCause {
143 #[label(borrowck_borrow_due_to_use_coroutine)]
144 BorrowInCoroutine {
145 #[primary_span]
146 path_span: Span,
147 },
148 #[label(borrowck_use_due_to_use_coroutine)]
149 UseInCoroutine {
150 #[primary_span]
151 path_span: Span,
152 },
153 #[label(borrowck_assign_due_to_use_coroutine)]
154 AssignInCoroutine {
155 #[primary_span]
156 path_span: Span,
157 },
158 #[label(borrowck_assign_part_due_to_use_coroutine)]
159 AssignPartInCoroutine {
160 #[primary_span]
161 path_span: Span,
162 },
163 #[label(borrowck_borrow_due_to_use_closure)]
164 BorrowInClosure {
165 #[primary_span]
166 path_span: Span,
167 },
168 #[label(borrowck_use_due_to_use_closure)]
169 UseInClosure {
170 #[primary_span]
171 path_span: Span,
172 },
173 #[label(borrowck_assign_due_to_use_closure)]
174 AssignInClosure {
175 #[primary_span]
176 path_span: Span,
177 },
178 #[label(borrowck_assign_part_due_to_use_closure)]
179 AssignPartInClosure {
180 #[primary_span]
181 path_span: Span,
182 },
183}
184
185#[derive(Subdiagnostic)]
186pub(crate) enum CaptureVarKind {
187 #[label(borrowck_capture_immute)]
188 Immut {
189 #[primary_span]
190 kind_span: Span,
191 },
192 #[label(borrowck_capture_mut)]
193 Mut {
194 #[primary_span]
195 kind_span: Span,
196 },
197 #[label(borrowck_capture_move)]
198 Move {
199 #[primary_span]
200 kind_span: Span,
201 },
202}
203
204#[derive(Subdiagnostic)]
205pub(crate) enum CaptureVarCause {
206 #[label(borrowck_var_borrow_by_use_place_in_coroutine)]
207 BorrowUsePlaceCoroutine {
208 is_single_var: bool,
209 place: String,
210 #[primary_span]
211 var_span: Span,
212 },
213 #[label(borrowck_var_borrow_by_use_place_in_closure)]
214 BorrowUsePlaceClosure {
215 is_single_var: bool,
216 place: String,
217 #[primary_span]
218 var_span: Span,
219 },
220 #[label(borrowck_var_borrow_by_use_in_coroutine)]
221 BorrowUseInCoroutine {
222 #[primary_span]
223 var_span: Span,
224 },
225 #[label(borrowck_var_borrow_by_use_in_closure)]
226 BorrowUseInClosure {
227 #[primary_span]
228 var_span: Span,
229 },
230 #[label(borrowck_var_move_by_use_in_coroutine)]
231 MoveUseInCoroutine {
232 #[primary_span]
233 var_span: Span,
234 },
235 #[label(borrowck_var_move_by_use_in_closure)]
236 MoveUseInClosure {
237 #[primary_span]
238 var_span: Span,
239 },
240 #[label(borrowck_var_first_borrow_by_use_place_in_coroutine)]
241 FirstBorrowUsePlaceCoroutine {
242 place: String,
243 #[primary_span]
244 var_span: Span,
245 },
246 #[label(borrowck_var_first_borrow_by_use_place_in_closure)]
247 FirstBorrowUsePlaceClosure {
248 place: String,
249 #[primary_span]
250 var_span: Span,
251 },
252 #[label(borrowck_var_second_borrow_by_use_place_in_coroutine)]
253 SecondBorrowUsePlaceCoroutine {
254 place: String,
255 #[primary_span]
256 var_span: Span,
257 },
258 #[label(borrowck_var_second_borrow_by_use_place_in_closure)]
259 SecondBorrowUsePlaceClosure {
260 place: String,
261 #[primary_span]
262 var_span: Span,
263 },
264 #[label(borrowck_var_mutable_borrow_by_use_place_in_closure)]
265 MutableBorrowUsePlaceClosure {
266 place: String,
267 #[primary_span]
268 var_span: Span,
269 },
270 #[label(borrowck_partial_var_move_by_use_in_coroutine)]
271 PartialMoveUseInCoroutine {
272 #[primary_span]
273 var_span: Span,
274 is_partial: bool,
275 },
276 #[label(borrowck_partial_var_move_by_use_in_closure)]
277 PartialMoveUseInClosure {
278 #[primary_span]
279 var_span: Span,
280 is_partial: bool,
281 },
282}
283
284#[derive(Diagnostic)]
285#[diag(borrowck_cannot_move_when_borrowed, code = E0505)]
286pub(crate) struct MoveBorrow<'a> {
287 pub place: &'a str,
288 pub borrow_place: &'a str,
289 pub value_place: &'a str,
290 #[primary_span]
291 #[label(borrowck_move_label)]
292 pub span: Span,
293 #[label]
294 pub borrow_span: Span,
295}
296
297#[derive(Diagnostic)]
298#[diag(borrowck_opaque_type_lifetime_mismatch)]
299pub(crate) struct LifetimeMismatchOpaqueParam<'tcx> {
300 pub arg: GenericArg<'tcx>,
301 pub prev: GenericArg<'tcx>,
302 #[primary_span]
303 #[label]
304 #[note]
305 pub span: Span,
306 #[label(borrowck_prev_lifetime_label)]
307 pub prev_span: Span,
308}
309
310#[derive(Subdiagnostic)]
311pub(crate) enum CaptureReasonLabel<'a> {
312 #[label(borrowck_moved_due_to_call)]
313 Call {
314 #[primary_span]
315 fn_call_span: Span,
316 place_name: &'a str,
317 is_partial: bool,
318 is_loop_message: bool,
319 },
320 #[label(borrowck_moved_due_to_usage_in_operator)]
321 OperatorUse {
322 #[primary_span]
323 fn_call_span: Span,
324 place_name: &'a str,
325 is_partial: bool,
326 is_loop_message: bool,
327 },
328 #[label(borrowck_moved_due_to_implicit_into_iter_call)]
329 ImplicitCall {
330 #[primary_span]
331 fn_call_span: Span,
332 place_name: &'a str,
333 is_partial: bool,
334 is_loop_message: bool,
335 },
336 #[label(borrowck_moved_due_to_method_call)]
337 MethodCall {
338 #[primary_span]
339 fn_call_span: Span,
340 place_name: &'a str,
341 is_partial: bool,
342 is_loop_message: bool,
343 },
344 #[label(borrowck_moved_due_to_await)]
345 Await {
346 #[primary_span]
347 fn_call_span: Span,
348 place_name: &'a str,
349 is_partial: bool,
350 is_loop_message: bool,
351 },
352 #[label(borrowck_value_moved_here)]
353 MovedHere {
354 #[primary_span]
355 move_span: Span,
356 is_partial: bool,
357 is_move_msg: bool,
358 is_loop_message: bool,
359 },
360 #[label(borrowck_consider_borrow_type_contents)]
361 BorrowContent {
362 #[primary_span]
363 var_span: Span,
364 },
365}
366
367#[derive(Subdiagnostic)]
368pub(crate) enum CaptureReasonNote {
369 #[note(borrowck_moved_a_fn_once_in_call)]
370 FnOnceMoveInCall {
371 #[primary_span]
372 var_span: Span,
373 },
374 #[note(borrowck_calling_operator_moves)]
375 UnOpMoveByOperator {
376 #[primary_span]
377 span: Span,
378 },
379 #[note(borrowck_calling_operator_moves_lhs)]
380 LhsMoveByOperator {
381 #[primary_span]
382 span: Span,
383 },
384 #[note(borrowck_func_take_self_moved_place)]
385 FuncTakeSelf {
386 func: String,
387 place_name: String,
388 #[primary_span]
389 span: Span,
390 },
391}
392
393#[derive(Subdiagnostic)]
394pub(crate) enum CaptureReasonSuggest<'tcx> {
395 #[suggestion(
396 borrowck_suggest_iterate_over_slice,
397 applicability = "maybe-incorrect",
398 code = "&",
399 style = "verbose"
400 )]
401 IterateSlice {
402 ty: Ty<'tcx>,
403 #[primary_span]
404 span: Span,
405 },
406 #[suggestion(
407 borrowck_suggest_create_fresh_reborrow,
408 applicability = "maybe-incorrect",
409 code = ".as_mut()",
410 style = "verbose"
411 )]
412 FreshReborrow {
413 #[primary_span]
414 span: Span,
415 },
416}
417
418#[derive(Subdiagnostic)]
419pub(crate) enum CaptureArgLabel {
420 #[label(borrowck_value_capture_here)]
421 Capture {
422 is_within: bool,
423 #[primary_span]
424 args_span: Span,
425 },
426 #[label(borrowck_move_out_place_here)]
427 MoveOutPlace {
428 place: String,
429 #[primary_span]
430 args_span: Span,
431 },
432}
433
434#[derive(Subdiagnostic)]
435pub(crate) enum OnClosureNote<'a> {
436 #[note(borrowck_closure_invoked_twice)]
437 InvokedTwice {
438 place_name: &'a str,
439 #[primary_span]
440 span: Span,
441 },
442 #[note(borrowck_closure_moved_twice)]
443 MovedTwice {
444 place_name: &'a str,
445 #[primary_span]
446 span: Span,
447 },
448}
449
450#[derive(Subdiagnostic)]
451pub(crate) enum TypeNoCopy<'a, 'tcx> {
452 #[label(borrowck_ty_no_impl_copy)]
453 Label {
454 is_partial_move: bool,
455 ty: Ty<'tcx>,
456 place: &'a str,
457 #[primary_span]
458 span: Span,
459 },
460 #[note(borrowck_ty_no_impl_copy)]
461 Note { is_partial_move: bool, ty: Ty<'tcx>, place: &'a str },
462}
463
464#[derive(Diagnostic)]
465#[diag(borrowck_simd_intrinsic_arg_const)]
466pub(crate) struct SimdIntrinsicArgConst {
467 #[primary_span]
468 pub span: Span,
469 pub arg: usize,
470 pub intrinsic: String,
471}
472
473#[derive(LintDiagnostic)]
474#[diag(borrowck_tail_expr_drop_order)]
475pub(crate) struct TailExprDropOrder {
476 #[label]
477 pub borrowed: Span,
478}