@@ -55,6 +55,17 @@ impl<'a> AstValidator<'a> {
5555 err. emit ( ) ;
5656 }
5757 }
58+
59+ fn check_decl_no_pat < ReportFn : Fn ( Span , bool ) > ( & self , decl : & FnDecl , report_err : ReportFn ) {
60+ for arg in & decl. inputs {
61+ match arg. pat . node {
62+ PatKind :: Ident ( BindingMode :: ByValue ( Mutability :: Immutable ) , _, None ) |
63+ PatKind :: Wild => { }
64+ PatKind :: Ident ( ..) => report_err ( arg. pat . span , true ) ,
65+ _ => report_err ( arg. pat . span , false ) ,
66+ }
67+ }
68+ }
5869}
5970
6071impl < ' a > Visitor for AstValidator < ' a > {
@@ -82,6 +93,23 @@ impl<'a> Visitor for AstValidator<'a> {
8293 visit:: walk_expr ( self , expr)
8394 }
8495
96+ fn visit_ty ( & mut self , ty : & Ty ) {
97+ match ty. node {
98+ TyKind :: BareFn ( ref bfty) => {
99+ self . check_decl_no_pat ( & bfty. decl , |span, _| {
100+ let mut err = struct_span_err ! ( self . session, span, E0561 ,
101+ "patterns aren't allowed in function pointer types" ) ;
102+ err. span_note ( span, "this is a recent error, see \
103+ issue #35203 for more details") ;
104+ err. emit ( ) ;
105+ } ) ;
106+ }
107+ _ => { }
108+ }
109+
110+ visit:: walk_ty ( self , ty)
111+ }
112+
85113 fn visit_path ( & mut self , path : & Path , id : NodeId ) {
86114 if path. global && path. segments . len ( ) > 0 {
87115 let ident = path. segments [ 0 ] . identifier ;
@@ -138,13 +166,15 @@ impl<'a> Visitor for AstValidator<'a> {
138166 fn visit_foreign_item ( & mut self , fi : & ForeignItem ) {
139167 match fi. node {
140168 ForeignItemKind :: Fn ( ref decl, _) => {
141- for arg in & decl. inputs {
142- match arg. pat . node {
143- PatKind :: Ident ( ..) | PatKind :: Wild => { }
144- _ => span_err ! ( self . session, arg. pat. span, E0130 ,
145- "patterns aren't allowed in foreign function declarations" )
169+ self . check_decl_no_pat ( decl, |span, is_recent| {
170+ let mut err = struct_span_err ! ( self . session, span, E0130 ,
171+ "patterns aren't allowed in foreign function declarations" ) ;
172+ if is_recent {
173+ err. span_note ( span, "this is a recent error, see \
174+ issue #35203 for more details") ;
146175 }
147- }
176+ err. emit ( ) ;
177+ } ) ;
148178 }
149179 ForeignItemKind :: Static ( ..) => { }
150180 }
0 commit comments