未验证 提交 01efe6d5 编写于 作者: A Aaron Hill

Address review comments

上级 e686aee4
...@@ -37,7 +37,7 @@ fn parse(input: ParseStream<'_>) -> Result<Self> { ...@@ -37,7 +37,7 @@ fn parse(input: ParseStream<'_>) -> Result<Self> {
braced!(body in input); braced!(body in input);
// Any additional `#[derive]` macro paths to apply // Any additional `#[derive]` macro paths to apply
let mut derive_paths: Option<Vec<Path>> = None; let mut derive_paths: Vec<Path> = Vec::new();
let mut debug_format: Option<DebugFormat> = None; let mut debug_format: Option<DebugFormat> = None;
let mut max = None; let mut max = None;
let mut consts = Vec::new(); let mut consts = Vec::new();
...@@ -62,28 +62,23 @@ fn parse(input: ParseStream<'_>) -> Result<Self> { ...@@ -62,28 +62,23 @@ fn parse(input: ParseStream<'_>) -> Result<Self> {
let derives: Punctuated<Path, Token![,]> = let derives: Punctuated<Path, Token![,]> =
derives.parse_terminated(Path::parse)?; derives.parse_terminated(Path::parse)?;
try_comma()?; try_comma()?;
if let Some(old) = derive_paths.replace(derives.into_iter().collect()) { derive_paths.extend(derives);
panic!("Specified multiple derives: {:?}", old);
}
continue; continue;
} }
if body.lookahead1().peek(kw::DEBUG_FORMAT) { if body.lookahead1().peek(kw::DEBUG_FORMAT) {
body.parse::<kw::DEBUG_FORMAT>()?; body.parse::<kw::DEBUG_FORMAT>()?;
body.parse::<Token![=]>()?; body.parse::<Token![=]>()?;
if body.lookahead1().peek(kw::custom) { let new_debug_format = if body.lookahead1().peek(kw::custom) {
body.parse::<kw::custom>()?; body.parse::<kw::custom>()?;
if let Some(old) = debug_format.replace(DebugFormat::Custom) { DebugFormat::Custom
panic!("Specified multiple debug format options: {:?}", old);
}
} else { } else {
let format_str: LitStr = body.parse()?; let format_str: LitStr = body.parse()?;
if let Some(old) = DebugFormat::Format(format_str.value())
debug_format.replace(DebugFormat::Format(format_str.value())) };
{
panic!("Specified multiple debug format options: {:?}", old);
}
}
try_comma()?; try_comma()?;
if let Some(old) = debug_format.replace(new_debug_format) {
panic!("Specified multiple debug format options: {:?}", old);
}
continue; continue;
} }
if body.lookahead1().peek(kw::MAX) { if body.lookahead1().peek(kw::MAX) {
...@@ -121,7 +116,6 @@ fn parse(input: ParseStream<'_>) -> Result<Self> { ...@@ -121,7 +116,6 @@ fn parse(input: ParseStream<'_>) -> Result<Self> {
} }
} }
let derive_paths = derive_paths.unwrap_or_else(Vec::new);
let debug_format = debug_format.unwrap_or(DebugFormat::Format("{}".to_string())); let debug_format = debug_format.unwrap_or(DebugFormat::Format("{}".to_string()));
// shave off 256 indices at the end to allow space for packing these indices into enums // shave off 256 indices at the end to allow space for packing these indices into enums
let max = max.unwrap_or_else(|| Lit::Int(LitInt::new("0xFFFF_FF00", Span::call_site()))); let max = max.unwrap_or_else(|| Lit::Int(LitInt::new("0xFFFF_FF00", Span::call_site())));
...@@ -158,7 +152,7 @@ fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ...@@ -158,7 +152,7 @@ fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
Ok(Self(quote! { Ok(Self(quote! {
#(#attrs)* #(#attrs)*
#[derive(Copy, PartialEq, Eq, Hash, PartialOrd, Ord, #(#derive_paths),*)] #[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, #(#derive_paths),*)]
#[rustc_layout_scalar_valid_range_end(#max)] #[rustc_layout_scalar_valid_range_end(#max)]
#vis struct #name { #vis struct #name {
private: u32, private: u32,
...@@ -166,13 +160,6 @@ fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ...@@ -166,13 +160,6 @@ fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
#(#consts)* #(#consts)*
impl Clone for #name {
#[inline]
fn clone(&self) -> Self {
*self
}
}
impl #name { impl #name {
/// Maximum value the index can take, as a `u32`. /// Maximum value the index can take, as a `u32`.
#vis const MAX_AS_U32: u32 = #max; #vis const MAX_AS_U32: u32 = #max;
...@@ -313,7 +300,6 @@ fn from(value: u32) -> Self { ...@@ -313,7 +300,6 @@ fn from(value: u32) -> Self {
#encodable_impls #encodable_impls
#debug_impl #debug_impl
})) }))
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册