11
11
//! nested within a uniquely determined `FnLike`), and users can ask
12
12
//! for the `Code` associated with a particular NodeId.
13
13
14
- use crate :: hir:: intravisit :: FnKind ;
15
- use crate :: hir:: map ;
16
- use rustc_hir as ast ;
14
+ use crate :: hir:: map :: Map ;
15
+ use rustc_hir as hir;
16
+ use rustc_hir:: intravisit :: FnKind ;
17
17
use rustc_hir:: { Expr , FnDecl , Node } ;
18
18
use rustc_span:: Span ;
19
19
use syntax:: ast:: { Attribute , Ident } ;
@@ -39,37 +39,37 @@ trait MaybeFnLike {
39
39
fn is_fn_like ( & self ) -> bool ;
40
40
}
41
41
42
- impl MaybeFnLike for ast :: Item < ' _ > {
42
+ impl MaybeFnLike for hir :: Item < ' _ > {
43
43
fn is_fn_like ( & self ) -> bool {
44
44
match self . kind {
45
- ast :: ItemKind :: Fn ( ..) => true ,
45
+ hir :: ItemKind :: Fn ( ..) => true ,
46
46
_ => false ,
47
47
}
48
48
}
49
49
}
50
50
51
- impl MaybeFnLike for ast :: ImplItem < ' _ > {
51
+ impl MaybeFnLike for hir :: ImplItem < ' _ > {
52
52
fn is_fn_like ( & self ) -> bool {
53
53
match self . kind {
54
- ast :: ImplItemKind :: Method ( ..) => true ,
54
+ hir :: ImplItemKind :: Method ( ..) => true ,
55
55
_ => false ,
56
56
}
57
57
}
58
58
}
59
59
60
- impl MaybeFnLike for ast :: TraitItem < ' _ > {
60
+ impl MaybeFnLike for hir :: TraitItem < ' _ > {
61
61
fn is_fn_like ( & self ) -> bool {
62
62
match self . kind {
63
- ast :: TraitItemKind :: Method ( _, ast :: TraitMethod :: Provided ( _) ) => true ,
63
+ hir :: TraitItemKind :: Method ( _, hir :: TraitMethod :: Provided ( _) ) => true ,
64
64
_ => false ,
65
65
}
66
66
}
67
67
}
68
68
69
- impl MaybeFnLike for ast :: Expr < ' _ > {
69
+ impl MaybeFnLike for hir :: Expr < ' _ > {
70
70
fn is_fn_like ( & self ) -> bool {
71
71
match self . kind {
72
- ast :: ExprKind :: Closure ( ..) => true ,
72
+ hir :: ExprKind :: Closure ( ..) => true ,
73
73
_ => false ,
74
74
}
75
75
}
@@ -85,21 +85,21 @@ pub enum Code<'a> {
85
85
}
86
86
87
87
impl < ' a > Code < ' a > {
88
- pub fn id ( & self ) -> ast :: HirId {
88
+ pub fn id ( & self ) -> hir :: HirId {
89
89
match * self {
90
90
Code :: FnLike ( node) => node. id ( ) ,
91
91
Code :: Expr ( block) => block. hir_id ,
92
92
}
93
93
}
94
94
95
95
/// Attempts to construct a Code from presumed FnLike or Expr node input.
96
- pub fn from_node ( map : & map :: Map < ' a > , id : ast :: HirId ) -> Option < Code < ' a > > {
96
+ pub fn from_node ( map : & Map < ' a > , id : hir :: HirId ) -> Option < Code < ' a > > {
97
97
match map. get ( id) {
98
- map :: Node :: Block ( _) => {
98
+ Node :: Block ( _) => {
99
99
// Use the parent, hopefully an expression node.
100
100
Code :: from_node ( map, map. get_parent_node ( id) )
101
101
}
102
- map :: Node :: Expr ( expr) => Some ( Code :: Expr ( expr) ) ,
102
+ Node :: Expr ( expr) => Some ( Code :: Expr ( expr) ) ,
103
103
node => FnLikeNode :: from_node ( node) . map ( Code :: FnLike ) ,
104
104
}
105
105
}
@@ -109,12 +109,12 @@ impl<'a> Code<'a> {
109
109
/// use when implementing FnLikeNode operations.
110
110
struct ItemFnParts < ' a > {
111
111
ident : Ident ,
112
- decl : & ' a ast :: FnDecl < ' a > ,
113
- header : ast :: FnHeader ,
114
- vis : & ' a ast :: Visibility < ' a > ,
115
- generics : & ' a ast :: Generics < ' a > ,
116
- body : ast :: BodyId ,
117
- id : ast :: HirId ,
112
+ decl : & ' a hir :: FnDecl < ' a > ,
113
+ header : hir :: FnHeader ,
114
+ vis : & ' a hir :: Visibility < ' a > ,
115
+ generics : & ' a hir :: Generics < ' a > ,
116
+ body : hir :: BodyId ,
117
+ id : hir :: HirId ,
118
118
span : Span ,
119
119
attrs : & ' a [ Attribute ] ,
120
120
}
@@ -123,17 +123,17 @@ struct ItemFnParts<'a> {
123
123
/// for use when implementing FnLikeNode operations.
124
124
struct ClosureParts < ' a > {
125
125
decl : & ' a FnDecl < ' a > ,
126
- body : ast :: BodyId ,
127
- id : ast :: HirId ,
126
+ body : hir :: BodyId ,
127
+ id : hir :: HirId ,
128
128
span : Span ,
129
129
attrs : & ' a [ Attribute ] ,
130
130
}
131
131
132
132
impl < ' a > ClosureParts < ' a > {
133
133
fn new (
134
134
d : & ' a FnDecl < ' a > ,
135
- b : ast :: BodyId ,
136
- id : ast :: HirId ,
135
+ b : hir :: BodyId ,
136
+ id : hir :: HirId ,
137
137
s : Span ,
138
138
attrs : & ' a [ Attribute ] ,
139
139
) -> Self {
@@ -145,65 +145,65 @@ impl<'a> FnLikeNode<'a> {
145
145
/// Attempts to construct a FnLikeNode from presumed FnLike node input.
146
146
pub fn from_node ( node : Node < ' _ > ) -> Option < FnLikeNode < ' _ > > {
147
147
let fn_like = match node {
148
- map :: Node :: Item ( item) => item. is_fn_like ( ) ,
149
- map :: Node :: TraitItem ( tm) => tm. is_fn_like ( ) ,
150
- map :: Node :: ImplItem ( it) => it. is_fn_like ( ) ,
151
- map :: Node :: Expr ( e) => e. is_fn_like ( ) ,
148
+ Node :: Item ( item) => item. is_fn_like ( ) ,
149
+ Node :: TraitItem ( tm) => tm. is_fn_like ( ) ,
150
+ Node :: ImplItem ( it) => it. is_fn_like ( ) ,
151
+ Node :: Expr ( e) => e. is_fn_like ( ) ,
152
152
_ => false ,
153
153
} ;
154
154
fn_like. then_some ( FnLikeNode { node } )
155
155
}
156
156
157
- pub fn body ( self ) -> ast :: BodyId {
157
+ pub fn body ( self ) -> hir :: BodyId {
158
158
self . handle (
159
159
|i : ItemFnParts < ' a > | i. body ,
160
- |_, _, _: & ' a ast :: FnSig < ' a > , _, body : ast :: BodyId , _, _| body,
160
+ |_, _, _: & ' a hir :: FnSig < ' a > , _, body : hir :: BodyId , _, _| body,
161
161
|c : ClosureParts < ' a > | c. body ,
162
162
)
163
163
}
164
164
165
165
pub fn decl ( self ) -> & ' a FnDecl < ' a > {
166
166
self . handle (
167
167
|i : ItemFnParts < ' a > | & * i. decl ,
168
- |_, _, sig : & ' a ast :: FnSig < ' a > , _, _, _, _| & sig. decl ,
168
+ |_, _, sig : & ' a hir :: FnSig < ' a > , _, _, _, _| & sig. decl ,
169
169
|c : ClosureParts < ' a > | c. decl ,
170
170
)
171
171
}
172
172
173
173
pub fn span ( self ) -> Span {
174
174
self . handle (
175
175
|i : ItemFnParts < ' _ > | i. span ,
176
- |_, _, _: & ' a ast :: FnSig < ' a > , _, _, span, _| span,
176
+ |_, _, _: & ' a hir :: FnSig < ' a > , _, _, span, _| span,
177
177
|c : ClosureParts < ' _ > | c. span ,
178
178
)
179
179
}
180
180
181
- pub fn id ( self ) -> ast :: HirId {
181
+ pub fn id ( self ) -> hir :: HirId {
182
182
self . handle (
183
183
|i : ItemFnParts < ' _ > | i. id ,
184
- |id, _, _: & ' a ast :: FnSig < ' a > , _, _, _, _| id,
184
+ |id, _, _: & ' a hir :: FnSig < ' a > , _, _, _, _| id,
185
185
|c : ClosureParts < ' _ > | c. id ,
186
186
)
187
187
}
188
188
189
- pub fn constness ( self ) -> ast :: Constness {
190
- self . kind ( ) . header ( ) . map_or ( ast :: Constness :: NotConst , |header| header. constness )
189
+ pub fn constness ( self ) -> hir :: Constness {
190
+ self . kind ( ) . header ( ) . map_or ( hir :: Constness :: NotConst , |header| header. constness )
191
191
}
192
192
193
- pub fn asyncness ( self ) -> ast :: IsAsync {
194
- self . kind ( ) . header ( ) . map_or ( ast :: IsAsync :: NotAsync , |header| header. asyncness )
193
+ pub fn asyncness ( self ) -> hir :: IsAsync {
194
+ self . kind ( ) . header ( ) . map_or ( hir :: IsAsync :: NotAsync , |header| header. asyncness )
195
195
}
196
196
197
- pub fn unsafety ( self ) -> ast :: Unsafety {
198
- self . kind ( ) . header ( ) . map_or ( ast :: Unsafety :: Normal , |header| header. unsafety )
197
+ pub fn unsafety ( self ) -> hir :: Unsafety {
198
+ self . kind ( ) . header ( ) . map_or ( hir :: Unsafety :: Normal , |header| header. unsafety )
199
199
}
200
200
201
201
pub fn kind ( self ) -> FnKind < ' a > {
202
202
let item = |p : ItemFnParts < ' a > | -> FnKind < ' a > {
203
203
FnKind :: ItemFn ( p. ident , p. generics , p. header , p. vis , p. attrs )
204
204
} ;
205
205
let closure = |c : ClosureParts < ' a > | FnKind :: Closure ( c. attrs ) ;
206
- let method = |_, ident : Ident , sig : & ' a ast :: FnSig < ' a > , vis, _, _, attrs| {
206
+ let method = |_, ident : Ident , sig : & ' a hir :: FnSig < ' a > , vis, _, _, attrs| {
207
207
FnKind :: Method ( ident, sig, vis, attrs)
208
208
} ;
209
209
self . handle ( item, method, closure)
@@ -213,19 +213,19 @@ impl<'a> FnLikeNode<'a> {
213
213
where
214
214
I : FnOnce ( ItemFnParts < ' a > ) -> A ,
215
215
M : FnOnce (
216
- ast :: HirId ,
216
+ hir :: HirId ,
217
217
Ident ,
218
- & ' a ast :: FnSig < ' a > ,
219
- Option < & ' a ast :: Visibility < ' a > > ,
220
- ast :: BodyId ,
218
+ & ' a hir :: FnSig < ' a > ,
219
+ Option < & ' a hir :: Visibility < ' a > > ,
220
+ hir :: BodyId ,
221
221
Span ,
222
222
& ' a [ Attribute ] ,
223
223
) -> A ,
224
224
C : FnOnce ( ClosureParts < ' a > ) -> A ,
225
225
{
226
226
match self . node {
227
- map :: Node :: Item ( i) => match i. kind {
228
- ast :: ItemKind :: Fn ( ref sig, ref generics, block) => item_fn ( ItemFnParts {
227
+ Node :: Item ( i) => match i. kind {
228
+ hir :: ItemKind :: Fn ( ref sig, ref generics, block) => item_fn ( ItemFnParts {
229
229
id : i. hir_id ,
230
230
ident : i. ident ,
231
231
decl : & sig. decl ,
@@ -238,20 +238,20 @@ impl<'a> FnLikeNode<'a> {
238
238
} ) ,
239
239
_ => bug ! ( "item FnLikeNode that is not fn-like" ) ,
240
240
} ,
241
- map :: Node :: TraitItem ( ti) => match ti. kind {
242
- ast :: TraitItemKind :: Method ( ref sig, ast :: TraitMethod :: Provided ( body) ) => {
241
+ Node :: TraitItem ( ti) => match ti. kind {
242
+ hir :: TraitItemKind :: Method ( ref sig, hir :: TraitMethod :: Provided ( body) ) => {
243
243
method ( ti. hir_id , ti. ident , sig, None , body, ti. span , & ti. attrs )
244
244
}
245
245
_ => bug ! ( "trait method FnLikeNode that is not fn-like" ) ,
246
246
} ,
247
- map :: Node :: ImplItem ( ii) => match ii. kind {
248
- ast :: ImplItemKind :: Method ( ref sig, body) => {
247
+ Node :: ImplItem ( ii) => match ii. kind {
248
+ hir :: ImplItemKind :: Method ( ref sig, body) => {
249
249
method ( ii. hir_id , ii. ident , sig, Some ( & ii. vis ) , body, ii. span , & ii. attrs )
250
250
}
251
251
_ => bug ! ( "impl method FnLikeNode that is not fn-like" ) ,
252
252
} ,
253
- map :: Node :: Expr ( e) => match e. kind {
254
- ast :: ExprKind :: Closure ( _, ref decl, block, _fn_decl_span, _gen) => {
253
+ Node :: Expr ( e) => match e. kind {
254
+ hir :: ExprKind :: Closure ( _, ref decl, block, _fn_decl_span, _gen) => {
255
255
closure ( ClosureParts :: new ( & decl, block, e. hir_id , e. span , & e. attrs ) )
256
256
}
257
257
_ => bug ! ( "expr FnLikeNode that is not fn-like" ) ,
0 commit comments