Always report patterns more complex than `mut IDENT` as errors
This commit is contained in:
parent
1055bdfb2a
commit
f7b4b88840
|
@ -67,12 +67,14 @@ impl<'a> AstValidator<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_decl_no_pat<ReportFn: Fn(Span)>(&self, decl: &FnDecl, report_err: ReportFn) {
|
||||
fn check_decl_no_pat<ReportFn: Fn(Span, bool)>(&self, decl: &FnDecl, report_err: ReportFn) {
|
||||
for arg in &decl.inputs {
|
||||
match arg.pat.node {
|
||||
PatKind::Ident(BindingMode::ByValue(Mutability::Immutable), _, None) |
|
||||
PatKind::Wild => {}
|
||||
_ => report_err(arg.pat.span),
|
||||
PatKind::Ident(BindingMode::ByValue(Mutability::Mutable), _, None) =>
|
||||
report_err(arg.pat.span, true),
|
||||
_ => report_err(arg.pat.span, false),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -149,7 +151,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
fn visit_ty(&mut self, ty: &'a Ty) {
|
||||
match ty.node {
|
||||
TyKind::BareFn(ref bfty) => {
|
||||
self.check_decl_no_pat(&bfty.decl, |span| {
|
||||
self.check_decl_no_pat(&bfty.decl, |span, _| {
|
||||
struct_span_err!(self.session, span, E0561,
|
||||
"patterns aren't allowed in function pointer types").emit();
|
||||
});
|
||||
|
@ -253,12 +255,16 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
if let TraitItemKind::Method(ref sig, ref block) = trait_item.node {
|
||||
self.check_trait_fn_not_const(sig.constness);
|
||||
if block.is_none() {
|
||||
self.check_decl_no_pat(&sig.decl, |span| {
|
||||
self.session.buffer_lint(
|
||||
lint::builtin::PATTERNS_IN_FNS_WITHOUT_BODY,
|
||||
trait_item.id, span,
|
||||
"patterns aren't allowed in methods \
|
||||
without bodies");
|
||||
self.check_decl_no_pat(&sig.decl, |span, mut_ident| {
|
||||
if mut_ident {
|
||||
self.session.buffer_lint(
|
||||
lint::builtin::PATTERNS_IN_FNS_WITHOUT_BODY,
|
||||
trait_item.id, span,
|
||||
"patterns aren't allowed in methods without bodies");
|
||||
} else {
|
||||
struct_span_err!(self.session, span, E0642,
|
||||
"patterns aren't allowed in methods without bodies").emit();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -292,7 +298,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
fn visit_foreign_item(&mut self, fi: &'a ForeignItem) {
|
||||
match fi.node {
|
||||
ForeignItemKind::Fn(ref decl, _) => {
|
||||
self.check_decl_no_pat(decl, |span| {
|
||||
self.check_decl_no_pat(decl, |span, _| {
|
||||
struct_span_err!(self.session, span, E0130,
|
||||
"patterns aren't allowed in foreign function declarations")
|
||||
.span_label(span, "pattern not allowed in foreign function").emit();
|
||||
|
|
|
@ -264,4 +264,5 @@ register_diagnostics! {
|
|||
E0226, // only a single explicit lifetime bound is permitted
|
||||
E0472, // asm! is unsupported on this target
|
||||
E0561, // patterns aren't allowed in function pointer types
|
||||
E0642, // patterns aren't allowed in methods without bodies
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ trait Tr {
|
|||
fn f1(mut arg: u8); //~ ERROR patterns aren't allowed in methods without bodies
|
||||
//~^ WARN was previously accepted
|
||||
fn f2(&arg: u8); //~ ERROR patterns aren't allowed in methods without bodies
|
||||
//~^ WARN was previously accepted
|
||||
fn g1(arg: u8); // OK
|
||||
fn g2(_: u8); // OK
|
||||
#[allow(anonymous_parameters)]
|
||||
|
|
|
@ -30,8 +30,7 @@ mod bad_pat {
|
|||
m!((bad, pat));
|
||||
//~^ ERROR patterns aren't allowed in function pointer types
|
||||
//~| ERROR patterns aren't allowed in foreign function declarations
|
||||
//~| WARN patterns aren't allowed in methods without bodies
|
||||
//~| WARN this was previously accepted
|
||||
//~| ERROR patterns aren't allowed in methods without bodies
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
Loading…
Reference in New Issue