fn extract_labels(ctxt: &mut LifetimeContext, b: &hir::Block) {
    struct GatherLabels<'a> {
        sess: &'a Session,
        scope: Scope<'a>,
        labels_in_fn: &'a mut Vec<(ast::Name, Span)>,
    }

    let mut gather = GatherLabels {
        sess: ctxt.sess,
        scope: ctxt.scope,
        labels_in_fn: &mut ctxt.labels_in_fn,
    };
    gather.visit_block(b);
    return;

    impl<'v, 'a> Visitor<'v> for GatherLabels<'a> {
        fn visit_expr(&mut self, ex: &'v hir::Expr) {
            // do not recurse into closures defined in the block
            // since they are treated as separate fns from the POV of
            // labels_in_fn
            if let hir::ExprClosure(..) = ex.node {
                return
            }
            if let Some((label, label_span)) = expression_label(ex) {
                for &(prior, prior_span) in &self.labels_in_fn[..] {
                    // FIXME (#24278): non-hygienic comparison
                    if label == prior {
                        signal_shadowing_problem(self.sess,
                                                 label,
                                                 original_label(prior_span),
                                                 shadower_label(label_span));
                    }
                }

                check_if_label_shadows_lifetime(self.sess,
                                                self.scope,
                                                label,
                                                label_span);

                self.labels_in_fn.push((label, label_span));
            }
            intravisit::walk_expr(self, ex)
        }

        fn visit_item(&mut self, _: &hir::Item) {
            // do not recurse into items defined in the block
        }
    }

    fn expression_label(ex: &hir::Expr) -> Option<(ast::Name, Span)> {
        match ex.node {
            hir::ExprWhile(_, _, Some(label)) |
            hir::ExprLoop(_, Some(label)) => Some((label.node, label.span)),
            _ => None,
        }
    }

    fn check_if_label_shadows_lifetime<'a>(sess: &'a Session,
                                           mut scope: Scope<'a>,
                                           label: ast::Name,
                                           label_span: Span) {
        loop {
            match *scope {
                FnScope { s, .. } => { scope = s; }
                RootScope => { return; }

                EarlyScope(_, lifetimes, s) |
                LateScope(lifetimes, s) => {
                    for lifetime_def in lifetimes {
                        // FIXME (#24278): non-hygienic comparison
                        if label == lifetime_def.lifetime.name {
                            signal_shadowing_problem(
                                sess,
                                label,
                                original_lifetime(&lifetime_def.lifetime),
                                shadower_label(label_span));
                            return;
                        }
                    }
                    scope = s;
                }
            }
        }
    }
}
// Adds all labels in `b` to `ctxt.labels_in_fn`, signalling a warning
// if one of the label shadows a lifetime or another label.
Adds all labels in `b` to `ctxt.labels_in_fn`, signalling a warning
if one of the label shadows a lifetime or another label.
Adds all labels in ` b ` to ` ctxt . labels_in_fn ` signalling a warning if one of the label shadows a lifetime or another label .
fn extract_labels(ctxt: &mut LifetimeContext, b: &hir::Block) {
    struct GatherLabels<'a> {
        sess: &'a Session,
        scope: Scope<'a>,
        labels_in_fn: &'a mut Vec<(ast::Name, Span)>,
    }
    let mut gather = GatherLabels {
        sess: ctxt.sess,
        scope: ctxt.scope,
        labels_in_fn: &mut ctxt.labels_in_fn,
    };
    gather.visit_block(b);
    return;
    impl<'v, 'a> Visitor<'v> for GatherLabels<'a> {
        fn visit_expr(&mut self, ex: &'v hir::Expr) {
            // do not recurse into closures defined in the block
            // since they are treated as separate fns from the POV of
            // labels_in_fn
            if let hir::ExprClosure(..) = ex.node {
                return
            }
            if let Some((label, label_span)) = expression_label(ex) {
                for &(prior, prior_span) in &self.labels_in_fn[..] {
                    // FIXME (#24278): non-hygienic comparison
                    if label == prior {
                        signal_shadowing_problem(self.sess,
                                                 label,
                                                 original_label(prior_span),
                                                 shadower_label(label_span));
                    }
                }
                check_if_label_shadows_lifetime(self.sess,
                                                self.scope,
                                                label,
                                                label_span);
                self.labels_in_fn.push((label, label_span));
            }
            intravisit::walk_expr(self, ex)
        }
        fn visit_item(&mut self, _: &hir::Item) {
            // do not recurse into items defined in the block
        }
    }
    fn expression_label(ex: &hir::Expr) -> Option<(ast::Name, Span)> {
        match ex.node {
            hir::ExprWhile(_, _, Some(label)) |
            hir::ExprLoop(_, Some(label)) => Some((label.node, label.span)),
            _ => None,
        }
    }
    fn check_if_label_shadows_lifetime<'a>(sess: &'a Session,
                                           mut scope: Scope<'a>,
                                           label: ast::Name,
                                           label_span: Span) {
        loop {
            match *scope {
                FnScope { s, .. } => { scope = s; }
                RootScope => { return; }
                EarlyScope(_, lifetimes, s) |
                LateScope(lifetimes, s) => {
                    for lifetime_def in lifetimes {
                        // FIXME (#24278): non-hygienic comparison
                        if label == lifetime_def.lifetime.name {
                            signal_shadowing_problem(
                                sess,
                                label,
                                original_lifetime(&lifetime_def.lifetime),
                                shadower_label(label_span));
                            return;
                        }
                    }
                    scope = s;
                }
            }
        }
    }
}
fn extract_labels ( ctxt : & mut LifetimeContext , b : & hir :: Block ) { struct GatherLabels < ' a > { sess : & ' a Session , scope : Scope < ' a > , labels_in_fn : & ' a mut Vec < ( ast :: Name , Span ) > , } let mut gather = GatherLabels { sess : ctxt . sess , scope : ctxt . scope , labels_in_fn : & mut ctxt . labels_in_fn , } ; gather . visit_block ( b ) ; return ; impl < ' v , ' a > Visitor < ' v > for GatherLabels < ' a > { fn visit_expr ( & mut self , ex : & ' v hir :: Expr ) { // do not recurse into closures defined in the block // since they are treated as separate fns from the POV of // labels_in_fn if let hir :: ExprClosure ( .. ) = ex . node { return } if let Some ( ( label , label_span ) ) = expression_label ( ex ) { for & ( prior , prior_span ) in & self . labels_in_fn [ .. ] { // FIXME (#24278): non-hygienic comparison if label == prior { signal_shadowing_problem ( self . sess , label , original_label ( prior_span ) , shadower_label ( label_span ) ) ; } } check_if_label_shadows_lifetime ( self . sess , self . scope , label , label_span ) ; self . labels_in_fn . push ( ( label , label_span ) ) ; } intravisit :: walk_expr ( self , ex ) } fn visit_item ( & mut self , _ : & hir :: Item ) { // do not recurse into items defined in the block } } fn expression_label ( ex : & hir :: Expr ) -> Option < ( ast :: Name , Span ) > { match ex . node { hir :: ExprWhile ( _ , _ , Some ( label ) ) | hir :: ExprLoop ( _ , Some ( label ) ) => Some ( ( label . node , label . span ) ) , _ => None , } } fn check_if_label_shadows_lifetime < ' a > ( sess : & ' a Session , mut scope : Scope < ' a > , label : ast :: Name , label_span : Span ) { loop { match * scope { FnScope { s , .. } => { scope = s ; } RootScope => { return ; } EarlyScope ( _ , lifetimes , s ) | LateScope ( lifetimes , s ) => { for lifetime_def in lifetimes { // FIXME (#24278): non-hygienic comparison if label == lifetime_def . lifetime . name { signal_shadowing_problem ( sess , label , original_lifetime ( & lifetime_def . lifetime ) , shadower_label ( label_span ) ) ; return ; } } scope = s ; } } } } }
Adds all labels in `b` to `ctxt.labels_in_fn`, signalling a warning
if one of the label shadows a lifetime or another label.
Adds all labels in ` b ` to ` ctxt . labels_in_fn ` signalling a warning if one of the label shadows a lifetime or another label .
ctxt
&mut LifetimeContext
b
&hir::Block
ctxt
&mut LifetimeContext
b
&hir::Block