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_non_generic_param, code = E0792)]
299pub(crate) struct NonGenericOpaqueTypeParam<'a, 'tcx> {
300 pub ty: GenericArg<'tcx>,
301 pub kind: &'a str,
302 #[primary_span]
303 pub span: Span,
304 #[label]
305 pub param_span: Span,
306}
307
308#[derive(Diagnostic)]
309#[diag(borrowck_opaque_type_lifetime_mismatch)]
310pub(crate) struct LifetimeMismatchOpaqueParam<'tcx> {
311 pub arg: GenericArg<'tcx>,
312 pub prev: GenericArg<'tcx>,
313 #[primary_span]
314 #[label]
315 #[note]
316 pub span: Span,
317 #[label(borrowck_prev_lifetime_label)]
318 pub prev_span: Span,
319}
320
321#[derive(Subdiagnostic)]
322pub(crate) enum CaptureReasonLabel<'a> {
323 #[label(borrowck_moved_due_to_call)]
324 Call {
325 #[primary_span]
326 fn_call_span: Span,
327 place_name: &'a str,
328 is_partial: bool,
329 is_loop_message: bool,
330 },
331 #[label(borrowck_moved_due_to_usage_in_operator)]
332 OperatorUse {
333 #[primary_span]
334 fn_call_span: Span,
335 place_name: &'a str,
336 is_partial: bool,
337 is_loop_message: bool,
338 },
339 #[label(borrowck_moved_due_to_implicit_into_iter_call)]
340 ImplicitCall {
341 #[primary_span]
342 fn_call_span: Span,
343 place_name: &'a str,
344 is_partial: bool,
345 is_loop_message: bool,
346 },
347 #[label(borrowck_moved_due_to_method_call)]
348 MethodCall {
349 #[primary_span]
350 fn_call_span: Span,
351 place_name: &'a str,
352 is_partial: bool,
353 is_loop_message: bool,
354 },
355 #[label(borrowck_moved_due_to_await)]
356 Await {
357 #[primary_span]
358 fn_call_span: Span,
359 place_name: &'a str,
360 is_partial: bool,
361 is_loop_message: bool,
362 },
363 #[label(borrowck_value_moved_here)]
364 MovedHere {
365 #[primary_span]
366 move_span: Span,
367 is_partial: bool,
368 is_move_msg: bool,
369 is_loop_message: bool,
370 },
371 #[label(borrowck_consider_borrow_type_contents)]
372 BorrowContent {
373 #[primary_span]
374 var_span: Span,
375 },
376}
377
378#[derive(Subdiagnostic)]
379pub(crate) enum CaptureReasonNote {
380 #[note(borrowck_moved_a_fn_once_in_call)]
381 FnOnceMoveInCall {
382 #[primary_span]
383 var_span: Span,
384 },
385 #[note(borrowck_calling_operator_moves)]
386 UnOpMoveByOperator {
387 #[primary_span]
388 span: Span,
389 },
390 #[note(borrowck_calling_operator_moves_lhs)]
391 LhsMoveByOperator {
392 #[primary_span]
393 span: Span,
394 },
395 #[note(borrowck_func_take_self_moved_place)]
396 FuncTakeSelf {
397 func: String,
398 place_name: String,
399 #[primary_span]
400 span: Span,
401 },
402}
403
404#[derive(Subdiagnostic)]
405pub(crate) enum CaptureReasonSuggest<'tcx> {
406 #[suggestion(
407 borrowck_suggest_iterate_over_slice,
408 applicability = "maybe-incorrect",
409 code = "&",
410 style = "verbose"
411 )]
412 IterateSlice {
413 ty: Ty<'tcx>,
414 #[primary_span]
415 span: Span,
416 },
417 #[suggestion(
418 borrowck_suggest_create_fresh_reborrow,
419 applicability = "maybe-incorrect",
420 code = ".as_mut()",
421 style = "verbose"
422 )]
423 FreshReborrow {
424 #[primary_span]
425 span: Span,
426 },
427}
428
429#[derive(Subdiagnostic)]
430pub(crate) enum CaptureArgLabel {
431 #[label(borrowck_value_capture_here)]
432 Capture {
433 is_within: bool,
434 #[primary_span]
435 args_span: Span,
436 },
437 #[label(borrowck_move_out_place_here)]
438 MoveOutPlace {
439 place: String,
440 #[primary_span]
441 args_span: Span,
442 },
443}
444
445#[derive(Subdiagnostic)]
446pub(crate) enum OnClosureNote<'a> {
447 #[note(borrowck_closure_invoked_twice)]
448 InvokedTwice {
449 place_name: &'a str,
450 #[primary_span]
451 span: Span,
452 },
453 #[note(borrowck_closure_moved_twice)]
454 MovedTwice {
455 place_name: &'a str,
456 #[primary_span]
457 span: Span,
458 },
459}
460
461#[derive(Subdiagnostic)]
462pub(crate) enum TypeNoCopy<'a> {
463 #[label(borrowck_ty_no_impl_copy)]
464 Label {
465 is_partial_move: bool,
466 ty: String,
467 place: &'a str,
468 #[primary_span]
469 span: Span,
470 },
471 #[note(borrowck_ty_no_impl_copy)]
472 Note { is_partial_move: bool, ty: String, place: &'a str },
473}
474
475#[derive(Diagnostic)]
476#[diag(borrowck_simd_intrinsic_arg_const)]
477pub(crate) struct SimdIntrinsicArgConst {
478 #[primary_span]
479 pub span: Span,
480 pub arg: usize,
481 pub intrinsic: String,
482}
483
484#[derive(LintDiagnostic)]
485#[diag(borrowck_tail_expr_drop_order)]
486pub(crate) struct TailExprDropOrder {
487 #[label]
488 pub borrowed: Span,
489}