// If a variant has an expression specifying its discriminant, then it needs
// to be checked just like a static or constant. However, if there are more
// variants with no explicitly specified discriminant, those variants will
// increment the same expression to get their values.
//
// So for every variant, we need to track whether there is an expression
// somewhere in the enum definition that controls its discriminant. We do
// this by starting from the end and searching backward.
If a variant has an expression specifying its discriminant, then it needs
to be checked just like a static or constant. However, if there are more
variants with no explicitly specified discriminant, those variants will
increment the same expression to get their values.

So for every variant, we need to track whether there is an expression
somewhere in the enum definition that controls its discriminant. We do
this by starting from the end and searching backward.
If a variant has an expression specifying its discriminant then it needs to be checked just like a static or constant . However if there are more variants with no explicitly specified discriminant those variants will increment the same expression to get their values . So for every variant we need to track whether there is an expression somewhere in the enum definition that controls its discriminant . We do this by starting from the end and searching backward .
fn populate_enum_discriminants(&self, enum_definition: &'ast hir::EnumDef) {
        // Get the map, and return if we already processed this enum or if it
        // has no variants.
        let mut discriminant_map = self.discriminant_map.borrow_mut();
        match enum_definition.variants.first() {
            None => { return; }
            Some(variant) if discriminant_map.contains_key(&variant.node.id) => {
                return;
            }
            _ => {}
        }
        // Go through all the variants.
        let mut variant_stack: Vec<ast::NodeId> = Vec::new();
        for variant in enum_definition.variants.iter().rev() {
            variant_stack.push(variant.node.id);
            // When we find an expression, every variant currently on the stack
            // is affected by that expression.
            if let Some(ref expr) = variant.node.disr_expr {
                for id in &variant_stack {
                    discriminant_map.insert(*id, Some(expr));
                }
                variant_stack.clear()
            }
        }
        // If we are at the top, that always starts at 0, so any variant on the
        // stack has a default value and does not need to be checked.
        for id in &variant_stack {
            discriminant_map.insert(*id, None);
        }
    }
fn populate_enum_discriminants ( & self , enum_definition : & ' ast hir :: EnumDef ) { // Get the map, and return if we already processed this enum or if it // has no variants. let mut discriminant_map = self . discriminant_map . borrow_mut ( ) ; match enum_definition . variants . first ( ) { None => { return ; } Some ( variant ) if discriminant_map . contains_key ( & variant . node . id ) => { return ; } _ => { } } // Go through all the variants. let mut variant_stack : Vec < ast :: NodeId > = Vec :: new ( ) ; for variant in enum_definition . variants . iter ( ) . rev ( ) { variant_stack . push ( variant . node . id ) ; // When we find an expression, every variant currently on the stack // is affected by that expression. if let Some ( ref expr ) = variant . node . disr_expr { for id in & variant_stack { discriminant_map . insert ( * id , Some ( expr ) ) ; } variant_stack . clear ( ) } } // If we are at the top, that always starts at 0, so any variant on the // stack has a default value and does not need to be checked. for id in & variant_stack { discriminant_map . insert ( * id , None ) ; } }
If a variant has an expression specifying its discriminant, then it needs
to be checked just like a static or constant.
If a variant has an expression specifying its discriminant then it needs to be checked just like a static or constant .
&self
enum_definition
&'ast hir::EnumDef