mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Make #[max]
an attribute in newtype_index
This commit is contained in:
parent
93429948cf
commit
91c3c2040c
@ -3,7 +3,10 @@
|
||||
// Allows the macro invocation below to work
|
||||
use crate as rustc_index;
|
||||
|
||||
rustc_macros::newtype_index!(struct MyIdx { MAX = 0xFFFF_FFFA });
|
||||
rustc_macros::newtype_index! {
|
||||
#[max = 0xFFFF_FFFA]
|
||||
struct MyIdx { }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn index_size_is_optimized() {
|
||||
|
@ -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() {
|
||||
|
@ -11,9 +11,9 @@ rustc_index::newtype_index! {
|
||||
/// (which _*descend*_ from u32::MAX). Id value `0` (zero) represents a virtual counter with a
|
||||
/// constant value of `0`.
|
||||
#[derive(HashStable)]
|
||||
#[max = 0xFFFF_FFFF]
|
||||
pub struct ExpressionOperandId {
|
||||
DEBUG_FORMAT = "ExpressionOperandId({})",
|
||||
MAX = 0xFFFF_FFFF,
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,9 +33,9 @@ impl ExpressionOperandId {
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
#[derive(HashStable)]
|
||||
#[max = 0xFFFF_FFFF]
|
||||
pub struct CounterValueReference {
|
||||
DEBUG_FORMAT = "CounterValueReference({})",
|
||||
MAX = 0xFFFF_FFFF,
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,9 +57,9 @@ rustc_index::newtype_index! {
|
||||
///
|
||||
/// Values descend from u32::MAX.
|
||||
#[derive(HashStable)]
|
||||
#[max = 0xFFFF_FFFF]
|
||||
pub struct InjectedExpressionId {
|
||||
DEBUG_FORMAT = "InjectedExpressionId({})",
|
||||
MAX = 0xFFFF_FFFF,
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,9 +68,9 @@ rustc_index::newtype_index! {
|
||||
///
|
||||
/// Values ascend from 0.
|
||||
#[derive(HashStable)]
|
||||
#[max = 0xFFFF_FFFF]
|
||||
pub struct InjectedExpressionIndex {
|
||||
DEBUG_FORMAT = "InjectedExpressionIndex({})",
|
||||
MAX = 0xFFFF_FFFF,
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,9 +79,9 @@ rustc_index::newtype_index! {
|
||||
/// array position in the LLVM coverage map "Expressions" array, which is assembled during the
|
||||
/// "mapgen" process. They cannot be computed algorithmically, from the other `newtype_index`s.
|
||||
#[derive(HashStable)]
|
||||
#[max = 0xFFFF_FFFF]
|
||||
pub struct MappedExpressionIndex {
|
||||
DEBUG_FORMAT = "MappedExpressionIndex({})",
|
||||
MAX = 0xFFFF_FFFF,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,8 +27,8 @@ use smallvec::SmallVec;
|
||||
// unused so that we can store multiple index types in `CompressedHybridIndex`,
|
||||
// and use those bits to encode which index type it contains.
|
||||
rustc_index::newtype_index! {
|
||||
#[max = 0x7FFF_FFFF]
|
||||
pub struct SerializedDepNodeIndex {
|
||||
MAX = 0x7FFF_FFFF
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user