@@ -130,6 +130,10 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
130
130
self . save_ctxt . span_from_span ( span)
131
131
}
132
132
133
+ fn lookup_def_id ( & self , ref_id : NodeId ) -> Option < DefId > {
134
+ self . save_ctxt . lookup_def_id ( ref_id)
135
+ }
136
+
133
137
pub fn dump_crate_info ( & mut self , name : & str , krate : & ast:: Crate ) {
134
138
let source_file = self . tcx . sess . local_crate_source_file . as_ref ( ) ;
135
139
let crate_root = source_file. map ( |source_file| {
@@ -223,13 +227,6 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
223
227
}
224
228
}
225
229
226
- fn lookup_def_id ( & self , ref_id : NodeId ) -> Option < DefId > {
227
- match self . save_ctxt . get_path_res ( ref_id) {
228
- Res :: PrimTy ( ..) | Res :: SelfTy ( ..) | Res :: Err => None ,
229
- def => Some ( def. def_id ( ) ) ,
230
- }
231
- }
232
-
233
230
fn process_formals ( & mut self , formals : & ' l [ ast:: Param ] , qualname : & str ) {
234
231
for arg in formals {
235
232
self . visit_pat ( & arg. pat ) ;
@@ -283,36 +280,32 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
283
280
) {
284
281
debug ! ( "process_method: {}:{}" , id, ident) ;
285
282
286
- if let Some ( mut method_data) = self . save_ctxt . get_method_data ( id, ident, span) {
287
- let sig_str = crate :: make_signature ( & sig. decl , & generics) ;
288
- if body. is_some ( ) {
289
- self . nest_tables (
290
- id,
291
- |v| v. process_formals ( & sig. decl . inputs , & method_data. qualname ) ,
292
- ) ;
293
- }
283
+ let hir_id = self . tcx . hir ( ) . node_to_hir_id ( id) ;
284
+ self . nest_tables ( id, |v| {
285
+ if let Some ( mut method_data) = v. save_ctxt . get_method_data ( id, ident, span) {
286
+ v. process_formals ( & sig. decl . inputs , & method_data. qualname ) ;
287
+ v. process_generic_params ( & generics, & method_data. qualname , id) ;
294
288
295
- self . process_generic_params ( & generics, & method_data. qualname , id) ;
289
+ method_data. value = crate :: make_signature ( & sig. decl , & generics) ;
290
+ method_data. sig = sig:: method_signature ( id, ident, generics, sig, & v. save_ctxt ) ;
296
291
297
- method_data. value = sig_str;
298
- method_data. sig = sig:: method_signature ( id, ident, generics, sig, & self . save_ctxt ) ;
299
- let hir_id = self . tcx . hir ( ) . node_to_hir_id ( id) ;
300
- self . dumper . dump_def ( & access_from_vis ! ( self . save_ctxt, vis, hir_id) , method_data) ;
301
- }
292
+ v. dumper . dump_def ( & access_from_vis ! ( v. save_ctxt, vis, hir_id) , method_data) ;
293
+ }
302
294
303
- // walk arg and return types
304
- for arg in & sig. decl . inputs {
305
- self . visit_ty ( & arg. ty ) ;
306
- }
295
+ // walk arg and return types
296
+ for arg in & sig. decl . inputs {
297
+ v . visit_ty ( & arg. ty ) ;
298
+ }
307
299
308
- if let ast:: FunctionRetTy :: Ty ( ref ret_ty) = sig. decl . output {
309
- self . visit_ty ( ret_ty) ;
310
- }
300
+ if let ast:: FunctionRetTy :: Ty ( ref ret_ty) = sig. decl . output {
301
+ v . visit_ty ( ret_ty) ;
302
+ }
311
303
312
- // walk the fn body
313
- if let Some ( body) = body {
314
- self . nest_tables ( id, |v| v. visit_block ( body) ) ;
315
- }
304
+ // walk the fn body
305
+ if let Some ( body) = body {
306
+ v. visit_block ( body) ;
307
+ }
308
+ } ) ;
316
309
}
317
310
318
311
fn process_struct_field_def ( & mut self , field : & ast:: StructField , parent_id : NodeId ) {
@@ -377,26 +370,31 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
377
370
ty_params : & ' l ast:: Generics ,
378
371
body : & ' l ast:: Block ,
379
372
) {
380
- if let Some ( fn_data) = self . save_ctxt . get_item_data ( item) {
381
- down_cast_data ! ( fn_data, DefData , item. span) ;
382
- self . nest_tables (
383
- item. id ,
384
- |v| v. process_formals ( & decl. inputs , & fn_data. qualname ) ,
385
- ) ;
386
- self . process_generic_params ( ty_params, & fn_data. qualname , item. id ) ;
387
- let hir_id = self . tcx . hir ( ) . node_to_hir_id ( item. id ) ;
388
- self . dumper . dump_def ( & access_from ! ( self . save_ctxt, item, hir_id) , fn_data) ;
389
- }
373
+ let hir_id = self . tcx . hir ( ) . node_to_hir_id ( item. id ) ;
374
+ self . nest_tables ( item. id , |v| {
375
+ if let Some ( fn_data) = v. save_ctxt . get_item_data ( item) {
376
+ down_cast_data ! ( fn_data, DefData , item. span) ;
377
+ v. process_formals ( & decl. inputs , & fn_data. qualname ) ;
378
+ v. process_generic_params ( ty_params, & fn_data. qualname , item. id ) ;
390
379
391
- for arg in & decl. inputs {
392
- self . visit_ty ( & arg. ty ) ;
393
- }
380
+ v. dumper . dump_def ( & access_from ! ( v. save_ctxt, item, hir_id) , fn_data) ;
381
+ }
394
382
395
- if let ast:: FunctionRetTy :: Ty ( ref ret_ty) = decl. output {
396
- self . visit_ty ( & ret_ty) ;
397
- }
383
+ for arg in & decl. inputs {
384
+ v. visit_ty ( & arg. ty )
385
+ }
386
+
387
+ if let ast:: FunctionRetTy :: Ty ( ref ret_ty) = decl. output {
388
+ if let ast:: TyKind :: ImplTrait ( ..) = ret_ty. node {
389
+ // FIXME: Opaque type desugaring prevents us from easily
390
+ // processing trait bounds. See `visit_ty` for more details.
391
+ } else {
392
+ v. visit_ty ( & ret_ty) ;
393
+ }
394
+ }
398
395
399
- self . nest_tables ( item. id , |v| v. visit_block ( & body) ) ;
396
+ v. visit_block ( & body) ;
397
+ } ) ;
400
398
}
401
399
402
400
fn process_static_or_const_item (
@@ -1113,11 +1111,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
1113
1111
// FIXME: uses of the assoc type should ideally point to this
1114
1112
// 'def' and the name here should be a ref to the def in the
1115
1113
// trait.
1116
- for bound in bounds. iter ( ) {
1117
- if let ast:: GenericBound :: Trait ( trait_ref, _) = bound {
1118
- self . process_path ( trait_ref. trait_ref . ref_id , & trait_ref. trait_ref . path )
1119
- }
1120
- }
1114
+ self . process_bounds ( & bounds) ;
1121
1115
}
1122
1116
ast:: ImplItemKind :: Macro ( _) => { }
1123
1117
}
@@ -1364,10 +1358,10 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
1364
1358
self . visit_ty ( & ty) ;
1365
1359
self . process_generic_params ( ty_params, & qualname, item. id ) ;
1366
1360
}
1367
- OpaqueTy ( ref _bounds , ref ty_params) => {
1361
+ OpaqueTy ( ref bounds , ref ty_params) => {
1368
1362
let qualname = format ! ( "::{}" ,
1369
1363
self . tcx. def_path_str( self . tcx. hir( ) . local_def_id_from_node_id( item. id) ) ) ;
1370
- // FIXME do something with _bounds
1364
+
1371
1365
let value = String :: new ( ) ;
1372
1366
if !self . span . filter_generated ( item. ident . span ) {
1373
1367
let span = self . span_from_span ( item. ident . span ) ;
@@ -1393,6 +1387,7 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
1393
1387
) ;
1394
1388
}
1395
1389
1390
+ self . process_bounds ( bounds) ;
1396
1391
self . process_generic_params ( ty_params, & qualname, item. id ) ;
1397
1392
}
1398
1393
Mac ( _) => ( ) ,
@@ -1449,6 +1444,18 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
1449
1444
self . visit_ty ( element) ;
1450
1445
self . nest_tables ( length. id , |v| v. visit_expr ( & length. value ) ) ;
1451
1446
}
1447
+ ast:: TyKind :: ImplTrait ( id, ref bounds) => {
1448
+ // FIXME: As of writing, the opaque type lowering introduces
1449
+ // another DefPath scope/segment (used to declare the resulting
1450
+ // opaque type item).
1451
+ // However, the synthetic scope does *not* have associated
1452
+ // typeck tables, which means we can't nest it and we fire an
1453
+ // assertion when resolving the qualified type paths in trait
1454
+ // bounds...
1455
+ // This will panic if called on return type `impl Trait`, which
1456
+ // we guard against in `process_fn`.
1457
+ self . nest_tables ( id, |v| v. process_bounds ( bounds) ) ;
1458
+ }
1452
1459
_ => visit:: walk_ty ( self , t) ,
1453
1460
}
1454
1461
}
0 commit comments