@@ -1225,14 +1225,16 @@ fn escape_utf8(string: &str, repr: &mut String) {
1225
1225
#[ cfg( feature = "proc-macro" ) ]
1226
1226
pub ( crate ) trait FromStr2 : FromStr < Err = proc_macro:: LexError > {
1227
1227
#[ cfg( wrap_proc_macro) ]
1228
- fn validate ( src : & str ) -> Result < ( ) , LexError > ;
1228
+ fn valid ( src : & str ) -> bool ;
1229
1229
1230
1230
#[ cfg( wrap_proc_macro) ]
1231
1231
fn from_str_checked ( src : & str ) -> Result < Self , imp:: LexError > {
1232
1232
// Validate using fallback parser, because rustc is incapable of
1233
1233
// returning a recoverable Err for certain invalid token streams, and
1234
1234
// will instead permanently poison the compilation.
1235
- Self :: validate ( src) ?;
1235
+ if !Self :: valid ( src) {
1236
+ return Err ( imp:: LexError :: CompilerPanic ) ;
1237
+ }
1236
1238
1237
1239
// Catch panic to work around https://github.com/rust-lang/rust/issues/58736.
1238
1240
match panic:: catch_unwind ( || Self :: from_str ( src) ) {
@@ -1250,15 +1252,15 @@ pub(crate) trait FromStr2: FromStr<Err = proc_macro::LexError> {
1250
1252
#[ cfg( feature = "proc-macro" ) ]
1251
1253
impl FromStr2 for proc_macro:: TokenStream {
1252
1254
#[ cfg( wrap_proc_macro) ]
1253
- fn validate ( src : & str ) -> Result < ( ) , LexError > {
1254
- TokenStream :: from_str_checked ( src) . map ( drop )
1255
+ fn valid ( src : & str ) -> bool {
1256
+ TokenStream :: from_str_checked ( src) . is_ok ( )
1255
1257
}
1256
1258
}
1257
1259
1258
1260
#[ cfg( feature = "proc-macro" ) ]
1259
1261
impl FromStr2 for proc_macro:: Literal {
1260
1262
#[ cfg( wrap_proc_macro) ]
1261
- fn validate ( src : & str ) -> Result < ( ) , LexError > {
1262
- Literal :: from_str_checked ( src) . map ( drop )
1263
+ fn valid ( src : & str ) -> bool {
1264
+ Literal :: from_str_checked ( src) . is_ok ( )
1263
1265
}
1264
1266
}
0 commit comments