Skip to content

Commit eb9e5e7

Browse files
committed
Auto merge of rust-lang#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.
2 parents 7f42e58 + 8bfd645 commit eb9e5e7

File tree

37 files changed

+182
-268
lines changed

37 files changed

+182
-268
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2554,10 +2554,9 @@ pub enum AttrStyle {
25542554
}
25552555

25562556
rustc_index::newtype_index! {
2557-
pub struct AttrId {
2558-
ENCODABLE = custom
2559-
DEBUG_FORMAT = "AttrId({})"
2560-
}
2557+
#[custom_encodable]
2558+
#[debug_format = "AttrId({})]"]
2559+
pub struct AttrId {}
25612560
}
25622561

25632562
impl<S: Encoder> Encodable<S> for AttrId {

compiler/rustc_ast/src/node_id.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ rustc_index::newtype_index! {
88
/// This is later turned into [`DefId`] and `HirId` for the HIR.
99
///
1010
/// [`DefId`]: rustc_span::def_id::DefId
11-
pub struct NodeId {
12-
DEBUG_FORMAT = "NodeId({})"
13-
}
11+
#[debug_format = "NodeId({})"]
12+
pub struct NodeId {}
1413
}
1514

1615
rustc_data_structures::define_id_collections!(NodeMap, NodeSet, NodeMapEntry, NodeId);

compiler/rustc_borrowck/src/constraints/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,11 @@ impl<'tcx> fmt::Debug for OutlivesConstraint<'tcx> {
115115
}
116116

117117
rustc_index::newtype_index! {
118-
pub struct OutlivesConstraintIndex {
119-
DEBUG_FORMAT = "OutlivesConstraintIndex({})"
120-
}
118+
#[debug_format = "OutlivesConstraintIndex({})"]
119+
pub struct OutlivesConstraintIndex {}
121120
}
122121

123122
rustc_index::newtype_index! {
124-
pub struct ConstraintSccIndex {
125-
DEBUG_FORMAT = "ConstraintSccIndex({})"
126-
}
123+
#[debug_format = "ConstraintSccIndex({})"]
124+
pub struct ConstraintSccIndex {}
127125
}

compiler/rustc_borrowck/src/dataflow.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,8 @@ impl_visitable! {
108108
}
109109

110110
rustc_index::newtype_index! {
111-
pub struct BorrowIndex {
112-
DEBUG_FORMAT = "bw{}"
113-
}
111+
#[debug_format = "bw{}"]
112+
pub struct BorrowIndex {}
114113
}
115114

116115
/// `Borrows` stores the data used in the analyses that track the flow

compiler/rustc_borrowck/src/location.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ pub struct LocationTable {
2020
}
2121

2222
rustc_index::newtype_index! {
23-
pub struct LocationIndex {
24-
DEBUG_FORMAT = "LocationIndex({})"
25-
}
23+
#[debug_format = "LocationIndex({})"]
24+
pub struct LocationIndex {}
2625
}
2726

2827
#[derive(Copy, Clone, Debug)]

compiler/rustc_borrowck/src/member_constraints.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ pub(crate) struct NllMemberConstraint<'tcx> {
5555
}
5656

5757
rustc_index::newtype_index! {
58-
pub(crate) struct NllMemberConstraintIndex {
59-
DEBUG_FORMAT = "MemberConstraintIndex({})"
60-
}
58+
#[debug_format = "MemberConstraintIndex({})"]
59+
pub(crate) struct NllMemberConstraintIndex {}
6160
}
6261

6362
impl Default for MemberConstraintSet<'_, ty::RegionVid> {

compiler/rustc_borrowck/src/region_infer/values.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,14 @@ impl RegionValueElements {
9090
rustc_index::newtype_index! {
9191
/// A single integer representing a `Location` in the MIR control-flow
9292
/// graph. Constructed efficiently from `RegionValueElements`.
93-
pub struct PointIndex { DEBUG_FORMAT = "PointIndex({})" }
93+
#[debug_format = "PointIndex({})"]
94+
pub struct PointIndex {}
9495
}
9596

9697
rustc_index::newtype_index! {
9798
/// A single integer representing a `ty::Placeholder`.
98-
pub struct PlaceholderIndex { DEBUG_FORMAT = "PlaceholderIndex({})" }
99+
#[debug_format = "PlaceholderIndex({})"]
100+
pub struct PlaceholderIndex {}
99101
}
100102

101103
/// An individual element in a region value -- the value of a

compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct Appearance {
4646
}
4747

4848
rustc_index::newtype_index! {
49-
pub struct AppearanceIndex { .. }
49+
pub struct AppearanceIndex {}
5050
}
5151

5252
impl vll::LinkElem for Appearance {

compiler/rustc_data_structures/src/graph/dominators/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct PreOrderFrame<Iter> {
2222
}
2323

2424
rustc_index::newtype_index! {
25-
struct PreorderIndex { .. }
25+
struct PreorderIndex {}
2626
}
2727

2828
pub fn dominators<G: ControlFlowGraph>(graph: G) -> Dominators<G::Node> {

compiler/rustc_hir/src/hir_id.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ rustc_index::newtype_index! {
138138
/// an "item-like" to something else can be implemented by a `Vec` instead of a
139139
/// tree or hash map.
140140
#[derive(HashStable_Generic)]
141-
pub struct ItemLocalId { .. }
141+
pub struct ItemLocalId {}
142142
}
143143

144144
impl ItemLocalId {

0 commit comments

Comments
 (0)