]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_borrowck/src/session_diagnostics.rs
Auto merge of #100733 - scottmcm:inline-from-from-identity, r=m-ou-se
[rust.git] / compiler / rustc_borrowck / src / session_diagnostics.rs
1 use rustc_errors::{IntoDiagnosticArg, MultiSpan};
2 use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic};
3 use rustc_middle::ty::Ty;
4 use rustc_span::Span;
5
6 use crate::diagnostics::RegionName;
7
8 #[derive(SessionDiagnostic)]
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(SessionDiagnostic)]
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(SessionSubdiagnostic)]
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(SessionDiagnostic)]
35 #[diag(borrowck::higher_ranked_subtype_error)]
36 pub(crate) struct HigherRankedSubtypeError {
37     #[primary_span]
38     pub span: Span,
39 }
40
41 #[derive(SessionDiagnostic)]
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_short(applicability = "machine-applicable", code = "")]
53     pub span: Span,
54 }
55
56 #[derive(SessionDiagnostic)]
57 #[diag(borrowck::const_not_used_in_type_alias)]
58 pub(crate) struct ConstNotUsedTraitAlias {
59     pub ct: String,
60     #[primary_span]
61     pub span: Span,
62 }
63
64 #[derive(SessionDiagnostic)]
65 #[diag(borrowck::var_cannot_escape_closure)]
66 #[note]
67 #[note(borrowck::cannot_escape)]
68 pub(crate) struct FnMutError {
69     #[primary_span]
70     pub span: Span,
71     #[subdiagnostic]
72     pub ty_err: FnMutReturnTypeErr,
73 }
74
75 #[derive(SessionSubdiagnostic)]
76 pub(crate) enum VarHereDenote {
77     #[label(borrowck::var_here_captured)]
78     Captured {
79         #[primary_span]
80         span: Span,
81     },
82     #[label(borrowck::var_here_defined)]
83     Defined {
84         #[primary_span]
85         span: Span,
86     },
87     #[label(borrowck::closure_inferred_mut)]
88     FnMutInferred {
89         #[primary_span]
90         span: Span,
91     },
92 }
93
94 #[derive(SessionSubdiagnostic)]
95 pub(crate) enum FnMutReturnTypeErr {
96     #[label(borrowck::returned_closure_escaped)]
97     ReturnClosure {
98         #[primary_span]
99         span: Span,
100     },
101     #[label(borrowck::returned_async_block_escaped)]
102     ReturnAsyncBlock {
103         #[primary_span]
104         span: Span,
105     },
106     #[label(borrowck::returned_ref_escaped)]
107     ReturnRef {
108         #[primary_span]
109         span: Span,
110     },
111 }
112
113 #[derive(SessionDiagnostic)]
114 #[diag(borrowck::lifetime_constraints_error)]
115 pub(crate) struct LifetimeOutliveErr {
116     #[primary_span]
117     pub span: Span,
118 }
119
120 #[derive(SessionSubdiagnostic)]
121 pub(crate) enum LifetimeReturnCategoryErr<'a> {
122     #[label(borrowck::returned_lifetime_wrong)]
123     WrongReturn {
124         #[primary_span]
125         span: Span,
126         mir_def_name: &'a str,
127         outlived_fr_name: RegionName,
128         fr_name: &'a RegionName,
129     },
130     #[label(borrowck::returned_lifetime_short)]
131     ShortReturn {
132         #[primary_span]
133         span: Span,
134         category_desc: &'static str,
135         free_region_name: &'a RegionName,
136         outlived_fr_name: RegionName,
137     },
138 }
139
140 impl IntoDiagnosticArg for &RegionName {
141     fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
142         format!("{}", self).into_diagnostic_arg()
143     }
144 }
145
146 impl IntoDiagnosticArg for RegionName {
147     fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
148         format!("{}", self).into_diagnostic_arg()
149     }
150 }
151
152 #[derive(SessionSubdiagnostic)]
153 pub(crate) enum RequireStaticErr {
154     #[note(borrowck::used_impl_require_static)]
155     UsedImpl {
156         #[primary_span]
157         multi_span: MultiSpan,
158     },
159 }