fn from_lit_token(
        lit: token::Lit,
        suf: Option<Symbol>,
        diag: Option<(Span, &Handler)>
    ) -> Option<LitKind> {
        if suf.is_some() && !lit.may_have_suffix() {
            err!(diag, |span, diag| {
                expect_no_suffix(span, diag, &format!("a {}", lit.literal_name()), suf)
            });
        }

        Some(match lit {
            token::Bool(i) => {
                assert!(i == kw::True || i == kw::False);
                LitKind::Bool(i == kw::True)
            }
            token::Byte(i) => {
                match unescape_byte(&i.as_str()) {
                    Ok(c) => LitKind::Byte(c),
                    Err(_) => LitKind::Err(i),
                }
            },
            token::Char(i) => {
                match unescape_char(&i.as_str()) {
                    Ok(c) => LitKind::Char(c),
                    Err(_) => LitKind::Err(i),
                }
            },
            token::Err(i) => LitKind::Err(i),

            // There are some valid suffixes for integer and float literals,
            // so all the handling is done internally.
            token::Integer(s) => return integer_lit(&s.as_str(), suf, diag),
            token::Float(s) => return float_lit(&s.as_str(), suf, diag),

            token::Str_(mut sym) => {
                // If there are no characters requiring special treatment we can
                // reuse the symbol from the Token. Otherwise, we must generate a
                // new symbol because the string in the LitKind is different to the
                // string in the Token.
                let mut has_error = false;
                let s = &sym.as_str();
                if s.as_bytes().iter().any(|&c| c == b'\\' || c == b'\r') {
                    let mut buf = String::with_capacity(s.len());
                    unescape_str(s, &mut |_, unescaped_char| {
                        match unescaped_char {
                            Ok(c) => buf.push(c),
                            Err(_) => has_error = true,
                        }
                    });
                    if has_error {
                        return Some(LitKind::Err(sym));
                    }
                    sym = Symbol::intern(&buf)
                }

                LitKind::Str(sym, ast::StrStyle::Cooked)
            }
            token::StrRaw(mut sym, n) => {
                // Ditto.
                let s = &sym.as_str();
                if s.contains('\r') {
                    sym = Symbol::intern(&raw_str_lit(s));
                }
                LitKind::Str(sym, ast::StrStyle::Raw(n))
            }
            token::ByteStr(i) => {
                let s = &i.as_str();
                let mut buf = Vec::with_capacity(s.len());
                let mut has_error = false;
                unescape_byte_str(s, &mut |_, unescaped_byte| {
                    match unescaped_byte {
                        Ok(c) => buf.push(c),
                        Err(_) => has_error = true,
                    }
                });
                if has_error {
                    return Some(LitKind::Err(i));
                }
                buf.shrink_to_fit();
                LitKind::ByteStr(Lrc::new(buf))
            }
            token::ByteStrRaw(i, _) => {
                LitKind::ByteStr(Lrc::new(i.to_string().into_bytes()))
            }
        })
    }
/// Converts literal token with a suffix into a semantic literal.
/// Works speculatively and may return `None` if diagnostic handler is not passed.
/// If diagnostic handler is passed, always returns `Some`,
/// possibly after reporting non-fatal errors and recovery.
Converts literal token with a suffix into a semantic literal.
Works speculatively and may return `None` if diagnostic handler is not passed.
If diagnostic handler is passed, always returns `Some`,
possibly after reporting non-fatal errors and recovery.
Converts literal token with a suffix into a semantic literal . Works speculatively and may return ` None ` if diagnostic handler is not passed . If diagnostic handler is passed always returns ` Some ` possibly after reporting non - fatal errors and recovery .
fn from_lit_token(
        lit: token::Lit,
        suf: Option<Symbol>,
        diag: Option<(Span, &Handler)>
    ) -> Option<LitKind> {
        if suf.is_some() && !lit.may_have_suffix() {
            err!(diag, |span, diag| {
                expect_no_suffix(span, diag, &format!("a {}", lit.literal_name()), suf)
            });
        }
        Some(match lit {
            token::Bool(i) => {
                assert!(i == kw::True || i == kw::False);
                LitKind::Bool(i == kw::True)
            }
            token::Byte(i) => {
                match unescape_byte(&i.as_str()) {
                    Ok(c) => LitKind::Byte(c),
                    Err(_) => LitKind::Err(i),
                }
            },
            token::Char(i) => {
                match unescape_char(&i.as_str()) {
                    Ok(c) => LitKind::Char(c),
                    Err(_) => LitKind::Err(i),
                }
            },
            token::Err(i) => LitKind::Err(i),
            // There are some valid suffixes for integer and float literals,
            // so all the handling is done internally.
            token::Integer(s) => return integer_lit(&s.as_str(), suf, diag),
            token::Float(s) => return float_lit(&s.as_str(), suf, diag),
            token::Str_(mut sym) => {
                // If there are no characters requiring special treatment we can
                // reuse the symbol from the Token. Otherwise, we must generate a
                // new symbol because the string in the LitKind is different to the
                // string in the Token.
                let mut has_error = false;
                let s = &sym.as_str();
                if s.as_bytes().iter().any(|&c| c == b'\\' || c == b'\r') {
                    let mut buf = String::with_capacity(s.len());
                    unescape_str(s, &mut |_, unescaped_char| {
                        match unescaped_char {
                            Ok(c) => buf.push(c),
                            Err(_) => has_error = true,
                        }
                    });
                    if has_error {
                        return Some(LitKind::Err(sym));
                    }
                    sym = Symbol::intern(&buf)
                }
                LitKind::Str(sym, ast::StrStyle::Cooked)
            }
            token::StrRaw(mut sym, n) => {
                // Ditto.
                let s = &sym.as_str();
                if s.contains('\r') {
                    sym = Symbol::intern(&raw_str_lit(s));
                }
                LitKind::Str(sym, ast::StrStyle::Raw(n))
            }
            token::ByteStr(i) => {
                let s = &i.as_str();
                let mut buf = Vec::with_capacity(s.len());
                let mut has_error = false;
                unescape_byte_str(s, &mut |_, unescaped_byte| {
                    match unescaped_byte {
                        Ok(c) => buf.push(c),
                        Err(_) => has_error = true,
                    }
                });
                if has_error {
                    return Some(LitKind::Err(i));
                }
                buf.shrink_to_fit();
                LitKind::ByteStr(Lrc::new(buf))
            }
            token::ByteStrRaw(i, _) => {
                LitKind::ByteStr(Lrc::new(i.to_string().into_bytes()))
            }
        })
    }
