3
3
4
4
use /*mod*/ syntax:: ast;
5
5
use /*mod*/ syntax:: visit;
6
- use syntax:: ast:: { expr_field, ident, item_class, item_impl, item_trait} ;
7
- use syntax:: ast:: { local_crate, node_id, private, provided, required} ;
6
+ use syntax:: ast:: { expr_field, expr_struct, ident, item_class, item_impl} ;
7
+ use syntax:: ast:: { item_trait, local_crate, node_id, pat_struct, private} ;
8
+ use syntax:: ast:: { provided, required} ;
8
9
use syntax:: ast_map:: { node_item, node_method} ;
9
10
use ty:: ty_class;
10
11
use typeck:: { method_map, method_origin, method_param, method_static} ;
@@ -160,7 +161,7 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
160
161
match method_map.find(expr.id) {
161
162
None => {
162
163
debug!(" ( privacy checking) checking \
163
- field") ;
164
+ field access ") ;
164
165
check_field ( expr. span , id, ident) ;
165
166
}
166
167
Some ( entry) => {
@@ -173,11 +174,58 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
173
174
_ => { }
174
175
}
175
176
}
177
+ expr_struct( _, fields, _) => {
178
+ match ty:: get ( ty:: expr_ty ( tcx, expr) ) . struct {
179
+ ty_class( id, _) => {
180
+ if id. crate != local_crate ||
181
+ !privileged_items. contains ( id. node ) {
182
+ for fields. each |field| {
183
+ debug ! ( "(privacy checking) checking \
184
+ field in struct literal") ;
185
+ check_field ( expr. span , id,
186
+ field. node . ident ) ;
187
+ }
188
+ }
189
+ }
190
+ _ => {
191
+ tcx. sess . span_bug ( expr. span , ~"struct expr \
192
+ didn' t have \
193
+ struct type ?!") ;
194
+ }
195
+ }
196
+ }
176
197
_ => { }
177
198
}
178
199
179
200
visit:: visit_expr ( expr, method_map, visitor) ;
180
201
} ,
202
+ visit_pat: |pattern, method_map, visitor| {
203
+ match pattern. node {
204
+ pat_struct( _, fields, _) => {
205
+ match ty:: get ( ty:: pat_ty ( tcx, pattern) ) . struct {
206
+ ty_class( id, _) => {
207
+ if id. crate != local_crate ||
208
+ !privileged_items. contains ( id. node ) {
209
+ for fields. each |field| {
210
+ debug ! ( "(privacy checking) checking \
211
+ struct pattern") ;
212
+ check_field ( pattern. span , id,
213
+ field. ident ) ;
214
+ }
215
+ }
216
+ }
217
+ _ => {
218
+ tcx. sess . span_bug ( pattern. span ,
219
+ ~"struct pattern didn' t have \
220
+ struct type ?!") ;
221
+ }
222
+ }
223
+ }
224
+ _ => { }
225
+ }
226
+
227
+ visit:: visit_pat( pattern, method_map, visitor) ;
228
+ } ,
181
229
.. * visit:: default_visitor ( )
182
230
} ) ;
183
231
visit:: visit_crate ( * crate , method_map, visitor) ;
0 commit comments