/// Generate a fresh name based on the names that have already been
/// used in the environment. We try to get close to the `name_hint`,
/// adding a number if necessary.
Generate a fresh name based on the names that have already been
used in the environment. We try to get close to the `name_hint`,
adding a number if necessary.
Generate a fresh name based on the names that have already been used in the environment . We try to get close to the ` name_hint ` adding a number if necessary .
fn fresh_name(&mut self, name_hint: Option<&str>) -> String {
        // Use `x` as our default name, for lack of anything better...
        const DEFAULT_NAME: &str = "x";
        match name_hint {
            None => self.fresh_name(Some(DEFAULT_NAME)),
            Some(name_hint) => {
                // Check to see if the hinted name was already used.
                let name = match self.names_to_counts.get_mut(name_hint) {
                    Some(count) => {
                        *count += 1; // Bump the count if it's been used!
                        format!("{}{}", name_hint, count)
                    },
                    None => name_hint.to_owned(),
                };
                // Allow the name to be found by future variable usages.
                self.names.add_entry(name.clone());
                // Add the name to the usage count map to ensure that we don't
                // collide with it again.
                self.names_to_counts.insert(name.clone(), 0);
                name
            },
        }
    }
fn fresh_name ( & mut self , name_hint : Option < & str > ) -> String { // Use `x` as our default name, for lack of anything better... const DEFAULT_NAME : & str = " " ; match name_hint { None => self . fresh_name ( Some ( DEFAULT_NAME ) ) , Some ( name_hint ) => { // Check to see if the hinted name was already used. let name = match self . names_to_counts . get_mut ( name_hint ) { Some ( count ) => { * count += 1 ; // Bump the count if it's been used! format ! ( " " name_hint count ) } , None => name_hint . to_owned ( ) , } ; // Allow the name to be found by future variable usages. self . names . add_entry ( name . clone ( ) ) ; // Add the name to the usage count map to ensure that we don't // collide with it again. self . names_to_counts . insert ( name . clone ( ) , 0 ) ; name } , } }
Generate a fresh name based on the names that have already been
used in the environment.
Generate a fresh name based on the names that have already been used in the environment .
&mut self
name_hint
Option<&str>