@@ -91,6 +91,12 @@ pub struct LexError {
91
91
_inner : ( ) ,
92
92
}
93
93
94
+ impl LexError {
95
+ fn new ( ) -> Self {
96
+ LexError { _inner : ( ) }
97
+ }
98
+ }
99
+
94
100
#[ stable( feature = "proc_macro_lexerror_impls" , since = "1.44.0" ) ]
95
101
impl fmt:: Display for LexError {
96
102
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
@@ -1171,6 +1177,28 @@ impl Literal {
1171
1177
}
1172
1178
}
1173
1179
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
+
1174
1202
// N.B., the bridge only provides `to_string`, implement `fmt::Display`
1175
1203
// based on it (the reverse of the usual relationship between the two).
1176
1204
#[ stable( feature = "proc_macro_lib" , since = "1.15.0" ) ]
0 commit comments