@@ -28,14 +28,10 @@ pub(crate) struct DeferredTokenStream {
28
28
pub ( crate ) enum LexError {
29
29
Compiler ( proc_macro:: LexError ) ,
30
30
Fallback ( fallback:: LexError ) ,
31
- }
32
31
33
- impl LexError {
34
- fn call_site ( ) -> Self {
35
- LexError :: Fallback ( fallback:: LexError {
36
- span : fallback:: Span :: call_site ( ) ,
37
- } )
38
- }
32
+ // Rustc was supposed to return a LexError, but it panicked instead.
33
+ // https://github.com/rust-lang/rust/issues/58736
34
+ CompilerPanic ,
39
35
}
40
36
41
37
#[ cold]
@@ -126,7 +122,7 @@ impl FromStr for TokenStream {
126
122
// Work around https://github.com/rust-lang/rust/issues/58736.
127
123
fn proc_macro_parse ( src : & str ) -> Result < proc_macro:: TokenStream , LexError > {
128
124
let result = panic:: catch_unwind ( || src. parse ( ) . map_err ( LexError :: Compiler ) ) ;
129
- result. unwrap_or_else ( |_| Err ( LexError :: call_site ( ) ) )
125
+ result. unwrap_or_else ( |_| Err ( LexError :: CompilerPanic ) )
130
126
}
131
127
132
128
impl Display for TokenStream {
@@ -264,7 +260,7 @@ impl Debug for TokenStream {
264
260
impl LexError {
265
261
pub ( crate ) fn span ( & self ) -> Span {
266
262
match self {
267
- LexError :: Compiler ( _) => Span :: call_site ( ) ,
263
+ LexError :: Compiler ( _) | LexError :: CompilerPanic => Span :: call_site ( ) ,
268
264
LexError :: Fallback ( e) => Span :: Fallback ( e. span ( ) ) ,
269
265
}
270
266
}
@@ -287,6 +283,10 @@ impl Debug for LexError {
287
283
match self {
288
284
LexError :: Compiler ( e) => Debug :: fmt ( e, f) ,
289
285
LexError :: Fallback ( e) => Debug :: fmt ( e, f) ,
286
+ LexError :: CompilerPanic => {
287
+ let fallback = fallback:: LexError :: call_site ( ) ;
288
+ Debug :: fmt ( & fallback, f)
289
+ }
290
290
}
291
291
}
292
292
}
@@ -296,6 +296,10 @@ impl Display for LexError {
296
296
match self {
297
297
LexError :: Compiler ( e) => Display :: fmt ( e, f) ,
298
298
LexError :: Fallback ( e) => Display :: fmt ( e, f) ,
299
+ LexError :: CompilerPanic => {
300
+ let fallback = fallback:: LexError :: call_site ( ) ;
301
+ Display :: fmt ( & fallback, f)
302
+ }
299
303
}
300
304
}
301
305
}
0 commit comments