Skip to content

Commit 269c853

Browse files
committed
Migrate forbidden_lifetime_bound, forbidden_non_lifetime_param, too_many_params, c_var_args_without_named_arg, c_var_args_not_last
1 parent 8d042f4 commit 269c853

File tree

3 files changed

+57
-26
lines changed

3 files changed

+57
-26
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,7 @@ impl<'a> AstValidator<'a> {
293293

294294
fn check_trait_fn_not_const(&self, constness: Const) {
295295
if let Const::Yes(span) = constness {
296-
struct_span_err!(
297-
self.session,
298-
span,
299-
E0379,
300-
"functions in traits cannot be declared const"
301-
)
302-
.span_label(span, "functions in traits cannot be const")
303-
.emit();
296+
self.session.emit_err(TraitFnConst { span });
304297
}
305298
}
306299

@@ -313,19 +306,15 @@ impl<'a> AstValidator<'a> {
313306
GenericParamKind::Lifetime { .. } => {
314307
if !param.bounds.is_empty() {
315308
let spans: Vec<_> = param.bounds.iter().map(|b| b.span()).collect();
316-
self.err_handler()
317-
.span_err(spans, "lifetime bounds cannot be used in this context");
309+
self.session.emit_err(ForbiddenLifetimeBound { spans });
318310
}
319311
None
320312
}
321313
_ => Some(param.ident.span),
322314
})
323315
.collect();
324316
if !non_lt_param_spans.is_empty() {
325-
self.err_handler().span_err(
326-
non_lt_param_spans,
327-
"only lifetime parameters can be used in this context",
328-
);
317+
self.session.emit_err(ForbiddenNonLifetimeParam { spans: non_lt_param_spans });
329318
}
330319
}
331320

@@ -342,30 +331,21 @@ impl<'a> AstValidator<'a> {
342331
let max_num_args: usize = u16::MAX.into();
343332
if fn_decl.inputs.len() > max_num_args {
344333
let Param { span, .. } = fn_decl.inputs[0];
345-
self.err_handler().span_fatal(
346-
span,
347-
&format!("function can not have more than {} arguments", max_num_args),
348-
);
334+
self.session.emit_err(TooManyParams { span, max_num_args });
349335
}
350336
}
351337

352338
fn check_decl_cvaradic_pos(&self, fn_decl: &FnDecl) {
353339
match &*fn_decl.inputs {
354340
[Param { ty, span, .. }] => {
355341
if let TyKind::CVarArgs = ty.kind {
356-
self.err_handler().span_err(
357-
*span,
358-
"C-variadic function must be declared with at least one named argument",
359-
);
342+
self.session.emit_err(CVarArgsWithoutNamedArg { span: *span });
360343
}
361344
}
362345
[ps @ .., _] => {
363346
for Param { ty, span, .. } in ps {
364347
if let TyKind::CVarArgs = ty.kind {
365-
self.err_handler().span_err(
366-
*span,
367-
"`...` must be the last argument of a C-variadic function",
368-
);
348+
self.session.emit_err(CVarArgsNotLast { span: *span });
369349
}
370350
}
371351
}

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,39 @@ pub struct TraitFnConst {
9090
#[label]
9191
pub span: Span,
9292
}
93+
94+
#[derive(SessionDiagnostic)]
95+
#[error(ast_passes::forbidden_lifetime_bound)]
96+
pub struct ForbiddenLifetimeBound {
97+
#[primary_span]
98+
pub spans: Vec<Span>,
99+
}
100+
101+
#[derive(SessionDiagnostic)]
102+
#[error(ast_passes::forbidden_non_lifetime_param)]
103+
pub struct ForbiddenNonLifetimeParam {
104+
#[primary_span]
105+
pub spans: Vec<Span>,
106+
}
107+
108+
#[derive(SessionDiagnostic)]
109+
#[error(ast_passes::too_many_params)]
110+
pub struct TooManyParams {
111+
#[primary_span]
112+
pub span: Span,
113+
pub max_num_args: usize,
114+
}
115+
116+
#[derive(SessionDiagnostic)]
117+
#[error(ast_passes::c_var_args_without_named_arg)]
118+
pub struct CVarArgsWithoutNamedArg {
119+
#[primary_span]
120+
pub span: Span,
121+
}
122+
123+
#[derive(SessionDiagnostic)]
124+
#[error(ast_passes::c_var_args_not_last)]
125+
pub struct CVarArgsNotLast {
126+
#[primary_span]
127+
pub span: Span,
128+
}

compiler/rustc_error_messages/locales/en-US/ast_passes.ftl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,18 @@ ast_passes_trait_fn_async =
3131
ast_passes_trait_fn_const =
3232
functions in traits cannot be declared const
3333
.label = functions in traits cannot be const
34+
35+
ast_passes_forbidden_lifetime_bound =
36+
lifetime bounds cannot be used in this context
37+
38+
ast_passes_forbidden_non_lifetime_param =
39+
only lifetime parameters can be used in this context
40+
41+
ast_passes_too_many_params =
42+
function can not have more than {$max_num_args} arguments
43+
44+
ast_passes_c_var_args_without_named_arg =
45+
C-variadic function must be declared with at least one named argument
46+
47+
ast_passes_c_var_args_not_last =
48+
`...` must be the last argument of a C-variadic function

0 commit comments

Comments
 (0)