@@ -1225,14 +1225,16 @@ fn escape_utf8(string: &str, repr: &mut String) {
12251225#[ cfg( feature = "proc-macro" ) ]
12261226pub ( crate ) trait FromStr2 : FromStr < Err = proc_macro:: LexError > {
12271227 #[ cfg( wrap_proc_macro) ]
1228- fn validate ( src : & str ) -> Result < ( ) , LexError > ;
1228+ fn valid ( src : & str ) -> bool ;
12291229
12301230 #[ cfg( wrap_proc_macro) ]
12311231 fn from_str_checked ( src : & str ) -> Result < Self , imp:: LexError > {
12321232 // Validate using fallback parser, because rustc is incapable of
12331233 // returning a recoverable Err for certain invalid token streams, and
12341234 // will instead permanently poison the compilation.
1235- Self :: validate ( src) ?;
1235+ if !Self :: valid ( src) {
1236+ return Err ( imp:: LexError :: CompilerPanic ) ;
1237+ }
12361238
12371239 // Catch panic to work around https://github.com/rust-lang/rust/issues/58736.
12381240 match panic:: catch_unwind ( || Self :: from_str ( src) ) {
@@ -1250,15 +1252,15 @@ pub(crate) trait FromStr2: FromStr<Err = proc_macro::LexError> {
12501252#[ cfg( feature = "proc-macro" ) ]
12511253impl FromStr2 for proc_macro:: TokenStream {
12521254 #[ 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 ( )
12551257 }
12561258}
12571259
12581260#[ cfg( feature = "proc-macro" ) ]
12591261impl FromStr2 for proc_macro:: Literal {
12601262 #[ 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 ( )
12631265 }
12641266}
0 commit comments