Skip to content

Commit 3925ce9

Browse files
committed
fix compat with 1.31
1 parent a20371a commit 3925ce9

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/fmt.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@ use proc_macro2::TokenStream;
33
use quote::quote_spanned;
44
use 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+
620
impl 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

Comments
 (0)