@@ -806,7 +806,7 @@ macro_rules! unsuffixed_integers {
806
806
impl Literal {
807
807
pub unsafe fn from_str_unchecked ( repr : & str ) -> Self {
808
808
if inside_proc_macro ( ) {
809
- Literal :: Compiler ( repr . parse ( ) . expect ( "invalid literal" ) )
809
+ Literal :: Compiler ( compiler_literal_from_str ( repr ) . expect ( "invalid literal" ) )
810
810
} else {
811
811
Literal :: Fallback ( fallback:: Literal :: from_str_unchecked ( repr) )
812
812
}
@@ -929,32 +929,32 @@ impl FromStr for Literal {
929
929
930
930
fn from_str ( repr : & str ) -> Result < Self , Self :: Err > {
931
931
if inside_proc_macro ( ) {
932
- #[ cfg( not( no_literal_from_str) ) ]
933
- {
934
- proc_macro:: Literal :: from_str ( repr)
935
- . map ( Literal :: Compiler )
936
- . map_err ( LexError :: Compiler )
937
- }
938
- #[ cfg( no_literal_from_str) ]
939
- {
940
- let tokens = proc_macro_parse ( repr) ?;
941
- let mut iter = tokens. into_iter ( ) ;
942
- if let ( Some ( proc_macro:: TokenTree :: Literal ( literal) ) , None ) =
943
- ( iter. next ( ) , iter. next ( ) )
944
- {
945
- if literal. to_string ( ) . len ( ) == repr. len ( ) {
946
- return Ok ( Literal :: Compiler ( literal) ) ;
947
- }
948
- }
949
- Err ( LexError :: call_site ( ) )
950
- }
932
+ compiler_literal_from_str ( repr) . map ( Literal :: Compiler )
951
933
} else {
952
934
let literal = fallback:: Literal :: from_str ( repr) ?;
953
935
Ok ( Literal :: Fallback ( literal) )
954
936
}
955
937
}
956
938
}
957
939
940
+ fn compiler_literal_from_str ( repr : & str ) -> Result < proc_macro:: Literal , LexError > {
941
+ #[ cfg( not( no_literal_from_str) ) ]
942
+ {
943
+ proc_macro:: Literal :: from_str ( repr) . map_err ( LexError :: Compiler )
944
+ }
945
+ #[ cfg( no_literal_from_str) ]
946
+ {
947
+ let tokens = proc_macro_parse ( repr) ?;
948
+ let mut iter = tokens. into_iter ( ) ;
949
+ if let ( Some ( proc_macro:: TokenTree :: Literal ( literal) ) , None ) = ( iter. next ( ) , iter. next ( ) ) {
950
+ if literal. to_string ( ) . len ( ) == repr. len ( ) {
951
+ return Ok ( literal) ;
952
+ }
953
+ }
954
+ Err ( LexError :: call_site ( ) )
955
+ }
956
+ }
957
+
958
958
impl Display for Literal {
959
959
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
960
960
match self {
0 commit comments