fn expand(&mut self, expansion: Expansion) -> Expansion {
        let orig_expansion_data = self.cx.current_expansion.clone();
        self.cx.current_expansion.depth = 0;

        let (expansion, mut invocations) = self.collect_invocations(expansion);
        self.resolve_imports();
        invocations.reverse();

        let mut expansions = Vec::new();
        let mut undetermined_invocations = Vec::new();
        let (mut progress, mut force) = (false, !self.monotonic);
        loop {
            let invoc = if let Some(invoc) = invocations.pop() {
                invoc
            } else {
                self.resolve_imports();
                if undetermined_invocations.is_empty() { break }
                invocations = mem::replace(&mut undetermined_invocations, Vec::new());
                force = !mem::replace(&mut progress, false);
                continue
            };

            let scope =
                if self.monotonic { invoc.expansion_data.mark } else { orig_expansion_data.mark };
            let resolution = match invoc.kind {
                InvocationKind::Bang { ref mac, .. } => {
                    self.cx.resolver.resolve_macro(scope, &mac.node.path, force)
                }
                InvocationKind::Attr { ref attr, .. } => {
                    let ident = Ident::with_empty_ctxt(attr.name());
                    let path = ast::Path::from_ident(attr.span, ident);
                    self.cx.resolver.resolve_macro(scope, &path, force)
                }
                InvocationKind::Derive { ref attr, .. } => {
                    let titem = derive_attr_trait(self.cx, &attr).unwrap();
                    let tname = titem.name().expect("Expected derive macro name");
                    let ident = Ident::with_empty_ctxt(tname);
                    let path = ast::Path::from_ident(attr.span, ident);
                    self.cx.resolver.resolve_derive_macro(scope, &path, force)
                }
            };
            let ext = match resolution {
                Ok(ext) => Some(ext),
                Err(Determinacy::Determined) => None,
                Err(Determinacy::Undetermined) => {
                    undetermined_invocations.push(invoc);
                    continue
                }
            };

            progress = true;
            let ExpansionData { depth, mark, .. } = invoc.expansion_data;
            self.cx.current_expansion = invoc.expansion_data.clone();

            self.cx.current_expansion.mark = scope;
            let expansion = match ext {
                Some(ext) => self.expand_invoc(invoc, ext),
                None => invoc.expansion_kind.dummy(invoc.span()),
            };

            let (expansion, new_invocations) = self.collect_invocations(expansion);

            if expansions.len() < depth {
                expansions.push(Vec::new());
            }
            expansions[depth - 1].push((mark, expansion));
            if !self.cx.ecfg.single_step {
                invocations.extend(new_invocations.into_iter().rev());
            }
        }

        self.cx.current_expansion = orig_expansion_data;

        let mut placeholder_expander = PlaceholderExpander::new(self.cx, self.monotonic);
        while let Some(expansions) = expansions.pop() {
            for (mark, expansion) in expansions.into_iter().rev() {
                placeholder_expander.add(mark.as_placeholder_id(), expansion);
            }
        }

        expansion.fold_with(&mut placeholder_expander)
    }
// Fully expand all the invocations in `expansion`.
Fully expand all the invocations in `expansion`.
Fully expand all the invocations in ` expansion ` .
fn expand(&mut self, expansion: Expansion) -> Expansion {
        let orig_expansion_data = self.cx.current_expansion.clone();
        self.cx.current_expansion.depth = 0;
        let (expansion, mut invocations) = self.collect_invocations(expansion);
        self.resolve_imports();
        invocations.reverse();
        let mut expansions = Vec::new();
        let mut undetermined_invocations = Vec::new();
        let (mut progress, mut force) = (false, !self.monotonic);
        loop {
            let invoc = if let Some(invoc) = invocations.pop() {
                invoc
            } else {
                self.resolve_imports();
                if undetermined_invocations.is_empty() { break }
                invocations = mem::replace(&mut undetermined_invocations, Vec::new());
                force = !mem::replace(&mut progress, false);
                continue
            };
            let scope =
                if self.monotonic { invoc.expansion_data.mark } else { orig_expansion_data.mark };
            let resolution = match invoc.kind {
                InvocationKind::Bang { ref mac, .. } => {
                    self.cx.resolver.resolve_macro(scope, &mac.node.path, force)
                }
                InvocationKind::Attr { ref attr, .. } => {
                    let ident = Ident::with_empty_ctxt(attr.name());
                    let path = ast::Path::from_ident(attr.span, ident);
                    self.cx.resolver.resolve_macro(scope, &path, force)
                }
                InvocationKind::Derive { ref attr, .. } => {
                    let titem = derive_attr_trait(self.cx, &attr).unwrap();
                    let tname = titem.name().expect("Expected derive macro name");
                    let ident = Ident::with_empty_ctxt(tname);
                    let path = ast::Path::from_ident(attr.span, ident);
                    self.cx.resolver.resolve_derive_macro(scope, &path, force)
                }
            };
            let ext = match resolution {
                Ok(ext) => Some(ext),
                Err(Determinacy::Determined) => None,
                Err(Determinacy::Undetermined) => {
                    undetermined_invocations.push(invoc);
                    continue
                }
            };
            progress = true;
            let ExpansionData { depth, mark, .. } = invoc.expansion_data;
            self.cx.current_expansion = invoc.expansion_data.clone();
            self.cx.current_expansion.mark = scope;
            let expansion = match ext {
                Some(ext) => self.expand_invoc(invoc, ext),
                None => invoc.expansion_kind.dummy(invoc.span()),
            };
            let (expansion, new_invocations) = self.collect_invocations(expansion);
            if expansions.len() < depth {
                expansions.push(Vec::new());
            }
            expansions[depth - 1].push((mark, expansion));
            if !self.cx.ecfg.single_step {
                invocations.extend(new_invocations.into_iter().rev());
            }
        }
        self.cx.current_expansion = orig_expansion_data;
        let mut placeholder_expander = PlaceholderExpander::new(self.cx, self.monotonic);
        while let Some(expansions) = expansions.pop() {
            for (mark, expansion) in expansions.into_iter().rev() {
                placeholder_expander.add(mark.as_placeholder_id(), expansion);
            }
        }
        expansion.fold_with(&mut placeholder_expander)
    }
