@@ -91,6 +91,12 @@ pub struct LexError {
9191 _inner : ( ) ,
9292}
9393
94+ impl LexError {
95+ fn new ( ) -> Self {
96+ LexError { _inner : ( ) }
97+ }
98+ }
99+
94100#[ stable( feature = "proc_macro_lexerror_impls" , since = "1.44.0" ) ]
95101impl fmt:: Display for LexError {
96102 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
@@ -1171,6 +1177,28 @@ impl Literal {
11711177 }
11721178}
11731179
1180+ /// Parse a single literal from its stringified representation.
1181+ ///
1182+ /// In order to parse successfully, the input string must not contain anything
1183+ /// but the literal token. Specifically, it must not contain whitespace or
1184+ /// comments in addition to the literal.
1185+ ///
1186+ /// The resulting literal token will have a `Span::call_site()` span.
1187+ ///
1188+ /// NOTE: some errors may cause panics instead of returning `LexError`. We
1189+ /// reserve the right to change these errors into `LexError`s later.
1190+ #[ stable( feature = "proc_macro_literal_parse" , since = "1.54.0" ) ]
1191+ impl FromStr for Literal {
1192+ type Err = LexError ;
1193+
1194+ fn from_str ( src : & str ) -> Result < Self , LexError > {
1195+ match bridge:: client:: Literal :: from_str ( src) {
1196+ Ok ( literal) => Ok ( Literal ( literal) ) ,
1197+ Err ( ( ) ) => Err ( LexError :: new ( ) ) ,
1198+ }
1199+ }
1200+ }
1201+
11741202// N.B., the bridge only provides `to_string`, implement `fmt::Display`
11751203// based on it (the reverse of the usual relationship between the two).
11761204#[ stable( feature = "proc_macro_lib" , since = "1.15.0" ) ]
0 commit comments