pub fn define(&self, scope: ScopeRef, name: Spanned<ResolvableName>, def: Def) -> Result<()> {
        if self.sess.opts.verbosity.contains(Verbosity::NAMES) {
            debugln!("define `{}` as {:?} in scope {:?}", name.value, def, scope);
        }
        self.with_scope(scope, |scope| match def {
            // Handle overloadable cases.
            Def::Enum(_) => {
                scope
                    .defs
                    .entry(name.value)
                    .or_insert_with(|| Vec::new())
                    .push(Spanned::new(def, name.span));
                Ok(())
            }

            // Handle unique cases.
            _ => {
                let ins = scope
                    .defs
                    .insert(name.value, vec![Spanned::new(def, name.span)]);
                if let Some(existing) = ins {
                    self.emit(
                        DiagBuilder2::error(format!("`{}` has already been declared", name.value))
                            .span(name.span)
                            .add_note("Previous declaration was here:")
                            .span(existing.last().unwrap().span),
                    );
                    Err(())
                } else {
                    Ok(())
                }
            }
        })
    }
/// Define a new name in a scope.
Define a new name in a scope.
Define a new name in a scope .
pub fn define(&self, scope: ScopeRef, name: Spanned<ResolvableName>, def: Def) -> Result<()> {
        if self.sess.opts.verbosity.contains(Verbosity::NAMES) {
            debugln!("define `{}` as {:?} in scope {:?}", name.value, def, scope);
        }
        self.with_scope(scope, |scope| match def {
            // Handle overloadable cases.
            Def::Enum(_) => {
                scope
                    .defs
                    .entry(name.value)
                    .or_insert_with(|| Vec::new())
                    .push(Spanned::new(def, name.span));
                Ok(())
            }
            // Handle unique cases.
            _ => {
                let ins = scope
                    .defs
                    .insert(name.value, vec![Spanned::new(def, name.span)]);
                if let Some(existing) = ins {
                    self.emit(
                        DiagBuilder2::error(format!("`{}` has already been declared", name.value))
                            .span(name.span)
                            .add_note("Previous declaration was here:")
                            .span(existing.last().unwrap().span),
                    );
                    Err(())
                } else {
                    Ok(())
                }
            }
        })
    }
pub fn define ( & self , scope : ScopeRef , name : Spanned < ResolvableName > , def : Def ) -> Result < ( ) > { if self . sess . opts . verbosity . contains ( Verbosity :: NAMES ) { debugln ! ( " " name value def scope ) ; } self . with_scope ( scope , | scope | match def { // Handle overloadable cases. Def :: Enum ( _ ) => { scope . defs . entry ( name . value ) . or_insert_with ( | | Vec :: new ( ) ) . push ( Spanned :: new ( def , name . span ) ) ; Ok ( ( ) ) } // Handle unique cases. _ => { let ins = scope . defs . insert ( name . value , vec ! [ Spanned new ( def name span ) ] ) ; if let Some ( existing ) = ins { self . emit ( DiagBuilder2 :: error ( format ! ( " " name value ) ) . span ( name . span ) . add_note ( " " ) . span ( existing . last ( ) . unwrap ( ) . span ) , ) ; Err ( ( ) ) } else { Ok ( ( ) ) } } } ) }
Define a new name in a scope.
Define a new name in a scope .
&self
scope
ScopeRef
name
Spanned<ResolvableName>
def
Def
&self
scope
ScopeRef
name
Spanned<ResolvableName>
def
Def