Migrate forbidden_lifetime_bound, forbidden_non_lifetime_param, too_many_params, c_var_args_without_named_arg, c_var_args_not_last
This commit is contained in:
parent
8d042f4483
commit
269c85390c
3 changed files with 57 additions and 26 deletions
|
@ -293,14 +293,7 @@ impl<'a> AstValidator<'a> {
|
||||||
|
|
||||||
fn check_trait_fn_not_const(&self, constness: Const) {
|
fn check_trait_fn_not_const(&self, constness: Const) {
|
||||||
if let Const::Yes(span) = constness {
|
if let Const::Yes(span) = constness {
|
||||||
struct_span_err!(
|
self.session.emit_err(TraitFnConst { span });
|
||||||
self.session,
|
|
||||||
span,
|
|
||||||
E0379,
|
|
||||||
"functions in traits cannot be declared const"
|
|
||||||
)
|
|
||||||
.span_label(span, "functions in traits cannot be const")
|
|
||||||
.emit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,8 +306,7 @@ impl<'a> AstValidator<'a> {
|
||||||
GenericParamKind::Lifetime { .. } => {
|
GenericParamKind::Lifetime { .. } => {
|
||||||
if !param.bounds.is_empty() {
|
if !param.bounds.is_empty() {
|
||||||
let spans: Vec<_> = param.bounds.iter().map(|b| b.span()).collect();
|
let spans: Vec<_> = param.bounds.iter().map(|b| b.span()).collect();
|
||||||
self.err_handler()
|
self.session.emit_err(ForbiddenLifetimeBound { spans });
|
||||||
.span_err(spans, "lifetime bounds cannot be used in this context");
|
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -322,10 +314,7 @@ impl<'a> AstValidator<'a> {
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
if !non_lt_param_spans.is_empty() {
|
if !non_lt_param_spans.is_empty() {
|
||||||
self.err_handler().span_err(
|
self.session.emit_err(ForbiddenNonLifetimeParam { spans: non_lt_param_spans });
|
||||||
non_lt_param_spans,
|
|
||||||
"only lifetime parameters can be used in this context",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,10 +331,7 @@ impl<'a> AstValidator<'a> {
|
||||||
let max_num_args: usize = u16::MAX.into();
|
let max_num_args: usize = u16::MAX.into();
|
||||||
if fn_decl.inputs.len() > max_num_args {
|
if fn_decl.inputs.len() > max_num_args {
|
||||||
let Param { span, .. } = fn_decl.inputs[0];
|
let Param { span, .. } = fn_decl.inputs[0];
|
||||||
self.err_handler().span_fatal(
|
self.session.emit_err(TooManyParams { span, max_num_args });
|
||||||
span,
|
|
||||||
&format!("function can not have more than {} arguments", max_num_args),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,19 +339,13 @@ impl<'a> AstValidator<'a> {
|
||||||
match &*fn_decl.inputs {
|
match &*fn_decl.inputs {
|
||||||
[Param { ty, span, .. }] => {
|
[Param { ty, span, .. }] => {
|
||||||
if let TyKind::CVarArgs = ty.kind {
|
if let TyKind::CVarArgs = ty.kind {
|
||||||
self.err_handler().span_err(
|
self.session.emit_err(CVarArgsWithoutNamedArg { span: *span });
|
||||||
*span,
|
|
||||||
"C-variadic function must be declared with at least one named argument",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[ps @ .., _] => {
|
[ps @ .., _] => {
|
||||||
for Param { ty, span, .. } in ps {
|
for Param { ty, span, .. } in ps {
|
||||||
if let TyKind::CVarArgs = ty.kind {
|
if let TyKind::CVarArgs = ty.kind {
|
||||||
self.err_handler().span_err(
|
self.session.emit_err(CVarArgsNotLast { span: *span });
|
||||||
*span,
|
|
||||||
"`...` must be the last argument of a C-variadic function",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,3 +90,39 @@ pub struct TraitFnConst {
|
||||||
#[label]
|
#[label]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[error(ast_passes::forbidden_lifetime_bound)]
|
||||||
|
pub struct ForbiddenLifetimeBound {
|
||||||
|
#[primary_span]
|
||||||
|
pub spans: Vec<Span>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[error(ast_passes::forbidden_non_lifetime_param)]
|
||||||
|
pub struct ForbiddenNonLifetimeParam {
|
||||||
|
#[primary_span]
|
||||||
|
pub spans: Vec<Span>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[error(ast_passes::too_many_params)]
|
||||||
|
pub struct TooManyParams {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
pub max_num_args: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[error(ast_passes::c_var_args_without_named_arg)]
|
||||||
|
pub struct CVarArgsWithoutNamedArg {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[error(ast_passes::c_var_args_not_last)]
|
||||||
|
pub struct CVarArgsNotLast {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
}
|
||||||
|
|
|
@ -31,3 +31,18 @@ ast_passes_trait_fn_async =
|
||||||
ast_passes_trait_fn_const =
|
ast_passes_trait_fn_const =
|
||||||
functions in traits cannot be declared const
|
functions in traits cannot be declared const
|
||||||
.label = functions in traits cannot be const
|
.label = functions in traits cannot be const
|
||||||
|
|
||||||
|
ast_passes_forbidden_lifetime_bound =
|
||||||
|
lifetime bounds cannot be used in this context
|
||||||
|
|
||||||
|
ast_passes_forbidden_non_lifetime_param =
|
||||||
|
only lifetime parameters can be used in this context
|
||||||
|
|
||||||
|
ast_passes_too_many_params =
|
||||||
|
function can not have more than {$max_num_args} arguments
|
||||||
|
|
||||||
|
ast_passes_c_var_args_without_named_arg =
|
||||||
|
C-variadic function must be declared with at least one named argument
|
||||||
|
|
||||||
|
ast_passes_c_var_args_not_last =
|
||||||
|
`...` must be the last argument of a C-variadic function
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue