@@ -2,7 +2,7 @@ use log::debug;
2
2
use rustc:: hir:: map:: definitions:: * ;
3
3
use rustc_ast:: ast:: * ;
4
4
use rustc_ast:: token:: { self , Token } ;
5
- use rustc_ast:: visit;
5
+ use rustc_ast:: visit:: { self , FnKind } ;
6
6
use rustc_expand:: expand:: AstFragment ;
7
7
use rustc_hir:: def_id:: DefIndex ;
8
8
use rustc_span:: hygiene:: ExpnId ;
@@ -38,42 +38,6 @@ impl<'a> DefCollector<'a> {
38
38
self . parent_def = orig_parent_def;
39
39
}
40
40
41
- fn visit_async_fn (
42
- & mut self ,
43
- id : NodeId ,
44
- name : Name ,
45
- span : Span ,
46
- header : & FnHeader ,
47
- generics : & ' a Generics ,
48
- decl : & ' a FnDecl ,
49
- body : Option < & ' a Block > ,
50
- ) {
51
- let ( closure_id, return_impl_trait_id) = match header. asyncness {
52
- Async :: Yes { span : _, closure_id, return_impl_trait_id } => {
53
- ( closure_id, return_impl_trait_id)
54
- }
55
- _ => unreachable ! ( ) ,
56
- } ;
57
-
58
- // For async functions, we need to create their inner defs inside of a
59
- // closure to match their desugared representation.
60
- let fn_def_data = DefPathData :: ValueNs ( name) ;
61
- let fn_def = self . create_def ( id, fn_def_data, span) ;
62
- return self . with_parent ( fn_def, |this| {
63
- this. create_def ( return_impl_trait_id, DefPathData :: ImplTrait , span) ;
64
-
65
- visit:: walk_generics ( this, generics) ;
66
- visit:: walk_fn_decl ( this, decl) ;
67
-
68
- let closure_def = this. create_def ( closure_id, DefPathData :: ClosureExpr , span) ;
69
- this. with_parent ( closure_def, |this| {
70
- if let Some ( body) = body {
71
- visit:: walk_block ( this, body) ;
72
- }
73
- } )
74
- } ) ;
75
- }
76
-
77
41
fn collect_field ( & mut self , field : & ' a StructField , index : Option < usize > ) {
78
42
let index = |this : & Self | {
79
43
index. unwrap_or_else ( || {
@@ -117,17 +81,6 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
117
81
| ItemKind :: ExternCrate ( ..)
118
82
| ItemKind :: ForeignMod ( ..)
119
83
| ItemKind :: TyAlias ( ..) => DefPathData :: TypeNs ( i. ident . name ) ,
120
- ItemKind :: Fn ( _, sig, generics, body) if sig. header . asyncness . is_async ( ) => {
121
- return self . visit_async_fn (
122
- i. id ,
123
- i. ident . name ,
124
- i. span ,
125
- & sig. header ,
126
- generics,
127
- & sig. decl ,
128
- body. as_deref ( ) ,
129
- ) ;
130
- }
131
84
ItemKind :: Static ( ..) | ItemKind :: Const ( ..) | ItemKind :: Fn ( ..) => {
132
85
DefPathData :: ValueNs ( i. ident . name )
133
86
}
@@ -154,6 +107,27 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
154
107
} ) ;
155
108
}
156
109
110
+ fn visit_fn ( & mut self , fn_kind : FnKind < ' a > , span : Span , _: NodeId ) {
111
+ if let FnKind :: Fn ( _, _, sig, _, body) = fn_kind {
112
+ if let Async :: Yes { closure_id, return_impl_trait_id, .. } = sig. header . asyncness {
113
+ self . create_def ( return_impl_trait_id, DefPathData :: ImplTrait , span) ;
114
+
115
+ // For async functions, we need to create their inner defs inside of a
116
+ // closure to match their desugared representation. Besides that,
117
+ // we must mirror everything that `visit::walk_fn` below does.
118
+ self . visit_fn_header ( & sig. header ) ;
119
+ visit:: walk_fn_decl ( self , & sig. decl ) ;
120
+ if let Some ( body) = body {
121
+ let closure_def = self . create_def ( closure_id, DefPathData :: ClosureExpr , span) ;
122
+ self . with_parent ( closure_def, |this| this. visit_block ( body) ) ;
123
+ }
124
+ return ;
125
+ }
126
+ }
127
+
128
+ visit:: walk_fn ( self , fn_kind, span) ;
129
+ }
130
+
157
131
fn visit_use_tree ( & mut self , use_tree : & ' a UseTree , id : NodeId , _nested : bool ) {
158
132
self . create_def ( id, DefPathData :: Misc , use_tree. span ) ;
159
133
visit:: walk_use_tree ( self , use_tree, id) ;
@@ -215,19 +189,6 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
215
189
216
190
fn visit_assoc_item ( & mut self , i : & ' a AssocItem , ctxt : visit:: AssocCtxt ) {
217
191
let def_data = match & i. kind {
218
- AssocItemKind :: Fn ( _, FnSig { header, decl } , generics, body)
219
- if header. asyncness . is_async ( ) =>
220
- {
221
- return self . visit_async_fn (
222
- i. id ,
223
- i. ident . name ,
224
- i. span ,
225
- header,
226
- generics,
227
- decl,
228
- body. as_deref ( ) ,
229
- ) ;
230
- }
231
192
AssocItemKind :: Fn ( ..) | AssocItemKind :: Const ( ..) => DefPathData :: ValueNs ( i. ident . name ) ,
232
193
AssocItemKind :: TyAlias ( ..) => DefPathData :: TypeNs ( i. ident . name ) ,
233
194
AssocItemKind :: Macro ( ..) => return self . visit_macro_invoc ( i. id ) ,
0 commit comments