1 //! Errors emitted by ast_passes.
3 use rustc_errors::{fluent, AddSubdiagnostic, Applicability, Diagnostic};
4 use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
5 use rustc_span::{Span, Symbol};
7 use crate::ast_validation::ForbiddenLetReason;
9 #[derive(SessionDiagnostic)]
10 #[diag(ast_passes::forbidden_let)]
12 pub struct ForbiddenLet {
16 pub(crate) reason: ForbiddenLetReason,
19 impl AddSubdiagnostic for ForbiddenLetReason {
20 fn add_to_diagnostic(self, diag: &mut Diagnostic) {
22 Self::GenericForbidden => {}
23 Self::NotSupportedOr(span) => {
24 diag.span_note(span, fluent::ast_passes::not_supported_or);
26 Self::NotSupportedParentheses(span) => {
27 diag.span_note(span, fluent::ast_passes::not_supported_parentheses);
33 #[derive(SessionDiagnostic)]
34 #[diag(ast_passes::forbidden_assoc_constraint)]
35 pub struct ForbiddenAssocConstraint {
40 #[derive(SessionDiagnostic)]
41 #[diag(ast_passes::keyword_lifetime)]
42 pub struct KeywordLifetime {
47 #[derive(SessionDiagnostic)]
48 #[diag(ast_passes::invalid_label)]
49 pub struct InvalidLabel {
55 #[derive(SessionDiagnostic)]
56 #[diag(ast_passes::invalid_visibility, code = "E0449")]
57 pub struct InvalidVisibility {
60 #[label(ast_passes::implied)]
61 pub implied: Option<Span>,
63 pub note: Option<InvalidVisibilityNote>,
66 #[derive(SessionSubdiagnostic)]
67 pub enum InvalidVisibilityNote {
68 #[note(ast_passes::individual_impl_items)]
70 #[note(ast_passes::individual_foreign_items)]
71 IndividualForeignItems,
74 #[derive(SessionDiagnostic)]
75 #[diag(ast_passes::trait_fn_async, code = "E0706")]
77 #[note(ast_passes::note2)]
78 pub struct TraitFnAsync {
85 #[derive(SessionDiagnostic)]
86 #[diag(ast_passes::trait_fn_const, code = "E0379")]
87 pub struct TraitFnConst {
93 #[derive(SessionDiagnostic)]
94 #[diag(ast_passes::forbidden_lifetime_bound)]
95 pub struct ForbiddenLifetimeBound {
100 #[derive(SessionDiagnostic)]
101 #[diag(ast_passes::forbidden_non_lifetime_param)]
102 pub struct ForbiddenNonLifetimeParam {
104 pub spans: Vec<Span>,
107 #[derive(SessionDiagnostic)]
108 #[diag(ast_passes::fn_param_too_many)]
109 pub struct FnParamTooMany {
112 pub max_num_args: usize,
115 #[derive(SessionDiagnostic)]
116 #[diag(ast_passes::fn_param_c_var_args_only)]
117 pub struct FnParamCVarArgsOnly {
122 #[derive(SessionDiagnostic)]
123 #[diag(ast_passes::fn_param_c_var_args_not_last)]
124 pub struct FnParamCVarArgsNotLast {
129 #[derive(SessionDiagnostic)]
130 #[diag(ast_passes::fn_param_doc_comment)]
131 pub struct FnParamDocComment {
137 #[derive(SessionDiagnostic)]
138 #[diag(ast_passes::fn_param_forbidden_attr)]
139 pub struct FnParamForbiddenAttr {
144 #[derive(SessionDiagnostic)]
145 #[diag(ast_passes::fn_param_forbidden_self)]
147 pub struct FnParamForbiddenSelf {
153 #[derive(SessionDiagnostic)]
154 #[diag(ast_passes::forbidden_default)]
155 pub struct ForbiddenDefault {
162 #[derive(SessionDiagnostic)]
163 #[diag(ast_passes::assoc_const_without_body)]
164 pub struct AssocConstWithoutBody {
167 #[suggestion(code = " = <expr>;", applicability = "has-placeholders")]
168 pub replace_span: Span,
171 #[derive(SessionDiagnostic)]
172 #[diag(ast_passes::assoc_fn_without_body)]
173 pub struct AssocFnWithoutBody {
176 #[suggestion(code = " {{ <body> }}", applicability = "has-placeholders")]
177 pub replace_span: Span,
180 #[derive(SessionDiagnostic)]
181 #[diag(ast_passes::assoc_type_without_body)]
182 pub struct AssocTypeWithoutBody {
185 #[suggestion(code = " = <type>;", applicability = "has-placeholders")]
186 pub replace_span: Span,
189 #[derive(SessionDiagnostic)]
190 #[diag(ast_passes::const_without_body)]
191 pub struct ConstWithoutBody {
194 #[suggestion(code = " = <expr>;", applicability = "has-placeholders")]
195 pub replace_span: Span,
198 #[derive(SessionDiagnostic)]
199 #[diag(ast_passes::static_without_body)]
200 pub struct StaticWithoutBody {
203 #[suggestion(code = " = <expr>;", applicability = "has-placeholders")]
204 pub replace_span: Span,
207 #[derive(SessionDiagnostic)]
208 #[diag(ast_passes::ty_alias_without_body)]
209 pub struct TyAliasWithoutBody {
212 #[suggestion(code = " = <type>;", applicability = "has-placeholders")]
213 pub replace_span: Span,
216 #[derive(SessionDiagnostic)]
217 #[diag(ast_passes::fn_without_body)]
218 pub struct FnWithoutBody {
221 #[suggestion(code = " {{ <body> }}", applicability = "has-placeholders")]
222 pub replace_span: Span,
224 pub extern_block_suggestion: Option<ExternBlockSuggestion>,
227 pub struct ExternBlockSuggestion {
228 pub start_span: Span,
230 pub abi: Option<Symbol>,
233 impl AddSubdiagnostic for ExternBlockSuggestion {
234 fn add_to_diagnostic(self, diag: &mut Diagnostic) {
235 let start_suggestion = if let Some(abi) = self.abi {
236 format!("extern \"{}\" {{", abi)
238 "extern {".to_owned()
240 let end_suggestion = " }".to_owned();
242 diag.multipart_suggestion(
243 fluent::ast_passes::extern_block_suggestion,
244 vec![(self.start_span, start_suggestion), (self.end_span, end_suggestion)],
245 Applicability::MaybeIncorrect,