@@ -3,6 +3,20 @@ use proc_macro2::TokenStream;
33use quote:: quote_spanned;
44use syn:: { Ident , LitStr } ;
55
6+ #[ cfg( feature = "std" ) ]
7+ const IS_STD : bool = true ;
8+ #[ cfg( not( feature = "std" ) ) ]
9+ const IS_STD : bool = false ;
10+
11+ macro_rules! peek_next {
12+ ( $read: ident) => {
13+ match $read. chars( ) . next( ) {
14+ Some ( next) => next,
15+ None => return ,
16+ }
17+ } ;
18+ }
19+
620impl Display {
721 // Transform `"error {var}"` to `"error {}", var`.
822 pub fn expand_shorthand ( & mut self ) {
@@ -23,10 +37,7 @@ impl Display {
2337 continue ;
2438 }
2539
26- let next = match read. chars ( ) . next ( ) {
27- Some ( next) => next,
28- None => return ,
29- } ;
40+ let next = peek_next ! ( read) ;
3041
3142 let var = match next {
3243 '0' ..='9' => take_int ( & mut read) ,
@@ -36,12 +47,9 @@ impl Display {
3647
3748 let ident = Ident :: new ( & var, span) ;
3849
39- let next = match read. chars ( ) . next ( ) {
40- Some ( next) => next,
41- None => return ,
42- } ;
50+ let next = peek_next ! ( read) ;
4351
44- let arg = if core :: cfg! ( feature = "std" ) && next == '}' {
52+ let arg = if IS_STD && next == '}' {
4553 quote_spanned ! ( span=> , ( & #ident) . get_display( ) )
4654 } else {
4755 quote_spanned ! ( span=> , #ident)
0 commit comments