Skip to content

Commit cb2e4ee

Browse files
committed
Address review comments
1 parent db0b3bd commit cb2e4ee

File tree

1 file changed

+10
-24
lines changed

1 file changed

+10
-24
lines changed

compiler/rustc_macros/src/newtype.rs

+10-24
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl Parse for Newtype {
3737
braced!(body in input);
3838

3939
// Any additional `#[derive]` macro paths to apply
40-
let mut derive_paths: Option<Vec<Path>> = None;
40+
let mut derive_paths: Vec<Path> = Vec::new();
4141
let mut debug_format: Option<DebugFormat> = None;
4242
let mut max = None;
4343
let mut consts = Vec::new();
@@ -62,28 +62,23 @@ impl Parse for Newtype {
6262
let derives: Punctuated<Path, Token![,]> =
6363
derives.parse_terminated(Path::parse)?;
6464
try_comma()?;
65-
if let Some(old) = derive_paths.replace(derives.into_iter().collect()) {
66-
panic!("Specified multiple derives: {:?}", old);
67-
}
65+
derive_paths.extend(derives);
6866
continue;
6967
}
7068
if body.lookahead1().peek(kw::DEBUG_FORMAT) {
7169
body.parse::<kw::DEBUG_FORMAT>()?;
7270
body.parse::<Token![=]>()?;
73-
if body.lookahead1().peek(kw::custom) {
71+
let new_debug_format = if body.lookahead1().peek(kw::custom) {
7472
body.parse::<kw::custom>()?;
75-
if let Some(old) = debug_format.replace(DebugFormat::Custom) {
76-
panic!("Specified multiple debug format options: {:?}", old);
77-
}
73+
DebugFormat::Custom
7874
} else {
7975
let format_str: LitStr = body.parse()?;
80-
if let Some(old) =
81-
debug_format.replace(DebugFormat::Format(format_str.value()))
82-
{
83-
panic!("Specified multiple debug format options: {:?}", old);
84-
}
85-
}
76+
DebugFormat::Format(format_str.value())
77+
};
8678
try_comma()?;
79+
if let Some(old) = debug_format.replace(new_debug_format) {
80+
panic!("Specified multiple debug format options: {:?}", old);
81+
}
8782
continue;
8883
}
8984
if body.lookahead1().peek(kw::MAX) {
@@ -121,7 +116,6 @@ impl Parse for Newtype {
121116
}
122117
}
123118

124-
let derive_paths = derive_paths.unwrap_or_else(Vec::new);
125119
let debug_format = debug_format.unwrap_or(DebugFormat::Format("{}".to_string()));
126120
// shave off 256 indices at the end to allow space for packing these indices into enums
127121
let max = max.unwrap_or_else(|| Lit::Int(LitInt::new("0xFFFF_FF00", Span::call_site())));
@@ -158,21 +152,14 @@ impl Parse for Newtype {
158152

159153
Ok(Self(quote! {
160154
#(#attrs)*
161-
#[derive(Copy, PartialEq, Eq, Hash, PartialOrd, Ord, #(#derive_paths),*)]
155+
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, #(#derive_paths),*)]
162156
#[rustc_layout_scalar_valid_range_end(#max)]
163157
#vis struct #name {
164158
private: u32,
165159
}
166160

167161
#(#consts)*
168162

169-
impl Clone for #name {
170-
#[inline]
171-
fn clone(&self) -> Self {
172-
*self
173-
}
174-
}
175-
176163
impl #name {
177164
/// Maximum value the index can take, as a `u32`.
178165
#vis const MAX_AS_U32: u32 = #max;
@@ -313,7 +300,6 @@ impl Parse for Newtype {
313300

314301
#encodable_impls
315302
#debug_impl
316-
317303
}))
318304
}
319305
}

0 commit comments

Comments
 (0)