@@ -55,6 +55,17 @@ impl<'a> AstValidator<'a> {
55
55
err. emit ( ) ;
56
56
}
57
57
}
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
+ }
58
69
}
59
70
60
71
impl < ' a > Visitor for AstValidator < ' a > {
@@ -82,6 +93,23 @@ impl<'a> Visitor for AstValidator<'a> {
82
93
visit:: walk_expr ( self , expr)
83
94
}
84
95
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
+
85
113
fn visit_path ( & mut self , path : & Path , id : NodeId ) {
86
114
if path. global && path. segments . len ( ) > 0 {
87
115
let ident = path. segments [ 0 ] . identifier ;
@@ -138,13 +166,15 @@ impl<'a> Visitor for AstValidator<'a> {
138
166
fn visit_foreign_item ( & mut self , fi : & ForeignItem ) {
139
167
match fi. node {
140
168
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") ;
146
175
}
147
- }
176
+ err. emit ( ) ;
177
+ } ) ;
148
178
}
149
179
ForeignItemKind :: Static ( ..) => { }
150
180
}
0 commit comments