1 use rustc_errors::{IntoDiagnosticArg, MultiSpan};
2 use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
3 use rustc_middle::ty::Ty;
6 use crate::diagnostics::RegionName;
9 #[diag(borrowck_move_unsized, code = "E0161")]
10 pub(crate) struct MoveUnsized<'tcx> {
18 #[diag(borrowck_higher_ranked_lifetime_error)]
19 pub(crate) struct HigherRankedLifetimeError {
21 pub cause: Option<HigherRankedErrorCause>,
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 },
35 #[diag(borrowck_higher_ranked_subtype_error)]
36 pub(crate) struct HigherRankedSubtypeError {
42 #[diag(borrowck_generic_does_not_live_long_enough)]
43 pub(crate) struct GenericDoesNotLiveLongEnough {
49 #[derive(LintDiagnostic)]
50 #[diag(borrowck_var_does_not_need_mut)]
51 pub(crate) struct VarNeedNotMut {
52 #[suggestion(style = "short", applicability = "machine-applicable", code = "")]
56 #[diag(borrowck_var_cannot_escape_closure)]
58 #[note(cannot_escape)]
59 pub(crate) struct FnMutError {
63 pub ty_err: FnMutReturnTypeErr,
66 #[derive(Subdiagnostic)]
67 pub(crate) enum VarHereDenote {
68 #[label(borrowck_var_here_captured)]
73 #[label(borrowck_var_here_defined)]
78 #[label(borrowck_closure_inferred_mut)]
85 #[derive(Subdiagnostic)]
86 pub(crate) enum FnMutReturnTypeErr {
87 #[label(borrowck_returned_closure_escaped)]
92 #[label(borrowck_returned_async_block_escaped)]
97 #[label(borrowck_returned_ref_escaped)]
104 #[derive(Diagnostic)]
105 #[diag(borrowck_lifetime_constraints_error)]
106 pub(crate) struct LifetimeOutliveErr {
111 #[derive(Subdiagnostic)]
112 pub(crate) enum LifetimeReturnCategoryErr<'a> {
113 #[label(borrowck_returned_lifetime_wrong)]
117 mir_def_name: &'a str,
118 outlived_fr_name: RegionName,
119 fr_name: &'a RegionName,
121 #[label(borrowck_returned_lifetime_short)]
125 category_desc: &'static str,
126 free_region_name: &'a RegionName,
127 outlived_fr_name: RegionName,
131 impl IntoDiagnosticArg for &RegionName {
132 fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
133 format!("{}", self).into_diagnostic_arg()
137 impl IntoDiagnosticArg for RegionName {
138 fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
139 format!("{}", self).into_diagnostic_arg()
143 #[derive(Subdiagnostic)]
144 pub(crate) enum RequireStaticErr {
145 #[note(borrowck_used_impl_require_static)]
148 multi_span: MultiSpan,
152 #[derive(Subdiagnostic)]
153 pub(crate) enum CaptureVarPathUseCause {
154 #[label(borrowck_borrow_due_to_use_generator)]
159 #[label(borrowck_use_due_to_use_generator)]
164 #[label(borrowck_assign_due_to_use_generator)]
169 #[label(borrowck_assign_part_due_to_use_generator)]
170 AssignPartInGenerator {
174 #[label(borrowck_borrow_due_to_use_closure)]
179 #[label(borrowck_use_due_to_use_closure)]
184 #[label(borrowck_assign_due_to_use_closure)]
189 #[label(borrowck_assign_part_due_to_use_closure)]
190 AssignPartInClosure {
196 #[derive(Subdiagnostic)]
197 pub(crate) enum CaptureVarKind {
198 #[label(borrowck_capture_immute)]
203 #[label(borrowck_capture_mut)]
208 #[label(borrowck_capture_move)]
215 #[derive(Subdiagnostic)]
216 pub(crate) enum CaptureVarCause {
217 #[label(borrowck_var_borrow_by_use_place_in_generator)]
218 BorrowUsePlaceGenerator {
223 #[label(borrowck_var_borrow_by_use_place_in_closure)]
224 BorrowUsePlaceClosure {
231 #[derive(Diagnostic)]
232 #[diag(borrowck_cannot_move_when_borrowed, code = "E0505")]
233 pub(crate) struct MoveBorrow<'a> {
235 pub borrow_place: &'a str,
236 pub value_place: &'a str,
241 pub borrow_span: Span,