Skip to content

Commit b18832e

Browse files
committed
Update cssparser-macros to syn 2
This makes no effort to gracefully handle errors that the old code didn't handle.
1 parent 8a24b11 commit b18832e

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ proc-macro = true
1414

1515
[dependencies]
1616
quote = "1"
17-
syn = {version = "1", features = ["full", "extra-traits"]}
17+
syn = {version = "2", features = ["full", "extra-traits"]}

macros/lib.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,18 @@ pub fn _cssparser_internal_max_len(input: TokenStream) -> TokenStream {
3838
.into()
3939
}
4040

41+
fn get_byte_from_lit(lit: &syn::Lit) -> u8 {
42+
if let syn::Lit::Byte(ref byte) = *lit {
43+
byte.value()
44+
} else {
45+
panic!("Found a pattern that wasn't a byte")
46+
}
47+
}
48+
4149
fn get_byte_from_expr_lit(expr: &syn::Expr) -> u8 {
4250
match *expr {
4351
syn::Expr::Lit(syn::ExprLit { ref lit, .. }) => {
44-
if let syn::Lit::Byte(ref byte) = *lit {
45-
byte.value()
46-
} else {
47-
panic!("Found a pattern that wasn't a byte")
48-
}
52+
get_byte_from_lit(lit)
4953
}
5054
_ => unreachable!(),
5155
}
@@ -59,15 +63,15 @@ fn parse_pat_to_table<'a>(
5963
table: &mut [u8; 256],
6064
) {
6165
match pat {
62-
&syn::Pat::Lit(syn::PatLit { ref expr, .. }) => {
63-
let value = get_byte_from_expr_lit(expr);
66+
&syn::Pat::Lit(syn::PatLit { ref lit, .. }) => {
67+
let value = get_byte_from_lit(lit);
6468
if table[value as usize] == 0 {
6569
table[value as usize] = case_id;
6670
}
6771
}
68-
&syn::Pat::Range(syn::PatRange { ref lo, ref hi, .. }) => {
69-
let lo = get_byte_from_expr_lit(lo);
70-
let hi = get_byte_from_expr_lit(hi);
72+
&syn::Pat::Range(syn::PatRange { ref start, ref end, .. }) => {
73+
let lo = get_byte_from_expr_lit(&start.as_ref().unwrap());
74+
let hi = get_byte_from_expr_lit(&end.as_ref().unwrap());
7175
for value in lo..hi {
7276
if table[value as usize] == 0 {
7377
table[value as usize] = case_id;

0 commit comments

Comments
 (0)