fn expand ( & mut self , expansion : Expansion ) -> Expansion { let orig_expansion_data = self . cx . current_expansion . clone ( ) ; self . cx . current_expansion . depth = 0 ; let ( expansion , mut invocations ) = self . collect_invocations ( expansion ) ; self . resolve_imports ( ) ; invocations . reverse ( ) ; let mut expansions = Vec :: new ( ) ; let mut undetermined_invocations = Vec :: new ( ) ; let ( mut progress , mut force ) = ( false , ! self . monotonic ) ; loop { let invoc = if let Some ( invoc ) = invocations . pop ( ) { invoc } else { self . resolve_imports ( ) ; if undetermined_invocations . is_empty ( ) { break } invocations = mem :: replace ( & mut undetermined_invocations , Vec :: new ( ) ) ; force = ! mem :: replace ( & mut progress , false ) ; continue } ; let scope = if self . monotonic { invoc . expansion_data . mark } else { orig_expansion_data . mark } ; let resolution = match invoc . kind { InvocationKind :: Bang { ref mac , .. } => { self . cx . resolver . resolve_macro ( scope , & mac . node . path , force ) } InvocationKind :: Attr { ref attr , .. } => { let ident = Ident :: with_empty_ctxt ( attr . name ( ) ) ; let path = ast :: Path :: from_ident ( attr . span , ident ) ; self . cx . resolver . resolve_macro ( scope , & path , force ) } InvocationKind :: Derive { ref attr , .. } => { let titem = derive_attr_trait ( self . cx , & attr ) . unwrap ( ) ; let tname = titem . name ( ) . expect ( " " ) ; let ident = Ident :: with_empty_ctxt ( tname ) ; let path = ast :: Path :: from_ident ( attr . span , ident ) ; self . cx . resolver . resolve_derive_macro ( scope , & path , force ) } } ; let ext = match resolution { Ok ( ext ) => Some ( ext ) , Err ( Determinacy :: Determined ) => None , Err ( Determinacy :: Undetermined ) => { undetermined_invocations . push ( invoc ) ; continue } } ; progress = true ; let ExpansionData { depth , mark , .. } = invoc . expansion_data ; self . cx . current_expansion = invoc . expansion_data . clone ( ) ; self . cx . current_expansion . mark = scope ; let expansion = match ext { Some ( ext ) => self . expand_invoc ( invoc , ext ) , None => invoc . expansion_kind . dummy ( invoc . span ( ) ) , } ; let ( expansion , new_invocations ) = self . collect_invocations ( expansion ) ; if expansions . len ( ) < depth { expansions . push ( Vec :: new ( ) ) ; } expansions [ depth - 1 ] . push ( ( mark , expansion ) ) ; if ! self . cx . ecfg . single_step { invocations . extend ( new_invocations . into_iter ( ) . rev ( ) ) ; } } self . cx . current_expansion = orig_expansion_data ; let mut placeholder_expander = PlaceholderExpander :: new ( self . cx , self . monotonic ) ; while let Some ( expansions ) = expansions . pop ( ) { for ( mark , expansion ) in expansions . into_iter ( ) . rev ( ) { placeholder_expander . add ( mark . as_placeholder_id ( ) , expansion ) ; } } expansion . fold_with ( & mut placeholder_expander ) }
Fully expand all the invocations in `expansion`.
Fully expand all the invocations in ` expansion ` .
&mut self
expansion
Expansion
&mut self
expansion
Expansion