@@ -3,6 +3,20 @@ use proc_macro2::TokenStream;
3
3
use quote:: quote_spanned;
4
4
use syn:: { Ident , LitStr } ;
5
5
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
+
6
20
impl Display {
7
21
// Transform `"error {var}"` to `"error {}", var`.
8
22
pub fn expand_shorthand ( & mut self ) {
@@ -23,10 +37,7 @@ impl Display {
23
37
continue ;
24
38
}
25
39
26
- let next = match read. chars ( ) . next ( ) {
27
- Some ( next) => next,
28
- None => return ,
29
- } ;
40
+ let next = peek_next ! ( read) ;
30
41
31
42
let var = match next {
32
43
'0' ..='9' => take_int ( & mut read) ,
@@ -36,12 +47,9 @@ impl Display {
36
47
37
48
let ident = Ident :: new ( & var, span) ;
38
49
39
- let next = match read. chars ( ) . next ( ) {
40
- Some ( next) => next,
41
- None => return ,
42
- } ;
50
+ let next = peek_next ! ( read) ;
43
51
44
- let arg = if core :: cfg! ( feature = "std" ) && next == '}' {
52
+ let arg = if IS_STD && next == '}' {
45
53
quote_spanned ! ( span=> , ( & #ident) . get_display( ) )
46
54
} else {
47
55
quote_spanned ! ( span=> , #ident)
0 commit comments