@@ -921,18 +921,25 @@ impl FromStr for Literal {
921
921
922
922
fn from_str ( repr : & str ) -> Result < Self , Self :: Err > {
923
923
if inside_proc_macro ( ) {
924
- // TODO: use libproc_macro's FromStr impl once it is available in
925
- // rustc. https://github.com/rust-lang/rust/pull/84717
926
- let tokens = proc_macro_parse ( repr) ?;
927
- let mut iter = tokens. into_iter ( ) ;
928
- if let ( Some ( proc_macro:: TokenTree :: Literal ( literal) ) , None ) =
929
- ( iter. next ( ) , iter. next ( ) )
924
+ #[ cfg( literal_from_str) ]
930
925
{
931
- if literal. to_string ( ) . len ( ) == repr. len ( ) {
932
- return Ok ( Literal :: Compiler ( literal) ) ;
926
+ proc_macro:: Literal :: from_str ( repr)
927
+ . map ( Literal :: Compiler )
928
+ . map_err ( LexError :: Compiler )
929
+ }
930
+ #[ cfg( not( literal_from_str) ) ]
931
+ {
932
+ let tokens = proc_macro_parse ( repr) ?;
933
+ let mut iter = tokens. into_iter ( ) ;
934
+ if let ( Some ( proc_macro:: TokenTree :: Literal ( literal) ) , None ) =
935
+ ( iter. next ( ) , iter. next ( ) )
936
+ {
937
+ if literal. to_string ( ) . len ( ) == repr. len ( ) {
938
+ return Ok ( Literal :: Compiler ( literal) ) ;
939
+ }
933
940
}
941
+ Err ( LexError :: call_site ( ) )
934
942
}
935
- Err ( LexError :: call_site ( ) )
936
943
} else {
937
944
let literal = fallback:: Literal :: from_str ( repr) ?;
938
945
Ok ( Literal :: Fallback ( literal) )
0 commit comments