Auto merge of #105880 - Nilstrieb:make-newtypes-less-not-rust, r=oli-obk
Improve syntax of `newtype_index` This makes it more like proper Rust and also makes the implementation a lot simpler. Mostly just turns weird flags in the body into proper attributes. It should probably also be converted to an attribute macro instead of function-like, but that can be done in a future PR.
This commit is contained in:
commit
eb9e5e711d
37 changed files with 182 additions and 268 deletions
|
@ -147,9 +147,8 @@ rustc_index::newtype_index! {
|
|||
///
|
||||
/// * The subscope with `first_statement_index == 1` is scope of `c`,
|
||||
/// and thus does not include EXPR_2, but covers the `...`.
|
||||
pub struct FirstStatementIndex {
|
||||
derive [HashStable]
|
||||
}
|
||||
#[derive(HashStable)]
|
||||
pub struct FirstStatementIndex {}
|
||||
}
|
||||
|
||||
// compilation error if size of `ScopeData` is not the same as a `u32`
|
||||
|
|
|
@ -10,10 +10,10 @@ rustc_index::newtype_index! {
|
|||
/// CounterValueReference.as_u32() (which ascend from 1) or an ExpressionOperandId.as_u32()
|
||||
/// (which _*descend*_ from u32::MAX). Id value `0` (zero) represents a virtual counter with a
|
||||
/// constant value of `0`.
|
||||
#[derive(HashStable)]
|
||||
#[max = 0xFFFF_FFFF]
|
||||
#[debug_format = "ExpressionOperandId({})"]
|
||||
pub struct ExpressionOperandId {
|
||||
derive [HashStable]
|
||||
DEBUG_FORMAT = "ExpressionOperandId({})",
|
||||
MAX = 0xFFFF_FFFF,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,11 +32,10 @@ impl ExpressionOperandId {
|
|||
}
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
pub struct CounterValueReference {
|
||||
derive [HashStable]
|
||||
DEBUG_FORMAT = "CounterValueReference({})",
|
||||
MAX = 0xFFFF_FFFF,
|
||||
}
|
||||
#[derive(HashStable)]
|
||||
#[max = 0xFFFF_FFFF]
|
||||
#[debug_format = "CounterValueReference({})"]
|
||||
pub struct CounterValueReference {}
|
||||
}
|
||||
|
||||
impl CounterValueReference {
|
||||
|
@ -56,33 +55,30 @@ rustc_index::newtype_index! {
|
|||
/// InjectedExpressionId.as_u32() converts to ExpressionOperandId.as_u32()
|
||||
///
|
||||
/// Values descend from u32::MAX.
|
||||
pub struct InjectedExpressionId {
|
||||
derive [HashStable]
|
||||
DEBUG_FORMAT = "InjectedExpressionId({})",
|
||||
MAX = 0xFFFF_FFFF,
|
||||
}
|
||||
#[derive(HashStable)]
|
||||
#[max = 0xFFFF_FFFF]
|
||||
#[debug_format = "InjectedExpressionId({})"]
|
||||
pub struct InjectedExpressionId {}
|
||||
}
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
/// InjectedExpressionIndex.as_u32() translates to u32::MAX - ExpressionOperandId.as_u32()
|
||||
///
|
||||
/// Values ascend from 0.
|
||||
pub struct InjectedExpressionIndex {
|
||||
derive [HashStable]
|
||||
DEBUG_FORMAT = "InjectedExpressionIndex({})",
|
||||
MAX = 0xFFFF_FFFF,
|
||||
}
|
||||
#[derive(HashStable)]
|
||||
#[max = 0xFFFF_FFFF]
|
||||
#[debug_format = "InjectedExpressionIndex({})"]
|
||||
pub struct InjectedExpressionIndex {}
|
||||
}
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
/// MappedExpressionIndex values ascend from zero, and are recalculated indexes based on their
|
||||
/// 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.
|
||||
pub struct MappedExpressionIndex {
|
||||
derive [HashStable]
|
||||
DEBUG_FORMAT = "MappedExpressionIndex({})",
|
||||
MAX = 0xFFFF_FFFF,
|
||||
}
|
||||
#[derive(HashStable)]
|
||||
#[max = 0xFFFF_FFFF]
|
||||
#[debug_format = "MappedExpressionIndex({})"]
|
||||
pub struct MappedExpressionIndex {}
|
||||
}
|
||||
|
||||
impl From<CounterValueReference> for ExpressionOperandId {
|
||||
|
|
|
@ -654,10 +654,10 @@ impl SourceInfo {
|
|||
// Variables and temps
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
#[derive(HashStable)]
|
||||
#[debug_format = "_{}"]
|
||||
pub struct Local {
|
||||
derive [HashStable]
|
||||
DEBUG_FORMAT = "_{}",
|
||||
const RETURN_PLACE = 0,
|
||||
const RETURN_PLACE = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1146,10 +1146,10 @@ rustc_index::newtype_index! {
|
|||
/// https://rustc-dev-guide.rust-lang.org/appendix/background.html#what-is-a-dataflow-analysis
|
||||
/// [`CriticalCallEdges`]: ../../rustc_const_eval/transform/add_call_guards/enum.AddCallGuards.html#variant.CriticalCallEdges
|
||||
/// [guide-mir]: https://rustc-dev-guide.rust-lang.org/mir/
|
||||
#[derive(HashStable)]
|
||||
#[debug_format = "bb{}"]
|
||||
pub struct BasicBlock {
|
||||
derive [HashStable]
|
||||
DEBUG_FORMAT = "bb{}",
|
||||
const START_BLOCK = 0,
|
||||
const START_BLOCK = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1530,10 +1530,9 @@ rustc_index::newtype_index! {
|
|||
/// [wrapper]: https://rustc-dev-guide.rust-lang.org/appendix/glossary.html#newtype
|
||||
/// [CFG]: https://rustc-dev-guide.rust-lang.org/appendix/background.html#cfg
|
||||
/// [mir-datatypes]: https://rustc-dev-guide.rust-lang.org/mir/index.html#mir-data-types
|
||||
pub struct Field {
|
||||
derive [HashStable]
|
||||
DEBUG_FORMAT = "field[{}]"
|
||||
}
|
||||
#[derive(HashStable)]
|
||||
#[debug_format = "field[{}]"]
|
||||
pub struct Field {}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
|
@ -1757,10 +1756,10 @@ impl Debug for Place<'_> {
|
|||
// Scopes
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
#[derive(HashStable)]
|
||||
#[debug_format = "scope[{}]"]
|
||||
pub struct SourceScope {
|
||||
derive [HashStable]
|
||||
DEBUG_FORMAT = "scope[{}]",
|
||||
const OUTERMOST_SOURCE_SCOPE = 0,
|
||||
const OUTERMOST_SOURCE_SCOPE = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2755,10 +2754,9 @@ impl<'tcx> TypeVisitable<'tcx> for UserTypeProjection {
|
|||
}
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
pub struct Promoted {
|
||||
derive [HashStable]
|
||||
DEBUG_FORMAT = "promoted[{}]"
|
||||
}
|
||||
#[derive(HashStable)]
|
||||
#[debug_format = "promoted[{}]"]
|
||||
pub struct Promoted {}
|
||||
}
|
||||
|
||||
impl<'tcx> Debug for Constant<'tcx> {
|
||||
|
|
|
@ -130,10 +130,9 @@ pub struct UnsafetyCheckResult {
|
|||
}
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
pub struct GeneratorSavedLocal {
|
||||
derive [HashStable]
|
||||
DEBUG_FORMAT = "_{}",
|
||||
}
|
||||
#[derive(HashStable)]
|
||||
#[debug_format = "_{}"]
|
||||
pub struct GeneratorSavedLocal {}
|
||||
}
|
||||
|
||||
/// The layout of generator state.
|
||||
|
|
|
@ -35,9 +35,8 @@ macro_rules! thir_with_elements {
|
|||
$(
|
||||
newtype_index! {
|
||||
#[derive(HashStable)]
|
||||
pub struct $id {
|
||||
DEBUG_FORMAT = $format
|
||||
}
|
||||
#[debug_format = $format]
|
||||
pub struct $id {}
|
||||
}
|
||||
)*
|
||||
|
||||
|
|
|
@ -99,12 +99,6 @@ impl<'tcx> fmt::Debug for ty::ConstVid<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for ty::RegionVid {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "'_#{}r", self.index())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> fmt::Debug for ty::TraitRef<'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
with_no_trimmed_paths!(fmt::Display::fmt(self, f))
|
||||
|
|
|
@ -1378,9 +1378,8 @@ pub struct ConstVid<'tcx> {
|
|||
rustc_index::newtype_index! {
|
||||
/// A **region** (lifetime) **v**ariable **ID**.
|
||||
#[derive(HashStable)]
|
||||
pub struct RegionVid {
|
||||
DEBUG_FORMAT = custom,
|
||||
}
|
||||
#[debug_format = "'_#{}r"]
|
||||
pub struct RegionVid {}
|
||||
}
|
||||
|
||||
impl Atom for RegionVid {
|
||||
|
@ -1391,7 +1390,7 @@ impl Atom for RegionVid {
|
|||
|
||||
rustc_index::newtype_index! {
|
||||
#[derive(HashStable)]
|
||||
pub struct BoundVar { .. }
|
||||
pub struct BoundVar {}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]
|
||||
|
|
|
@ -608,10 +608,10 @@ impl<'a, V> LocalTableInContextMut<'a, V> {
|
|||
}
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
#[derive(HashStable)]
|
||||
#[debug_format = "UserType({})"]
|
||||
pub struct UserTypeAnnotationIndex {
|
||||
derive [HashStable]
|
||||
DEBUG_FORMAT = "UserType({})",
|
||||
const START_INDEX = 0,
|
||||
const START_INDEX = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue