Skip to content

Commit c8a12ad

Browse files
committed
Address code review
1 parent 3abdabe commit c8a12ad

File tree

3 files changed

+45
-54
lines changed

3 files changed

+45
-54
lines changed

procedural-masquerade/lib.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -244,33 +244,33 @@ macro_rules! define_invoke_proc_macro {
244244
#[doc(hidden)]
245245
#[macro_export]
246246
macro_rules! $macro_name {
247-
($proc_macro_name: ident ! $paren: tt) => {
248-
#[derive($proc_macro_name)]
249-
#[allow(unused)]
250-
enum ProceduralMasqueradeDummyType {
251-
// The magic happens here.
252-
//
253-
// We use an `enum` with an explicit discriminant
254-
// because that is the only case where a type definition
255-
// can contain a (const) expression.
256-
//
257-
// `(0, "foo").0` evalutes to 0, with the `"foo"` part ignored.
258-
//
259-
// By the time the `#[proc_macro_derive]` function
260-
// implementing `#[derive($proc_macro_name)]` is called,
261-
// `$paren` has already been replaced with the input of this inner macro,
262-
// but `stringify!` has not been expanded yet.
263-
//
264-
// This how arbitrary tokens can be inserted
265-
// in the input to the `#[proc_macro_derive]` function.
266-
//
267-
// Later, `stringify!(...)` is expanded into a string literal
268-
// which is then ignored.
269-
// Using `stringify!` enables passing arbitrary tokens
270-
// rather than only what can be parsed as a const expression.
271-
Input = (0, stringify! $paren ).0
247+
($proc_macro_name: ident ! $paren: tt) => {
248+
#[derive($proc_macro_name)]
249+
#[allow(unused)]
250+
enum ProceduralMasqueradeDummyType {
251+
// The magic happens here.
252+
//
253+
// We use an `enum` with an explicit discriminant
254+
// because that is the only case where a type definition
255+
// can contain a (const) expression.
256+
//
257+
// `(0, "foo").0` evalutes to 0, with the `"foo"` part ignored.
258+
//
259+
// By the time the `#[proc_macro_derive]` function
260+
// implementing `#[derive($proc_macro_name)]` is called,
261+
// `$paren` has already been replaced with the input of this inner macro,
262+
// but `stringify!` has not been expanded yet.
263+
//
264+
// This how arbitrary tokens can be inserted
265+
// in the input to the `#[proc_macro_derive]` function.
266+
//
267+
// Later, `stringify!(...)` is expanded into a string literal
268+
// which is then ignored.
269+
// Using `stringify!` enables passing arbitrary tokens
270+
// rather than only what can be parsed as a const expression.
271+
Input = (0, stringify! $paren ).0
272+
}
273+
}
272274
}
273-
}
274-
}
275275
};
276276
}

src/from_bytes.rs

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,27 @@ where
3838
E: EncodingSupport,
3939
{
4040
// https://drafts.csswg.org/css-syntax/#the-input-byte-stream
41-
match protocol_encoding_label {
42-
None => (),
43-
Some(label) => match E::from_label(label) {
44-
None => (),
45-
Some(protocol_encoding) => return protocol_encoding,
46-
},
47-
}
41+
if let Some(label) = protocol_encoding_label {
42+
if let Some(protocol_encoding) = E::from_label(label) {
43+
return protocol_encoding;
44+
};
45+
};
46+
4847
let prefix = b"@charset \"";
4948
if css.starts_with(prefix) {
5049
let rest = &css[prefix.len()..];
51-
match rest.iter().position(|&b| b == b'"') {
52-
None => (),
53-
Some(label_length) => {
54-
if rest[label_length..].starts_with(b"\";") {
55-
let label = &rest[..label_length];
56-
match E::from_label(label) {
57-
None => (),
58-
Some(charset_encoding) => {
59-
if E::is_utf16_be_or_le(&charset_encoding) {
60-
return E::utf8();
61-
} else {
62-
return charset_encoding;
63-
}
64-
},
50+
if let Some(label_length) = rest.iter().position(|&b| b == b'"') {
51+
if rest[label_length..].starts_with(b"\";") {
52+
let label = &rest[..label_length];
53+
if let Some(charset_encoding) = E::from_label(label) {
54+
if E::is_utf16_be_or_le(&charset_encoding) {
55+
return E::utf8();
56+
} else {
57+
return charset_encoding;
6558
}
66-
}
67-
},
68-
}
59+
};
60+
}
61+
};
6962
}
7063
environment_encoding.unwrap_or_else(E::utf8)
7164
}

src/parser.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,7 @@ impl<'i: 't, 't> Parser<'i, 't> {
354354
..
355355
}) => Ok(()),
356356
Err(e) => unreachable!("Unexpected error encountered: {:?}", e),
357-
Ok(t) => Err(start
358-
.source_location()
359-
.new_basic_unexpected_token_error(t.clone())),
357+
Ok(t) => Err(start.source_location().new_basic_unexpected_token_error(t.clone())),
360358
};
361359
self.reset(&start);
362360
result

0 commit comments

Comments
 (0)