Make #[max] an attribute in newtype_index

This commit is contained in:
Nilstrieb 2022-12-18 21:22:14 +01:00
parent 93429948cf
commit 91c3c2040c
4 changed files with 21 additions and 17 deletions

View file

@ -59,6 +59,17 @@ impl Parse for Newtype {
ord = false;
false
}
"max" => {
let Ok(Meta::NameValue(literal) )= attr.parse_meta() else {
panic!("#[max = NUMBER] attribute requires max value");
};
if let Some(old) = max.replace(literal.lit) {
panic!("Specified multiple MAX: {:?}", old);
}
false
}
_ => true,
},
_ => true,
@ -84,16 +95,6 @@ impl Parse for Newtype {
}
continue;
}
if body.lookahead1().peek(kw::MAX) {
body.parse::<kw::MAX>()?;
body.parse::<Token![=]>()?;
let val: Lit = body.parse()?;
try_comma()?;
if let Some(old) = max.replace(val) {
panic!("Specified multiple MAX: {:?}", old);
}
continue;
}
// We've parsed everything that the user provided, so we're done
if body.is_empty() {