diff options
| author | bors <bors@rust-lang.org> | 2022-12-20 07:27:01 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-12-20 07:27:01 +0000 |
| commit | eb9e5e711d3eef1998ff24ac2bc57386662652e9 (patch) | |
| tree | 10d0607d0ca60fd9f25fedfde0cf1a025b9de3b1 /compiler/rustc_middle | |
| parent | 7f42e58effa3871dda6a41e250dea60cf88868ca (diff) | |
| parent | 8bfd6450c7b61ffee0fd7e21b538d00018a0e47e (diff) | |
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.
Diffstat (limited to 'compiler/rustc_middle')
| -rw-r--r-- | compiler/rustc_middle/src/middle/region.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/mir/coverage.rs | 42 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/mir/mod.rs | 32 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/mir/query.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/thir.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/structural_impls.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/sty.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/typeck_results.rs | 6 |
8 files changed, 47 insertions, 63 deletions
diff --git a/compiler/rustc_middle/src/middle/region.rs b/compiler/rustc_middle/src/middle/region.rs index c886175c6ea..94ca38c0e75 100644 --- a/compiler/rustc_middle/src/middle/region.rs +++ b/compiler/rustc_middle/src/middle/region.rs @@ -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` diff --git a/compiler/rustc_middle/src/mir/coverage.rs b/compiler/rustc_middle/src/mir/coverage.rs index 0b55757eb03..e7bb3ab0bc3 100644 --- a/compiler/rustc_middle/src/mir/coverage.rs +++ b/compiler/rustc_middle/src/mir/coverage.rs @@ -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 { diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index bdaa586c698..ffdf61d4244 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -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> { diff --git a/compiler/rustc_middle/src/mir/query.rs b/compiler/rustc_middle/src/mir/query.rs index efd7357afc4..a8a4532223c 100644 --- a/compiler/rustc_middle/src/mir/query.rs +++ b/compiler/rustc_middle/src/mir/query.rs @@ -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. diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index 8bef9dfe099..ac903010c8d 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -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 {} } )* diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 3c6800cf293..30073b541ec 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -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)) diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 66aeebab88b..e13b68c83b5 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -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)] diff --git a/compiler/rustc_middle/src/ty/typeck_results.rs b/compiler/rustc_middle/src/ty/typeck_results.rs index 4fe85d4366f..136a4906c58 100644 --- a/compiler/rustc_middle/src/ty/typeck_results.rs +++ b/compiler/rustc_middle/src/ty/typeck_results.rs @@ -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; } } |
