@@ -67,12 +67,14 @@ impl<'a> AstValidator<'a> {
67
67
}
68
68
}
69
69
70
- fn check_decl_no_pat < ReportFn : Fn ( Span ) > ( & self , decl : & FnDecl , report_err : ReportFn ) {
70
+ fn check_decl_no_pat < ReportFn : Fn ( Span , bool ) > ( & self , decl : & FnDecl , report_err : ReportFn ) {
71
71
for arg in & decl. inputs {
72
72
match arg. pat . node {
73
73
PatKind :: Ident ( BindingMode :: ByValue ( Mutability :: Immutable ) , _, None ) |
74
74
PatKind :: Wild => { }
75
- _ => report_err ( arg. pat . span ) ,
75
+ PatKind :: Ident ( BindingMode :: ByValue ( Mutability :: Mutable ) , _, None ) =>
76
+ report_err ( arg. pat . span , true ) ,
77
+ _ => report_err ( arg. pat . span , false ) ,
76
78
}
77
79
}
78
80
}
@@ -149,7 +151,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
149
151
fn visit_ty ( & mut self , ty : & ' a Ty ) {
150
152
match ty. node {
151
153
TyKind :: BareFn ( ref bfty) => {
152
- self . check_decl_no_pat ( & bfty. decl , |span| {
154
+ self . check_decl_no_pat ( & bfty. decl , |span, _ | {
153
155
struct_span_err ! ( self . session, span, E0561 ,
154
156
"patterns aren't allowed in function pointer types" ) . emit ( ) ;
155
157
} ) ;
@@ -253,12 +255,16 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
253
255
if let TraitItemKind :: Method ( ref sig, ref block) = trait_item. node {
254
256
self . check_trait_fn_not_const ( sig. constness ) ;
255
257
if block. is_none ( ) {
256
- self . check_decl_no_pat ( & sig. decl , |span| {
257
- self . session . buffer_lint (
258
- lint:: builtin:: PATTERNS_IN_FNS_WITHOUT_BODY ,
259
- trait_item. id , span,
260
- "patterns aren't allowed in methods \
261
- without bodies") ;
258
+ self . check_decl_no_pat ( & sig. decl , |span, mut_ident| {
259
+ if mut_ident {
260
+ self . session . buffer_lint (
261
+ lint:: builtin:: PATTERNS_IN_FNS_WITHOUT_BODY ,
262
+ trait_item. id , span,
263
+ "patterns aren't allowed in methods without bodies" ) ;
264
+ } else {
265
+ struct_span_err ! ( self . session, span, E0642 ,
266
+ "patterns aren't allowed in methods without bodies" ) . emit ( ) ;
267
+ }
262
268
} ) ;
263
269
}
264
270
}
@@ -292,7 +298,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
292
298
fn visit_foreign_item ( & mut self , fi : & ' a ForeignItem ) {
293
299
match fi. node {
294
300
ForeignItemKind :: Fn ( ref decl, _) => {
295
- self . check_decl_no_pat ( decl, |span| {
301
+ self . check_decl_no_pat ( decl, |span, _ | {
296
302
struct_span_err ! ( self . session, span, E0130 ,
297
303
"patterns aren't allowed in foreign function declarations" )
298
304
. span_label ( span, "pattern not allowed in foreign function" ) . emit ( ) ;
0 commit comments