File tree 4 files changed +31
-0
lines changed
4 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,10 @@ fn main() {
69
69
println ! ( "cargo:rustc-cfg=no_bind_by_move_pattern_guard" ) ;
70
70
}
71
71
72
+ if version. minor >= 44 {
73
+ println ! ( "cargo:rustc-cfg=lexerror_display" ) ;
74
+ }
75
+
72
76
if version. minor >= 45 {
73
77
println ! ( "cargo:rustc-cfg=hygiene" ) ;
74
78
}
Original file line number Diff line number Diff line change @@ -148,6 +148,12 @@ impl FromStr for TokenStream {
148
148
}
149
149
}
150
150
151
+ impl Display for LexError {
152
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
153
+ f. write_str ( "cannot parse string into token stream" )
154
+ }
155
+ }
156
+
151
157
impl Display for TokenStream {
152
158
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
153
159
let mut joint = false ;
Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ mod imp;
105
105
106
106
use crate :: marker:: Marker ;
107
107
use std:: cmp:: Ordering ;
108
+ use std:: error:: Error ;
108
109
use std:: fmt:: { self , Debug , Display } ;
109
110
use std:: hash:: { Hash , Hasher } ;
110
111
use std:: iter:: FromIterator ;
@@ -254,6 +255,14 @@ impl Debug for LexError {
254
255
}
255
256
}
256
257
258
+ impl Display for LexError {
259
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
260
+ Display :: fmt ( & self . inner , f)
261
+ }
262
+ }
263
+
264
+ impl Error for LexError { }
265
+
257
266
/// The source file of a given `Span`.
258
267
///
259
268
/// This type is semver exempt and not exposed by default.
Original file line number Diff line number Diff line change @@ -264,6 +264,18 @@ impl Debug for LexError {
264
264
}
265
265
}
266
266
267
+ impl Display for LexError {
268
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
269
+ match self {
270
+ #[ cfg( lexerror_display) ]
271
+ LexError :: Compiler ( e) => Display :: fmt ( e, f) ,
272
+ #[ cfg( not( lexerror_display) ) ]
273
+ LexError :: Compiler ( _e) => Display :: fmt ( & fallback:: LexError , f) ,
274
+ LexError :: Fallback ( e) => Display :: fmt ( e, f) ,
275
+ }
276
+ }
277
+ }
278
+
267
279
#[ derive( Clone ) ]
268
280
pub ( crate ) enum TokenTreeIter {
269
281
Compiler ( proc_macro:: token_stream:: IntoIter ) ,
You can’t perform that action at this time.
0 commit comments