/// Map a term to a definition.
///
/// This works for terms that are actually identifiers.
Map a term to a definition.
This works for terms that are actually identifiers.
Map a term to a definition . This works for terms that are actually identifiers .
pub fn term_to_ident(&self, term: Spanned<Term>) -> Result<Spanned<Def>> {
        Ok(match term.value {
            Term::Unresolved(name) => {
                self.emit(DiagBuilder2::error(format!("`{}` is unknown", name)).span(term.span));
                return Err(());
            }
            Term::Ident(def) => def,
            Term::TypeMark(tm) => tm.map_into(),
            Term::Enum(defs) => {
                if defs.len() == 1 {
                    let e = defs.into_iter().next().unwrap();
                    e.map(|e| e.0.into())
                } else {
                    self.emit(
                        DiagBuilder2::error(format!("`{}` is ambiguous", term.span.extract()))
                            .span(term.span),
                    );
                    debugln!("Its definitions are {:#?}", defs);
                    return Err(());
                }
            }
            _ => {
                self.emit(
                    DiagBuilder2::error(format!("`{}` is not an identifier", term.span.extract()))
                        .span(term.span),
                );
                debugln!("It is a {:#?}", term);
                return Err(());
            }
        })
    }
pub fn term_to_ident ( & self , term : Spanned < Term > ) -> Result < Spanned < Def > > { Ok ( match term . value { Term :: Unresolved ( name ) => { self . emit ( DiagBuilder2 :: error ( format ! ( " " name ) ) . span ( term . span ) ) ; return Err ( ( ) ) ; } Term :: Ident ( def ) => def , Term :: TypeMark ( tm ) => tm . map_into ( ) , Term :: Enum ( defs ) => { if defs . len ( ) == 1 { let e = defs . into_iter ( ) . next ( ) . unwrap ( ) ; e . map ( | e | e . 0 . into ( ) ) } else { self . emit ( DiagBuilder2 :: error ( format ! ( " " term span extract ( ) ) ) . span ( term . span ) , ) ; debugln ! ( " " defs ) ; return Err ( ( ) ) ; } } _ => { self . emit ( DiagBuilder2 :: error ( format ! ( " " term span extract ( ) ) ) . span ( term . span ) , ) ; debugln ! ( " " term ) ; return Err ( ( ) ) ; } } ) }
Map a term to a definition.
Map a term to a definition .
&self
term
Spanned<Term>