/// Converts literal token with a suffix into an AST literal.
/// Works speculatively and may return `None` if diagnostic handler is not passed.
/// If diagnostic handler is passed, may return `Some`,
/// possibly after reporting non-fatal errors and recovery, or `None` for irrecoverable errors.
Converts literal token with a suffix into an AST literal.
Works speculatively and may return `None` if diagnostic handler is not passed.
If diagnostic handler is passed, may return `Some`,
possibly after reporting non-fatal errors and recovery, or `None` for irrecoverable errors.
Converts literal token with a suffix into an AST literal . Works speculatively and may return ` None ` if diagnostic handler is not passed . If diagnostic handler is passed may return ` Some ` possibly after reporting non - fatal errors and recovery or ` None ` for irrecoverable errors .
crate fn from_token(
        token: &token::Token,
        span: Span,
        diag: Option<(Span, &Handler)>,
    ) -> Option<Lit> {
        let (token, suffix) = match *token {
            token::Ident(ident, false) if ident.name == kw::True || ident.name == kw::False =>
                (token::Bool(ident.name), None),
            token::Literal(token, suffix) =>
                (token, suffix),
            token::Interpolated(ref nt) => {
                if let token::NtExpr(expr) | token::NtLiteral(expr) = &**nt {
                    if let ast::ExprKind::Lit(lit) = &expr.node {
                        return Some(lit.clone());
                    }
                }
                return None;
            }
            _ => return None,
        };
        let node = LitKind::from_lit_token(token, suffix, diag)?;
        Some(Lit { node, token, suffix, span })
    }
crate fn from_token ( token : & token :: Token , span : Span , diag : Option < ( Span , & Handler ) > , ) -> Option < Lit > { let ( token , suffix ) = match * token { token :: Ident ( ident , false ) if ident . name == kw :: True || ident . name == kw :: False => ( token :: Bool ( ident . name ) , None ) , token :: Literal ( token , suffix ) => ( token , suffix ) , token :: Interpolated ( ref nt ) => { if let token :: NtExpr ( expr ) | token :: NtLiteral ( expr ) = & * * nt { if let ast :: ExprKind :: Lit ( lit ) = & expr . node { return Some ( lit . clone ( ) ) ; } } return None ; } _ => return None , } ; let node = LitKind :: from_lit_token ( token , suffix , diag ) ? ; Some ( Lit { node , token , suffix , span } ) }
Converts literal token with a suffix into an AST literal.
Converts literal token with a suffix into an AST literal .
token
&token::Token
span
Span
diag
Option<(Span, &Handler)>