Skip to content

Commit 64c5f41

Browse files
committed
Update to syn 0.13
1 parent 113df80 commit 64c5f41

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

impl/Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ proc-macro = true
1616

1717
[dependencies]
1818
proc-macro-hack = "0.4"
19-
quote = "0.3"
20-
syn = "0.11"
19+
proc-macro2 = { version = "0.3", default-features = false }
20+
quote = { version = "0.5", default-features = false }
21+
syn = { version = "0.13", default-features = false, features = ["derive", "parsing", "printing"] }
2122
unindent = { version = "0.1", path = "../unindent" }

impl/src/lib.rs

+20-21
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@
1212

1313
#[cfg(feature = "unstable")]
1414
extern crate proc_macro;
15-
#[cfg(feature = "unstable")]
16-
use proc_macro::TokenStream;
1715

1816
#[cfg(not(feature = "unstable"))]
1917
#[macro_use]
2018
extern crate proc_macro_hack;
2119

20+
extern crate proc_macro2;
2221
extern crate syn;
2322

2423
#[macro_use]
@@ -27,14 +26,15 @@ extern crate quote;
2726
extern crate unindent;
2827
use unindent::*;
2928

30-
use syn::{TokenTree, Token, Lit};
29+
use proc_macro2::TokenStream;
30+
use syn::{Lit, LitStr, LitByteStr};
3131

3232
use std::fmt::Debug;
3333
use std::str::FromStr;
3434

3535
#[cfg(feature = "unstable")]
3636
#[proc_macro]
37-
pub fn indoc(input: TokenStream) -> TokenStream {
37+
pub fn indoc(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
3838
expand(&input)
3939
}
4040

@@ -50,34 +50,33 @@ fn expand<T, R>(input: &T) -> R
5050
R: FromStr,
5151
R::Err: Debug
5252
{
53-
let source = input.to_string();
54-
55-
let tts = syn::parse_token_trees(&source).unwrap();
53+
let source = input.to_string().parse::<TokenStream>().unwrap();
5654

57-
if tts.len() != 1 {
58-
panic!("argument must be a single string literal, but got {} arguments", tts.len());
55+
let len = source.clone().into_iter().count();
56+
if len != 1 {
57+
panic!("argument must be a single string literal, but got {} arguments", len);
5958
}
6059

61-
let tt = tts.into_iter().next().unwrap();
62-
63-
let mut lit = match tt {
64-
TokenTree::Token(Token::Literal(lit)) => lit,
65-
_ => {
60+
let lit = match syn::parse2::<Lit>(source) {
61+
Ok(lit) => lit,
62+
Err(_) => {
6663
panic!("argument must be a single string literal");
6764
}
6865
};
6966

70-
match lit {
71-
Lit::Str(ref mut s, _style) => {
72-
*s = unindent(s);
67+
let lit = match lit {
68+
Lit::Str(lit) => {
69+
let v = unindent(&lit.value());
70+
Lit::Str(LitStr::new(&v, lit.span()))
7371
}
74-
Lit::ByteStr(ref mut v, _style) => {
75-
*v = unindent_bytes(v);
72+
Lit::ByteStr(lit) => {
73+
let v = unindent_bytes(&lit.value());
74+
Lit::ByteStr(LitByteStr::new(&v, lit.span()))
7675
}
7776
_ => {
7877
panic!("argument must be a single string literal");
7978
}
80-
}
79+
};
8180

82-
quote!(#lit).parse().unwrap()
81+
quote!(#lit).to_string().parse().unwrap()
8382
}

0 commit comments

Comments
 (0)