pub(crate) fn mark_use(&mut self, var: &str) {
        let mut levels = self.levels.borrow_mut();
        let iter = levels.iter_mut().rev();

        let mut closures = Vec::new();
        let mut found = false;

        for level in iter {
            match level {
                IndexScopeLevel::IndexScope(scope) => {
                    if scope.locals.get(var).is_some() {
                        found = true;
                        break;
                    }
                }
                IndexScopeLevel::IndexClosure(closure) => {
                    if closure.existing.contains(var) {
                        found = true;
                        break;
                    }

                    if closure.scope.locals.get(var).is_some() {
                        found = true;
                        break;
                    }

                    closures.push(closure);
                }
                // NB: cannot capture variables outside of functions.
                IndexScopeLevel::IndexFunction(scope) => {
                    found = scope.scope.locals.get(var).is_some();
                    break;
                }
            }
        }

        // mark all traversed closures to capture the given variable.
        if found {
            for closure in closures {
                closure
                    .captures
                    .push(CompileMetaCapture { ident: var.into() });

                let inserted = closure.existing.insert(var.into());

                // NB: should be checked above, because closures where it's
                // already captured are skipped.
                debug_assert!(inserted);
            }
        }
    }
/// Mark that the given variable is used.
Mark that the given variable is used.
Mark that the given variable is used .
pub(crate) fn mark_use(&mut self, var: &str) {
        let mut levels = self.levels.borrow_mut();
        let iter = levels.iter_mut().rev();
        let mut closures = Vec::new();
        let mut found = false;
        for level in iter {
            match level {
                IndexScopeLevel::IndexScope(scope) => {
                    if scope.locals.get(var).is_some() {
                        found = true;
                        break;
                    }
                }
                IndexScopeLevel::IndexClosure(closure) => {
                    if closure.existing.contains(var) {
                        found = true;
                        break;
                    }
                    if closure.scope.locals.get(var).is_some() {
                        found = true;
                        break;
                    }
                    closures.push(closure);
                }
                // NB: cannot capture variables outside of functions.
                IndexScopeLevel::IndexFunction(scope) => {
                    found = scope.scope.locals.get(var).is_some();
                    break;
                }
            }
        }
        // mark all traversed closures to capture the given variable.
        if found {
            for closure in closures {
                closure
                    .captures
                    .push(CompileMetaCapture { ident: var.into() });
                let inserted = closure.existing.insert(var.into());
                // NB: should be checked above, because closures where it's
                // already captured are skipped.
                debug_assert!(inserted);
            }
        }
    }
pub ( crate ) fn mark_use ( & mut self , var : & str ) { let mut levels = self . levels . borrow_mut ( ) ; let iter = levels . iter_mut ( ) . rev ( ) ; let mut closures = Vec :: new ( ) ; let mut found = false ; for level in iter { match level { IndexScopeLevel :: IndexScope ( scope ) => { if scope . locals . get ( var ) . is_some ( ) { found = true ; break ; } } IndexScopeLevel :: IndexClosure ( closure ) => { if closure . existing . contains ( var ) { found = true ; break ; } if closure . scope . locals . get ( var ) . is_some ( ) { found = true ; break ; } closures . push ( closure ) ; } // NB: cannot capture variables outside of functions. IndexScopeLevel :: IndexFunction ( scope ) => { found = scope . scope . locals . get ( var ) . is_some ( ) ; break ; } } } // mark all traversed closures to capture the given variable. if found { for closure in closures { closure . captures . push ( CompileMetaCapture { ident : var . into ( ) } ) ; let inserted = closure . existing . insert ( var . into ( ) ) ; // NB: should be checked above, because closures where it's // already captured are skipped. debug_assert ! ( inserted ) ; } } }
Mark that the given variable is used.
Mark that the given variable is used .
&mut self
var
&str
&mut self
var
&str