Skip to content

Commit b56aaa2

Browse files
committed
Use ControlFlow in HIR Visitor
1 parent 6290ae9 commit b56aaa2

File tree

114 files changed

+2554
-2206
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+2554
-2206
lines changed

Cargo.lock

+3-2
Original file line numberDiff line numberDiff line change
@@ -1324,9 +1324,9 @@ dependencies = [
13241324

13251325
[[package]]
13261326
name = "either"
1327-
version = "1.6.0"
1327+
version = "1.8.1"
13281328
source = "registry+https://github.com/rust-lang/crates.io-index"
1329-
checksum = "cd56b59865bce947ac5958779cfa508f6c3b9497cc762b7e24a12d11ccde2c4f"
1329+
checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
13301330

13311331
[[package]]
13321332
name = "elasticlunr-rs"
@@ -4735,6 +4735,7 @@ checksum = "8ba09476327c4b70ccefb6180f046ef588c26a24cf5d269a9feba316eb4f029f"
47354735
name = "rustc_trait_selection"
47364736
version = "0.0.0"
47374737
dependencies = [
4738+
"either",
47384739
"itertools",
47394740
"rustc_ast",
47404741
"rustc_attr",

compiler/rustc_ast_lowering/src/index.rs

+72-42
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_middle::span_bug;
1010
use rustc_session::Session;
1111
use rustc_span::source_map::SourceMap;
1212
use rustc_span::{Span, DUMMY_SP};
13+
use std::ops::ControlFlow::{self, Continue};
1314

1415
/// A visitor that walks over the HIR and collects `Node`s into a HIR map.
1516
pub(super) struct NodeCollector<'a, 'hir> {
@@ -110,39 +111,44 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
110111
/// deep walking so that we walk nested items in the context of
111112
/// their outer items.
112113
113-
fn visit_nested_item(&mut self, item: ItemId) {
114+
fn visit_nested_item(&mut self, item: ItemId) -> ControlFlow<!> {
114115
debug!("visit_nested_item: {:?}", item);
115116
self.insert_nested(item.owner_id.def_id);
117+
Continue(())
116118
}
117119

118-
fn visit_nested_trait_item(&mut self, item_id: TraitItemId) {
120+
fn visit_nested_trait_item(&mut self, item_id: TraitItemId) -> ControlFlow<!> {
119121
self.insert_nested(item_id.owner_id.def_id);
122+
Continue(())
120123
}
121124

122-
fn visit_nested_impl_item(&mut self, item_id: ImplItemId) {
125+
fn visit_nested_impl_item(&mut self, item_id: ImplItemId) -> ControlFlow<!> {
123126
self.insert_nested(item_id.owner_id.def_id);
127+
Continue(())
124128
}
125129

126-
fn visit_nested_foreign_item(&mut self, foreign_id: ForeignItemId) {
130+
fn visit_nested_foreign_item(&mut self, foreign_id: ForeignItemId) -> ControlFlow<!> {
127131
self.insert_nested(foreign_id.owner_id.def_id);
132+
Continue(())
128133
}
129134

130-
fn visit_nested_body(&mut self, id: BodyId) {
135+
fn visit_nested_body(&mut self, id: BodyId) -> ControlFlow<!> {
131136
debug_assert_eq!(id.hir_id.owner, self.owner);
132137
let body = self.bodies[&id.hir_id.local_id];
133-
self.visit_body(body);
138+
self.visit_body(body)
134139
}
135140

136-
fn visit_param(&mut self, param: &'hir Param<'hir>) {
141+
fn visit_param(&mut self, param: &'hir Param<'hir>) -> ControlFlow<!> {
137142
let node = Node::Param(param);
138143
self.insert(param.pat.span, param.hir_id, node);
139144
self.with_parent(param.hir_id, |this| {
140145
intravisit::walk_param(this, param);
141146
});
147+
Continue(())
142148
}
143149

144150
#[instrument(level = "debug", skip(self))]
145-
fn visit_item(&mut self, i: &'hir Item<'hir>) {
151+
fn visit_item(&mut self, i: &'hir Item<'hir>) -> ControlFlow<!> {
146152
debug_assert_eq!(i.owner_id, self.owner);
147153
self.with_parent(i.hir_id(), |this| {
148154
if let ItemKind::Struct(struct_def, _) = &i.kind {
@@ -153,147 +159,165 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
153159
}
154160
intravisit::walk_item(this, i);
155161
});
162+
Continue(())
156163
}
157164

158165
#[instrument(level = "debug", skip(self))]
159-
fn visit_foreign_item(&mut self, fi: &'hir ForeignItem<'hir>) {
166+
fn visit_foreign_item(&mut self, fi: &'hir ForeignItem<'hir>) -> ControlFlow<!> {
160167
debug_assert_eq!(fi.owner_id, self.owner);
161168
self.with_parent(fi.hir_id(), |this| {
162169
intravisit::walk_foreign_item(this, fi);
163170
});
171+
Continue(())
164172
}
165173

166-
fn visit_generic_param(&mut self, param: &'hir GenericParam<'hir>) {
174+
fn visit_generic_param(&mut self, param: &'hir GenericParam<'hir>) -> ControlFlow<!> {
167175
self.insert(param.span, param.hir_id, Node::GenericParam(param));
168-
intravisit::walk_generic_param(self, param);
176+
intravisit::walk_generic_param(self, param)
169177
}
170178

171-
fn visit_const_param_default(&mut self, param: HirId, ct: &'hir AnonConst) {
179+
fn visit_const_param_default(&mut self, param: HirId, ct: &'hir AnonConst) -> ControlFlow<!> {
172180
self.with_parent(param, |this| {
173181
intravisit::walk_const_param_default(this, ct);
174-
})
182+
});
183+
Continue(())
175184
}
176185

177186
#[instrument(level = "debug", skip(self))]
178-
fn visit_trait_item(&mut self, ti: &'hir TraitItem<'hir>) {
187+
fn visit_trait_item(&mut self, ti: &'hir TraitItem<'hir>) -> ControlFlow<!> {
179188
debug_assert_eq!(ti.owner_id, self.owner);
180189
self.with_parent(ti.hir_id(), |this| {
181190
intravisit::walk_trait_item(this, ti);
182191
});
192+
Continue(())
183193
}
184194

185195
#[instrument(level = "debug", skip(self))]
186-
fn visit_impl_item(&mut self, ii: &'hir ImplItem<'hir>) {
196+
fn visit_impl_item(&mut self, ii: &'hir ImplItem<'hir>) -> ControlFlow<!> {
187197
debug_assert_eq!(ii.owner_id, self.owner);
188198
self.with_parent(ii.hir_id(), |this| {
189199
intravisit::walk_impl_item(this, ii);
190200
});
201+
Continue(())
191202
}
192203

193-
fn visit_pat(&mut self, pat: &'hir Pat<'hir>) {
204+
fn visit_pat(&mut self, pat: &'hir Pat<'hir>) -> ControlFlow<!> {
194205
self.insert(pat.span, pat.hir_id, Node::Pat(pat));
195206

196207
self.with_parent(pat.hir_id, |this| {
197208
intravisit::walk_pat(this, pat);
198209
});
210+
Continue(())
199211
}
200212

201-
fn visit_pat_field(&mut self, field: &'hir PatField<'hir>) {
213+
fn visit_pat_field(&mut self, field: &'hir PatField<'hir>) -> ControlFlow<!> {
202214
self.insert(field.span, field.hir_id, Node::PatField(field));
203215
self.with_parent(field.hir_id, |this| {
204216
intravisit::walk_pat_field(this, field);
205217
});
218+
Continue(())
206219
}
207220

208-
fn visit_arm(&mut self, arm: &'hir Arm<'hir>) {
221+
fn visit_arm(&mut self, arm: &'hir Arm<'hir>) -> ControlFlow<!> {
209222
let node = Node::Arm(arm);
210223

211224
self.insert(arm.span, arm.hir_id, node);
212225

213226
self.with_parent(arm.hir_id, |this| {
214227
intravisit::walk_arm(this, arm);
215228
});
229+
Continue(())
216230
}
217231

218-
fn visit_anon_const(&mut self, constant: &'hir AnonConst) {
232+
fn visit_anon_const(&mut self, constant: &'hir AnonConst) -> ControlFlow<!> {
219233
self.insert(DUMMY_SP, constant.hir_id, Node::AnonConst(constant));
220234

221235
self.with_parent(constant.hir_id, |this| {
222236
intravisit::walk_anon_const(this, constant);
223237
});
238+
Continue(())
224239
}
225240

226-
fn visit_expr(&mut self, expr: &'hir Expr<'hir>) {
241+
fn visit_expr(&mut self, expr: &'hir Expr<'hir>) -> ControlFlow<!> {
227242
self.insert(expr.span, expr.hir_id, Node::Expr(expr));
228243

229244
self.with_parent(expr.hir_id, |this| {
230245
intravisit::walk_expr(this, expr);
231246
});
247+
Continue(())
232248
}
233249

234-
fn visit_expr_field(&mut self, field: &'hir ExprField<'hir>) {
250+
fn visit_expr_field(&mut self, field: &'hir ExprField<'hir>) -> ControlFlow<!> {
235251
self.insert(field.span, field.hir_id, Node::ExprField(field));
236252
self.with_parent(field.hir_id, |this| {
237253
intravisit::walk_expr_field(this, field);
238254
});
255+
Continue(())
239256
}
240257

241-
fn visit_stmt(&mut self, stmt: &'hir Stmt<'hir>) {
258+
fn visit_stmt(&mut self, stmt: &'hir Stmt<'hir>) -> ControlFlow<!> {
242259
self.insert(stmt.span, stmt.hir_id, Node::Stmt(stmt));
243260

244261
self.with_parent(stmt.hir_id, |this| {
245262
intravisit::walk_stmt(this, stmt);
246263
});
264+
Continue(())
247265
}
248266

249-
fn visit_path_segment(&mut self, path_segment: &'hir PathSegment<'hir>) {
267+
fn visit_path_segment(&mut self, path_segment: &'hir PathSegment<'hir>) -> ControlFlow<!> {
250268
self.insert(path_segment.ident.span, path_segment.hir_id, Node::PathSegment(path_segment));
251-
intravisit::walk_path_segment(self, path_segment);
269+
intravisit::walk_path_segment(self, path_segment)
252270
}
253271

254-
fn visit_ty(&mut self, ty: &'hir Ty<'hir>) {
272+
fn visit_ty(&mut self, ty: &'hir Ty<'hir>) -> ControlFlow<!> {
255273
self.insert(ty.span, ty.hir_id, Node::Ty(ty));
256274

257275
self.with_parent(ty.hir_id, |this| {
258276
intravisit::walk_ty(this, ty);
259277
});
278+
Continue(())
260279
}
261280

262-
fn visit_infer(&mut self, inf: &'hir InferArg) {
281+
fn visit_infer(&mut self, inf: &'hir InferArg) -> ControlFlow<!> {
263282
self.insert(inf.span, inf.hir_id, Node::Infer(inf));
264283

265284
self.with_parent(inf.hir_id, |this| {
266285
intravisit::walk_inf(this, inf);
267286
});
287+
Continue(())
268288
}
269289

270-
fn visit_trait_ref(&mut self, tr: &'hir TraitRef<'hir>) {
290+
fn visit_trait_ref(&mut self, tr: &'hir TraitRef<'hir>) -> ControlFlow<!> {
271291
self.insert(tr.path.span, tr.hir_ref_id, Node::TraitRef(tr));
272292

273293
self.with_parent(tr.hir_ref_id, |this| {
274294
intravisit::walk_trait_ref(this, tr);
275295
});
296+
Continue(())
276297
}
277298

278-
fn visit_block(&mut self, block: &'hir Block<'hir>) {
299+
fn visit_block(&mut self, block: &'hir Block<'hir>) -> ControlFlow<!> {
279300
self.insert(block.span, block.hir_id, Node::Block(block));
280301
self.with_parent(block.hir_id, |this| {
281302
intravisit::walk_block(this, block);
282303
});
304+
Continue(())
283305
}
284306

285-
fn visit_local(&mut self, l: &'hir Local<'hir>) {
307+
fn visit_local(&mut self, l: &'hir Local<'hir>) -> ControlFlow<!> {
286308
self.insert(l.span, l.hir_id, Node::Local(l));
287309
self.with_parent(l.hir_id, |this| {
288310
intravisit::walk_local(this, l);
289-
})
311+
});
312+
Continue(())
290313
}
291314

292-
fn visit_lifetime(&mut self, lifetime: &'hir Lifetime) {
315+
fn visit_lifetime(&mut self, lifetime: &'hir Lifetime) -> ControlFlow<!> {
293316
self.insert(lifetime.ident.span, lifetime.hir_id, Node::Lifetime(lifetime));
317+
Continue(())
294318
}
295319

296-
fn visit_variant(&mut self, v: &'hir Variant<'hir>) {
320+
fn visit_variant(&mut self, v: &'hir Variant<'hir>) -> ControlFlow<!> {
297321
self.insert(v.span, v.hir_id, Node::Variant(v));
298322
self.with_parent(v.hir_id, |this| {
299323
// Register the constructor of this variant.
@@ -302,43 +326,49 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
302326
}
303327
intravisit::walk_variant(this, v);
304328
});
329+
Continue(())
305330
}
306331

307-
fn visit_field_def(&mut self, field: &'hir FieldDef<'hir>) {
332+
fn visit_field_def(&mut self, field: &'hir FieldDef<'hir>) -> ControlFlow<!> {
308333
self.insert(field.span, field.hir_id, Node::Field(field));
309334
self.with_parent(field.hir_id, |this| {
310335
intravisit::walk_field_def(this, field);
311336
});
337+
Continue(())
312338
}
313339

314-
fn visit_assoc_type_binding(&mut self, type_binding: &'hir TypeBinding<'hir>) {
340+
fn visit_assoc_type_binding(
341+
&mut self,
342+
type_binding: &'hir TypeBinding<'hir>,
343+
) -> ControlFlow<!> {
315344
self.insert(type_binding.span, type_binding.hir_id, Node::TypeBinding(type_binding));
316345
self.with_parent(type_binding.hir_id, |this| {
317-
intravisit::walk_assoc_type_binding(this, type_binding)
318-
})
346+
intravisit::walk_assoc_type_binding(this, type_binding);
347+
});
348+
Continue(())
319349
}
320350

321-
fn visit_trait_item_ref(&mut self, ii: &'hir TraitItemRef) {
351+
fn visit_trait_item_ref(&mut self, ii: &'hir TraitItemRef) -> ControlFlow<!> {
322352
// Do not visit the duplicate information in TraitItemRef. We want to
323353
// map the actual nodes, not the duplicate ones in the *Ref.
324354
let TraitItemRef { id, ident: _, kind: _, span: _ } = *ii;
325355

326-
self.visit_nested_trait_item(id);
356+
self.visit_nested_trait_item(id)
327357
}
328358

329-
fn visit_impl_item_ref(&mut self, ii: &'hir ImplItemRef) {
359+
fn visit_impl_item_ref(&mut self, ii: &'hir ImplItemRef) -> ControlFlow<!> {
330360
// Do not visit the duplicate information in ImplItemRef. We want to
331361
// map the actual nodes, not the duplicate ones in the *Ref.
332362
let ImplItemRef { id, ident: _, kind: _, span: _, trait_item_def_id: _ } = *ii;
333363

334-
self.visit_nested_impl_item(id);
364+
self.visit_nested_impl_item(id)
335365
}
336366

337-
fn visit_foreign_item_ref(&mut self, fi: &'hir ForeignItemRef) {
367+
fn visit_foreign_item_ref(&mut self, fi: &'hir ForeignItemRef) -> ControlFlow<!> {
338368
// Do not visit the duplicate information in ForeignItemRef. We want to
339369
// map the actual nodes, not the duplicate ones in the *Ref.
340370
let ForeignItemRef { id, ident: _, span: _ } = *fi;
341371

342-
self.visit_nested_foreign_item(id);
372+
self.visit_nested_foreign_item(id)
343373
}
344374
}

0 commit comments

Comments
 (0)