fn check_consistent_bindings(&mut self, pats: &[P<Pat>]) -> Vec<BindingMap> {
        let mut missing_vars = FxHashMap::default();
        let mut inconsistent_vars = FxHashMap::default();

        // 1) Compute the binding maps of all arms.
        let maps = pats.iter().map(|pat| self.binding_mode_map(pat)).collect::<Vec<_>>();

        // 2) Record any missing bindings or binding mode inconsistencies.
        for (map_outer, pat_outer) in pats.iter().enumerate().map(|(idx, pat)| (&maps[idx], pat)) {
            // Check against all arms except for the same pattern which is always self-consistent.
            let inners = pats
                .iter()
                .enumerate()
                .filter(|(_, pat)| pat.id != pat_outer.id)
                .flat_map(|(idx, _)| maps[idx].iter())
                .map(|(key, binding)| (key.name, map_outer.get(&key), binding));

            for (name, info, &binding_inner) in inners {
                match info {
                    None => {
                        // The inner binding is missing in the outer.
                        let binding_error =
                            missing_vars.entry(name).or_insert_with(|| BindingError {
                                name,
                                origin: BTreeSet::new(),
                                target: BTreeSet::new(),
                                could_be_path: name.as_str().starts_with(char::is_uppercase),
                            });
                        binding_error.origin.insert(binding_inner.span);
                        binding_error.target.insert(pat_outer.span);
                    }
                    Some(binding_outer) => {
                        if binding_outer.binding_mode != binding_inner.binding_mode {
                            // The binding modes in the outer and inner bindings differ.
                            inconsistent_vars
                                .entry(name)
                                .or_insert((binding_inner.span, binding_outer.span));
                        }
                    }
                }
            }
        }

        // 3) Report all missing variables we found.
        let mut missing_vars = missing_vars.iter_mut().collect::<Vec<_>>();
        missing_vars.sort_by_key(|(sym, _err)| sym.as_str());

        for (name, mut v) in missing_vars {
            if inconsistent_vars.contains_key(name) {
                v.could_be_path = false;
            }
            self.r.report_error(
                *v.origin.iter().next().unwrap(),
                ResolutionError::VariableNotBoundInPattern(v),
            );
        }

        // 4) Report all inconsistencies in binding modes we found.
        let mut inconsistent_vars = inconsistent_vars.iter().collect::<Vec<_>>();
        inconsistent_vars.sort();
        for (name, v) in inconsistent_vars {
            self.r.report_error(v.0, ResolutionError::VariableBoundWithDifferentMode(*name, v.1));
        }

        // 5) Finally bubble up all the binding maps.
        maps
    }
/// Checks that all of the arms in an or-pattern have exactly the
/// same set of bindings, with the same binding modes for each.
Checks that all of the arms in an or-pattern have exactly the
same set of bindings, with the same binding modes for each.
Checks that all of the arms in an or - pattern have exactly the same set of bindings with the same binding modes for each .
fn check_consistent_bindings(&mut self, pats: &[P<Pat>]) -> Vec<BindingMap> {
        let mut missing_vars = FxHashMap::default();
        let mut inconsistent_vars = FxHashMap::default();
        // 1) Compute the binding maps of all arms.
        let maps = pats.iter().map(|pat| self.binding_mode_map(pat)).collect::<Vec<_>>();
        // 2) Record any missing bindings or binding mode inconsistencies.
        for (map_outer, pat_outer) in pats.iter().enumerate().map(|(idx, pat)| (&maps[idx], pat)) {
            // Check against all arms except for the same pattern which is always self-consistent.
            let inners = pats
                .iter()
                .enumerate()
                .filter(|(_, pat)| pat.id != pat_outer.id)
                .flat_map(|(idx, _)| maps[idx].iter())
                .map(|(key, binding)| (key.name, map_outer.get(&key), binding));
            for (name, info, &binding_inner) in inners {
                match info {
                    None => {
                        // The inner binding is missing in the outer.
                        let binding_error =
                            missing_vars.entry(name).or_insert_with(|| BindingError {
                                name,
                                origin: BTreeSet::new(),
                                target: BTreeSet::new(),
                                could_be_path: name.as_str().starts_with(char::is_uppercase),
                            });
                        binding_error.origin.insert(binding_inner.span);
                        binding_error.target.insert(pat_outer.span);
                    }
                    Some(binding_outer) => {
                        if binding_outer.binding_mode != binding_inner.binding_mode {
                            // The binding modes in the outer and inner bindings differ.
                            inconsistent_vars
                                .entry(name)
                                .or_insert((binding_inner.span, binding_outer.span));
                        }
                    }
                }
            }
        }
        // 3) Report all missing variables we found.
        let mut missing_vars = missing_vars.iter_mut().collect::<Vec<_>>();
        missing_vars.sort_by_key(|(sym, _err)| sym.as_str());
        for (name, mut v) in missing_vars {
            if inconsistent_vars.contains_key(name) {
                v.could_be_path = false;
            }
            self.r.report_error(
                *v.origin.iter().next().unwrap(),
                ResolutionError::VariableNotBoundInPattern(v),
            );
        }
        // 4) Report all inconsistencies in binding modes we found.
        let mut inconsistent_vars = inconsistent_vars.iter().collect::<Vec<_>>();
        inconsistent_vars.sort();
        for (name, v) in inconsistent_vars {
            self.r.report_error(v.0, ResolutionError::VariableBoundWithDifferentMode(*name, v.1));
        }
        // 5) Finally bubble up all the binding maps.
        maps
    }
