/// Define a new name in the scope.
Define a new name in the scope.
Define a new name in the scope .
pub fn define(
        &self,
        name: Spanned<ResolvableName>,
        def: Def2<'t>,
        ctx: &SessionContext,
    ) -> Result<()> {
        if ctx.has_verbosity(Verbosity::NAMES) {
            ctx.emit(
                DiagBuilder2::note(format!("define `{}` as {:?}", name.value, def)).span(name.span),
            );
        }
        debugln!("define `{}` as {:?}", name.value, def);
        match def {
            // Handle overloadable cases.
            Def2::Enum(..) => {
                self.defs
                    .borrow_mut()
                    .entry(name.value)
                    .or_insert_with(|| Vec::new())
                    .push(Spanned::new(def, name.span));
                Ok(())
            }
            // Handle unique cases.
            _ => {
                let ins = self
                    .defs
                    .borrow_mut()
                    .insert(name.value, vec![Spanned::new(def, name.span)]);
                if let Some(existing) = ins {
                    ctx.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 , name : Spanned < ResolvableName > , def : Def2 < ' t > , ctx : & SessionContext , ) -> Result < ( ) > { if ctx . has_verbosity ( Verbosity :: NAMES ) { ctx . emit ( DiagBuilder2 :: note ( format ! ( " " name value def ) ) . span ( name . span ) , ) ; } debugln ! ( " " name value def ) ; match def { // Handle overloadable cases. Def2 :: Enum ( .. ) => { self . defs . borrow_mut ( ) . entry ( name . value ) . or_insert_with ( | | Vec :: new ( ) ) . push ( Spanned :: new ( def , name . span ) ) ; Ok ( ( ) ) } // Handle unique cases. _ => { let ins = self . defs . borrow_mut ( ) . insert ( name . value , vec ! [ Spanned new ( def name span ) ] ) ; if let Some ( existing ) = ins { ctx . emit ( DiagBuilder2 :: error ( format ! ( " " name value ) ) . span ( name . span ) . add_note ( " " ) . span ( existing . last ( ) . unwrap ( ) . span ) , ) ; Err ( ( ) ) } else { Ok ( ( ) ) } } } }
Define a new name in the scope.
Define a new name in the scope .
&self
name
Spanned<ResolvableName>
def
Def2<'t>
ctx
&SessionContext