diff options
| -rw-r--r-- | compiler/rustc_index/src/vec/tests.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_macros/src/newtype.rs | 21 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/mir/coverage.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_query_system/src/dep_graph/serialized.rs | 2 |
4 files changed, 21 insertions, 17 deletions
diff --git a/compiler/rustc_index/src/vec/tests.rs b/compiler/rustc_index/src/vec/tests.rs index 915d2e8bcb3..e72863f6de1 100644 --- a/compiler/rustc_index/src/vec/tests.rs +++ b/compiler/rustc_index/src/vec/tests.rs @@ -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() { diff --git a/compiler/rustc_macros/src/newtype.rs b/compiler/rustc_macros/src/newtype.rs index 59cedef08ea..99f3f638d2f 100644 --- a/compiler/rustc_macros/src/newtype.rs +++ b/compiler/rustc_macros/src/newtype.rs @@ -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() { diff --git a/compiler/rustc_middle/src/mir/coverage.rs b/compiler/rustc_middle/src/mir/coverage.rs index 173c8967eec..3025e2dd134 100644 --- a/compiler/rustc_middle/src/mir/coverage.rs +++ b/compiler/rustc_middle/src/mir/coverage.rs @@ -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, } } diff --git a/compiler/rustc_query_system/src/dep_graph/serialized.rs b/compiler/rustc_query_system/src/dep_graph/serialized.rs index d292f4beef2..fbc0aeb6c80 100644 --- a/compiler/rustc_query_system/src/dep_graph/serialized.rs +++ b/compiler/rustc_query_system/src/dep_graph/serialized.rs @@ -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 } } |