fn check_consistent_bindings ( & mut self , pats : & [ P < Pat > ] ) -> Vec < BindingMap > { let mut missing_vars = FxHashMap :: default ( ) ; let mut inconsistent_vars = FxHashMap :: default ( ) ; // 1) Compute the binding maps of all arms. let maps = pats . iter ( ) . map ( | pat | self . binding_mode_map ( pat ) ) . collect :: < Vec < _ > > ( ) ; // 2) Record any missing bindings or binding mode inconsistencies. for ( map_outer , pat_outer ) in pats . iter ( ) . enumerate ( ) . map ( | ( idx , pat ) | ( & maps [ idx ] , pat ) ) { // Check against all arms except for the same pattern which is always self-consistent. let inners = pats . iter ( ) . enumerate ( ) . filter ( | ( _ , pat ) | pat . id != pat_outer . id ) . flat_map ( | ( idx , _ ) | maps [ idx ] . iter ( ) ) . map ( | ( key , binding ) | ( key . name , map_outer . get ( & key ) , binding ) ) ; for ( name , info , & binding_inner ) in inners { match info { None => { // The inner binding is missing in the outer. let binding_error = missing_vars . entry ( name ) . or_insert_with ( | | BindingError { name , origin : BTreeSet :: new ( ) , target : BTreeSet :: new ( ) , could_be_path : name . as_str ( ) . starts_with ( char :: is_uppercase ) , } ) ; binding_error . origin . insert ( binding_inner . span ) ; binding_error . target . insert ( pat_outer . span ) ; } Some ( binding_outer ) => { if binding_outer . binding_mode != binding_inner . binding_mode { // The binding modes in the outer and inner bindings differ. inconsistent_vars . entry ( name ) . or_insert ( ( binding_inner . span , binding_outer . span ) ) ; } } } } } // 3) Report all missing variables we found. let mut missing_vars = missing_vars . iter_mut ( ) . collect :: < Vec < _ > > ( ) ; missing_vars . sort_by_key ( | ( sym , _err ) | sym . as_str ( ) ) ; for ( name , mut v ) in missing_vars { if inconsistent_vars . contains_key ( name ) { v . could_be_path = false ; } self . r . report_error ( * v . origin . iter ( ) . next ( ) . unwrap ( ) , ResolutionError :: VariableNotBoundInPattern ( v ) , ) ; } // 4) Report all inconsistencies in binding modes we found. let mut inconsistent_vars = inconsistent_vars . iter ( ) . collect :: < Vec < _ > > ( ) ; inconsistent_vars . sort ( ) ; for ( name , v ) in inconsistent_vars { self . r . report_error ( v . 0 , ResolutionError :: VariableBoundWithDifferentMode ( * name , v . 1 ) ) ; } // 5) Finally bubble up all the binding maps. maps }
Checks that all of the arms in an or-pattern have exactly the
same set of bindings, with the same binding modes for each.
Checks that all of the arms in an or - pattern have exactly the same set of bindings with the same binding modes for each .
&mut self
pats
&[P<Pat>]
&mut self
pats
&[P<Pat>]