File tree Expand file tree Collapse file tree 4 files changed +31
-0
lines changed Expand file tree Collapse file tree 4 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,10 @@ fn main() {
6969 println ! ( "cargo:rustc-cfg=no_bind_by_move_pattern_guard" ) ;
7070 }
7171
72+ if version. minor >= 44 {
73+ println ! ( "cargo:rustc-cfg=lexerror_display" ) ;
74+ }
75+
7276 if version. minor >= 45 {
7377 println ! ( "cargo:rustc-cfg=hygiene" ) ;
7478 }
Original file line number Diff line number Diff line change @@ -148,6 +148,12 @@ impl FromStr for TokenStream {
148148 }
149149}
150150
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+
151157impl Display for TokenStream {
152158 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
153159 let mut joint = false ;
Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ mod imp;
105105
106106use crate :: marker:: Marker ;
107107use std:: cmp:: Ordering ;
108+ use std:: error:: Error ;
108109use std:: fmt:: { self , Debug , Display } ;
109110use std:: hash:: { Hash , Hasher } ;
110111use std:: iter:: FromIterator ;
@@ -254,6 +255,14 @@ impl Debug for LexError {
254255 }
255256}
256257
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+
257266/// The source file of a given `Span`.
258267///
259268/// 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 {
264264 }
265265}
266266
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+
267279#[ derive( Clone ) ]
268280pub ( crate ) enum TokenTreeIter {
269281 Compiler ( proc_macro:: token_stream:: IntoIter ) ,
You can’t perform that action at this time.
0 commit comments