Skip to content

Commit e7ee4d6

Browse files
committed
expand: Move fully_configure to config.rs
1 parent b49fbc9 commit e7ee4d6

File tree

2 files changed

+45
-42
lines changed

2 files changed

+45
-42
lines changed

compiler/rustc_expand/src/config.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Conditional compilation stripping.
22
3+
use crate::base::Annotatable;
4+
35
use rustc_ast::attr::HasAttrs;
46
use rustc_ast::mut_visit::*;
57
use rustc_ast::ptr::P;
@@ -496,6 +498,49 @@ impl<'a> StripUnconfigured<'a> {
496498
pub fn configure_fn_decl(&mut self, fn_decl: &mut ast::FnDecl) {
497499
fn_decl.inputs.flat_map_in_place(|arg| self.configure(arg));
498500
}
501+
502+
pub fn fully_configure(&mut self, item: Annotatable) -> Annotatable {
503+
// Since the item itself has already been configured by the InvocationCollector,
504+
// we know that fold result vector will contain exactly one element
505+
match item {
506+
Annotatable::Item(item) => Annotatable::Item(self.flat_map_item(item).pop().unwrap()),
507+
Annotatable::TraitItem(item) => {
508+
Annotatable::TraitItem(self.flat_map_trait_item(item).pop().unwrap())
509+
}
510+
Annotatable::ImplItem(item) => {
511+
Annotatable::ImplItem(self.flat_map_impl_item(item).pop().unwrap())
512+
}
513+
Annotatable::ForeignItem(item) => {
514+
Annotatable::ForeignItem(self.flat_map_foreign_item(item).pop().unwrap())
515+
}
516+
Annotatable::Stmt(stmt) => {
517+
Annotatable::Stmt(stmt.map(|stmt| self.flat_map_stmt(stmt).pop().unwrap()))
518+
}
519+
Annotatable::Expr(mut expr) => Annotatable::Expr({
520+
self.visit_expr(&mut expr);
521+
expr
522+
}),
523+
Annotatable::Arm(arm) => Annotatable::Arm(self.flat_map_arm(arm).pop().unwrap()),
524+
Annotatable::Field(field) => {
525+
Annotatable::Field(self.flat_map_field(field).pop().unwrap())
526+
}
527+
Annotatable::FieldPat(fp) => {
528+
Annotatable::FieldPat(self.flat_map_field_pattern(fp).pop().unwrap())
529+
}
530+
Annotatable::GenericParam(param) => {
531+
Annotatable::GenericParam(self.flat_map_generic_param(param).pop().unwrap())
532+
}
533+
Annotatable::Param(param) => {
534+
Annotatable::Param(self.flat_map_param(param).pop().unwrap())
535+
}
536+
Annotatable::StructField(sf) => {
537+
Annotatable::StructField(self.flat_map_struct_field(sf).pop().unwrap())
538+
}
539+
Annotatable::Variant(v) => {
540+
Annotatable::Variant(self.flat_map_variant(v).pop().unwrap())
541+
}
542+
}
543+
}
499544
}
500545

501546
impl<'a> MutVisitor for StripUnconfigured<'a> {

compiler/rustc_expand/src/expand.rs

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -609,48 +609,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
609609
(fragment, invocations)
610610
}
611611

612-
fn fully_configure(&mut self, item: Annotatable) -> Annotatable {
613-
let mut cfg = StripUnconfigured { sess: &self.cx.sess, features: self.cx.ecfg.features };
614-
// Since the item itself has already been configured by the InvocationCollector,
615-
// we know that fold result vector will contain exactly one element
616-
match item {
617-
Annotatable::Item(item) => Annotatable::Item(cfg.flat_map_item(item).pop().unwrap()),
618-
Annotatable::TraitItem(item) => {
619-
Annotatable::TraitItem(cfg.flat_map_trait_item(item).pop().unwrap())
620-
}
621-
Annotatable::ImplItem(item) => {
622-
Annotatable::ImplItem(cfg.flat_map_impl_item(item).pop().unwrap())
623-
}
624-
Annotatable::ForeignItem(item) => {
625-
Annotatable::ForeignItem(cfg.flat_map_foreign_item(item).pop().unwrap())
626-
}
627-
Annotatable::Stmt(stmt) => {
628-
Annotatable::Stmt(stmt.map(|stmt| cfg.flat_map_stmt(stmt).pop().unwrap()))
629-
}
630-
Annotatable::Expr(mut expr) => Annotatable::Expr({
631-
cfg.visit_expr(&mut expr);
632-
expr
633-
}),
634-
Annotatable::Arm(arm) => Annotatable::Arm(cfg.flat_map_arm(arm).pop().unwrap()),
635-
Annotatable::Field(field) => {
636-
Annotatable::Field(cfg.flat_map_field(field).pop().unwrap())
637-
}
638-
Annotatable::FieldPat(fp) => {
639-
Annotatable::FieldPat(cfg.flat_map_field_pattern(fp).pop().unwrap())
640-
}
641-
Annotatable::GenericParam(param) => {
642-
Annotatable::GenericParam(cfg.flat_map_generic_param(param).pop().unwrap())
643-
}
644-
Annotatable::Param(param) => {
645-
Annotatable::Param(cfg.flat_map_param(param).pop().unwrap())
646-
}
647-
Annotatable::StructField(sf) => {
648-
Annotatable::StructField(cfg.flat_map_struct_field(sf).pop().unwrap())
649-
}
650-
Annotatable::Variant(v) => Annotatable::Variant(cfg.flat_map_variant(v).pop().unwrap()),
651-
}
652-
}
653-
654612
fn error_recursion_limit_reached(&mut self) {
655613
let expn_data = self.cx.current_expansion.id.expn_data();
656614
let suggested_limit = self.cx.ecfg.recursion_limit * 2;

0 commit comments

Comments
 (0)