fn from_lit_token ( lit : token :: Lit , suf : Option < Symbol > , diag : Option < ( Span , & Handler ) > ) -> Option < LitKind > { if suf . is_some ( ) && ! lit . may_have_suffix ( ) { err ! ( diag span diag { expect_no_suffix ( span diag format ( " " lit literal_name ( ) ) suf ) } ) ; } Some ( match lit { token :: Bool ( i ) => { assert ! ( i kw True i kw False ) ; LitKind :: Bool ( i == kw :: True ) } token :: Byte ( i ) => { match unescape_byte ( & i . as_str ( ) ) { Ok ( c ) => LitKind :: Byte ( c ) , Err ( _ ) => LitKind :: Err ( i ) , } } , token :: Char ( i ) => { match unescape_char ( & i . as_str ( ) ) { Ok ( c ) => LitKind :: Char ( c ) , Err ( _ ) => LitKind :: Err ( i ) , } } , token :: Err ( i ) => LitKind :: Err ( i ) , // There are some valid suffixes for integer and float literals, // so all the handling is done internally. token :: Integer ( s ) => return integer_lit ( & s . as_str ( ) , suf , diag ) , token :: Float ( s ) => return float_lit ( & s . as_str ( ) , suf , diag ) , token :: Str_ ( mut sym ) => { // If there are no characters requiring special treatment we can // reuse the symbol from the Token. Otherwise, we must generate a // new symbol because the string in the LitKind is different to the // string in the Token. let mut has_error = false ; let s = & sym . as_str ( ) ; if s . as_bytes ( ) . iter ( ) . any ( | & c | c == b'\\' || c == b'\r' ) { let mut buf = String :: with_capacity ( s . len ( ) ) ; unescape_str ( s , & mut | _ , unescaped_char | { match unescaped_char { Ok ( c ) => buf . push ( c ) , Err ( _ ) => has_error = true , } } ) ; if has_error { return Some ( LitKind :: Err ( sym ) ) ; } sym = Symbol :: intern ( & buf ) } LitKind :: Str ( sym , ast :: StrStyle :: Cooked ) } token :: StrRaw ( mut sym , n ) => { // Ditto. let s = & sym . as_str ( ) ; if s . contains ( '\r' ) { sym = Symbol :: intern ( & raw_str_lit ( s ) ) ; } LitKind :: Str ( sym , ast :: StrStyle :: Raw ( n ) ) } token :: ByteStr ( i ) => { let s = & i . as_str ( ) ; let mut buf = Vec :: with_capacity ( s . len ( ) ) ; let mut has_error = false ; unescape_byte_str ( s , & mut | _ , unescaped_byte | { match unescaped_byte { Ok ( c ) => buf . push ( c ) , Err ( _ ) => has_error = true , } } ) ; if has_error { return Some ( LitKind :: Err ( i ) ) ; } buf . shrink_to_fit ( ) ; LitKind :: ByteStr ( Lrc :: new ( buf ) ) } token :: ByteStrRaw ( i , _ ) => { LitKind :: ByteStr ( Lrc :: new ( i . to_string ( ) . into_bytes ( ) ) ) } } ) }
Converts literal token with a suffix into a semantic literal.
Converts literal token with a suffix into a semantic literal .
lit
token::Lit
suf
Option<Symbol>
diag
Option<(Span, &Handler)>
lit
token::Lit
suf
Option<Symbol>
diag
Option<(Span, &Handler)>