@@ -67,12 +67,14 @@ impl<'a> AstValidator<'a> {
6767 }
6868 }
6969
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 ) {
7171 for arg in & decl. inputs {
7272 match arg. pat . node {
7373 PatKind :: Ident ( BindingMode :: ByValue ( Mutability :: Immutable ) , _, None ) |
7474 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 ) ,
7678 }
7779 }
7880 }
@@ -149,7 +151,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
149151 fn visit_ty ( & mut self , ty : & ' a Ty ) {
150152 match ty. node {
151153 TyKind :: BareFn ( ref bfty) => {
152- self . check_decl_no_pat ( & bfty. decl , |span| {
154+ self . check_decl_no_pat ( & bfty. decl , |span, _ | {
153155 struct_span_err ! ( self . session, span, E0561 ,
154156 "patterns aren't allowed in function pointer types" ) . emit ( ) ;
155157 } ) ;
@@ -253,12 +255,16 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
253255 if let TraitItemKind :: Method ( ref sig, ref block) = trait_item. node {
254256 self . check_trait_fn_not_const ( sig. constness ) ;
255257 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+ }
262268 } ) ;
263269 }
264270 }
@@ -292,7 +298,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
292298 fn visit_foreign_item ( & mut self , fi : & ' a ForeignItem ) {
293299 match fi. node {
294300 ForeignItemKind :: Fn ( ref decl, _) => {
295- self . check_decl_no_pat ( decl, |span| {
301+ self . check_decl_no_pat ( decl, |span, _ | {
296302 struct_span_err ! ( self . session, span, E0130 ,
297303 "patterns aren't allowed in foreign function declarations" )
298304 . span_label ( span, "pattern not allowed in foreign function" ) . emit ( ) ;
0 commit comments