Skip to content

Commit b2b643c

Browse files
committed
Inline and remove flat_map_annotatable.
Important: we know from the `parse_annotatable_with` call above the call site that only some of the `Annotatable` variants are possible. The remaining cases can be replaced with `unreachable!`.
1 parent 7aee2b3 commit b2b643c

File tree

1 file changed

+17
-39
lines changed

1 file changed

+17
-39
lines changed

compiler/rustc_builtin_macros/src/cfg_eval.rs

+17-39
Original file line numberDiff line numberDiff line change
@@ -43,44 +43,6 @@ pub(crate) fn cfg_eval(
4343

4444
struct CfgEval<'a>(StripUnconfigured<'a>);
4545

46-
fn flat_map_annotatable(vis: &mut impl MutVisitor, annotatable: Annotatable) -> Annotatable {
47-
match annotatable {
48-
Annotatable::Item(item) => Annotatable::Item(vis.flat_map_item(item).pop().unwrap()),
49-
Annotatable::AssocItem(item, ctxt) => {
50-
Annotatable::AssocItem(vis.flat_map_assoc_item(item, ctxt).pop().unwrap(), ctxt)
51-
}
52-
Annotatable::ForeignItem(item) => {
53-
Annotatable::ForeignItem(vis.flat_map_foreign_item(item).pop().unwrap())
54-
}
55-
Annotatable::Stmt(stmt) => {
56-
Annotatable::Stmt(P(vis.flat_map_stmt(stmt.into_inner()).pop().unwrap()))
57-
}
58-
Annotatable::Expr(mut expr) => {
59-
vis.visit_expr(&mut expr);
60-
Annotatable::Expr(expr)
61-
}
62-
Annotatable::Arm(arm) => Annotatable::Arm(vis.flat_map_arm(arm).pop().unwrap()),
63-
Annotatable::ExprField(field) => {
64-
Annotatable::ExprField(vis.flat_map_expr_field(field).pop().unwrap())
65-
}
66-
Annotatable::PatField(fp) => {
67-
Annotatable::PatField(vis.flat_map_pat_field(fp).pop().unwrap())
68-
}
69-
Annotatable::GenericParam(param) => {
70-
Annotatable::GenericParam(vis.flat_map_generic_param(param).pop().unwrap())
71-
}
72-
Annotatable::Param(param) => Annotatable::Param(vis.flat_map_param(param).pop().unwrap()),
73-
Annotatable::FieldDef(sf) => {
74-
Annotatable::FieldDef(vis.flat_map_field_def(sf).pop().unwrap())
75-
}
76-
Annotatable::Variant(v) => Annotatable::Variant(vis.flat_map_variant(v).pop().unwrap()),
77-
Annotatable::Crate(mut krate) => {
78-
vis.visit_crate(&mut krate);
79-
Annotatable::Crate(krate)
80-
}
81-
}
82-
}
83-
8446
fn has_cfg_or_cfg_attr(annotatable: &Annotatable) -> bool {
8547
struct CfgFinder;
8648

@@ -201,7 +163,23 @@ impl CfgEval<'_> {
201163

202164
// Now that we have our re-parsed `AttrTokenStream`, recursively configuring
203165
// our attribute target will correctly configure the tokens as well.
204-
flat_map_annotatable(&mut self, annotatable)
166+
match annotatable {
167+
Annotatable::Item(item) => Annotatable::Item(self.flat_map_item(item).pop().unwrap()),
168+
Annotatable::AssocItem(item, ctxt) => {
169+
Annotatable::AssocItem(self.flat_map_assoc_item(item, ctxt).pop().unwrap(), ctxt)
170+
}
171+
Annotatable::ForeignItem(item) => {
172+
Annotatable::ForeignItem(self.flat_map_foreign_item(item).pop().unwrap())
173+
}
174+
Annotatable::Stmt(stmt) => {
175+
Annotatable::Stmt(P(self.flat_map_stmt(stmt.into_inner()).pop().unwrap()))
176+
}
177+
Annotatable::Expr(mut expr) => {
178+
self.visit_expr(&mut expr);
179+
Annotatable::Expr(expr)
180+
}
181+
_ => unreachable!(),
182+
}
205183
}
206184
}
207185

0 commit comments

Comments
 (0)