Skip to content

Commit 8bfd645

Browse files
committed
A few small cleanups for newtype_index
Remove the `..` from the body, only a few invocations used it and it's inconsistent with rust syntax. Use `;` instead of `,` between consts. As the Rust syntax gods inteded.
1 parent d679764 commit 8bfd645

File tree

35 files changed

+68
-115
lines changed

35 files changed

+68
-115
lines changed

compiler/rustc_ast/src/ast.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2556,8 +2556,7 @@ pub enum AttrStyle {
25562556
rustc_index::newtype_index! {
25572557
#[custom_encodable]
25582558
#[debug_format = "AttrId({})]"]
2559-
pub struct AttrId {
2560-
}
2559+
pub struct AttrId {}
25612560
}
25622561

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

compiler/rustc_ast/src/node_id.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ rustc_index::newtype_index! {
99
///
1010
/// [`DefId`]: rustc_span::def_id::DefId
1111
#[debug_format = "NodeId({})"]
12-
pub struct NodeId {
13-
}
12+
pub struct NodeId {}
1413
}
1514

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

compiler/rustc_borrowck/src/constraints/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,10 @@ impl<'tcx> fmt::Debug for OutlivesConstraint<'tcx> {
116116

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

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

compiler/rustc_borrowck/src/dataflow.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ impl_visitable! {
109109

110110
rustc_index::newtype_index! {
111111
#[debug_format = "bw{}"]
112-
pub struct BorrowIndex {
113-
}
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

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ pub struct LocationTable {
2121

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

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

compiler/rustc_borrowck/src/member_constraints.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ pub(crate) struct NllMemberConstraint<'tcx> {
5656

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

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

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

+1-1
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

+1-1
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

+1-1
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 {

compiler/rustc_hir_analysis/src/coherence/inherent_impls_overlap.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
199199

200200
rustc_index::newtype_index! {
201201
#[custom_encodable]
202-
pub struct RegionId {
203-
}
202+
pub struct RegionId {}
204203
}
204+
205205
struct ConnectedRegion {
206206
idents: SmallVec<[Symbol; 8]>,
207207
impl_blocks: FxHashSet<usize>,

compiler/rustc_hir_typeck/src/fn_ctxt/arg_matrix.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ use rustc_middle::ty::error::TypeError;
55

66
rustc_index::newtype_index! {
77
#[debug_format = "ExpectedIdx({})"]
8-
pub(crate) struct ExpectedIdx {
9-
}
8+
pub(crate) struct ExpectedIdx {}
109
}
1110

1211
rustc_index::newtype_index! {
1312
#[debug_format = "ProvidedIdx({})"]
14-
pub(crate) struct ProvidedIdx {
15-
}
13+
pub(crate) struct ProvidedIdx {}
1614
}
1715

1816
impl ExpectedIdx {

compiler/rustc_hir_typeck/src/generator_interior/drop_ranges/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,12 @@ fn for_each_consumable<'tcx>(hir: Map<'tcx>, place: TrackedValue, mut f: impl Fn
9797

9898
rustc_index::newtype_index! {
9999
#[debug_format = "id({})"]
100-
pub struct PostOrderId {
101-
}
100+
pub struct PostOrderId {}
102101
}
103102

104103
rustc_index::newtype_index! {
105104
#[debug_format = "hidx({})"]
106-
pub struct TrackedValueIndex {
107-
}
105+
pub struct TrackedValueIndex {}
108106
}
109107

110108
/// Identifies a value whose drop state we need to track.

compiler/rustc_index/src/vec/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate as rustc_index;
55

66
rustc_macros::newtype_index! {
77
#[max = 0xFFFF_FFFA]
8-
struct MyIdx { }
8+
struct MyIdx {}
99
}
1010

1111
#[test]

compiler/rustc_infer/src/infer/region_constraints/leak_check.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -358,14 +358,12 @@ impl<'tcx> SccUniverse<'tcx> {
358358

359359
rustc_index::newtype_index! {
360360
#[debug_format = "LeakCheckNode({})"]
361-
struct LeakCheckNode {
362-
}
361+
struct LeakCheckNode {}
363362
}
364363

365364
rustc_index::newtype_index! {
366365
#[debug_format = "LeakCheckScc({})"]
367-
struct LeakCheckScc {
368-
}
366+
struct LeakCheckScc {}
369367
}
370368

371369
/// Represents the graph of constraints. For each `R1: R2` constraint we create

compiler/rustc_lint/src/levels.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct LintLevelSets {
4141
rustc_index::newtype_index! {
4242
#[custom_encodable] // we don't need encoding
4343
struct LintStackIndex {
44-
const COMMAND_LINE = 0,
44+
const COMMAND_LINE = 0;
4545
}
4646
}
4747

compiler/rustc_macros/src/newtype.rs

+13-25
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ impl Parse for Newtype {
2525
let mut encodable = true;
2626
let mut ord = true;
2727

28-
// Parse an optional trailing comma
29-
let try_comma = || -> Result<()> {
30-
if body.lookahead1().peek(Token![,]) {
31-
body.parse::<Token![,]>()?;
32-
}
33-
Ok(())
34-
};
35-
3628
attrs.retain(|attr| match attr.path.get_ident() {
3729
Some(ident) => match &*ident.to_string() {
3830
"custom_encodable" => {
@@ -70,24 +62,20 @@ impl Parse for Newtype {
7062
_ => true,
7163
});
7264

73-
if body.lookahead1().peek(Token![..]) {
74-
body.parse::<Token![..]>()?;
75-
} else {
76-
loop {
77-
// We've parsed everything that the user provided, so we're done
78-
if body.is_empty() {
79-
break;
80-
}
81-
82-
// Otherwise, we are parsing a user-defined constant
83-
let const_attrs = body.call(Attribute::parse_outer)?;
84-
body.parse::<Token![const]>()?;
85-
let const_name: Ident = body.parse()?;
86-
body.parse::<Token![=]>()?;
87-
let const_val: Expr = body.parse()?;
88-
try_comma()?;
89-
consts.push(quote! { #(#const_attrs)* #vis const #const_name: #name = #name::from_u32(#const_val); });
65+
loop {
66+
// We've parsed everything that the user provided, so we're done
67+
if body.is_empty() {
68+
break;
9069
}
70+
71+
// Otherwise, we are parsing a user-defined constant
72+
let const_attrs = body.call(Attribute::parse_outer)?;
73+
body.parse::<Token![const]>()?;
74+
let const_name: Ident = body.parse()?;
75+
body.parse::<Token![=]>()?;
76+
let const_val: Expr = body.parse()?;
77+
body.parse::<Token![;]>()?;
78+
consts.push(quote! { #(#const_attrs)* #vis const #const_name: #name = #name::from_u32(#const_val); });
9179
}
9280

9381
let debug_format =

compiler/rustc_middle/src/middle/region.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ rustc_index::newtype_index! {
148148
/// * The subscope with `first_statement_index == 1` is scope of `c`,
149149
/// and thus does not include EXPR_2, but covers the `...`.
150150
#[derive(HashStable)]
151-
pub struct FirstStatementIndex {
152-
}
151+
pub struct FirstStatementIndex {}
153152
}
154153

155154
// compilation error if size of `ScopeData` is not the same as a `u32`

compiler/rustc_middle/src/mir/coverage.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ rustc_index::newtype_index! {
3535
#[derive(HashStable)]
3636
#[max = 0xFFFF_FFFF]
3737
#[debug_format = "CounterValueReference({})"]
38-
pub struct CounterValueReference {
39-
}
38+
pub struct CounterValueReference {}
4039
}
4140

4241
impl CounterValueReference {
@@ -59,8 +58,7 @@ rustc_index::newtype_index! {
5958
#[derive(HashStable)]
6059
#[max = 0xFFFF_FFFF]
6160
#[debug_format = "InjectedExpressionId({})"]
62-
pub struct InjectedExpressionId {
63-
}
61+
pub struct InjectedExpressionId {}
6462
}
6563

6664
rustc_index::newtype_index! {
@@ -70,8 +68,7 @@ rustc_index::newtype_index! {
7068
#[derive(HashStable)]
7169
#[max = 0xFFFF_FFFF]
7270
#[debug_format = "InjectedExpressionIndex({})"]
73-
pub struct InjectedExpressionIndex {
74-
}
71+
pub struct InjectedExpressionIndex {}
7572
}
7673

7774
rustc_index::newtype_index! {
@@ -81,8 +78,7 @@ rustc_index::newtype_index! {
8178
#[derive(HashStable)]
8279
#[max = 0xFFFF_FFFF]
8380
#[debug_format = "MappedExpressionIndex({})"]
84-
pub struct MappedExpressionIndex {
85-
}
81+
pub struct MappedExpressionIndex {}
8682
}
8783

8884
impl From<CounterValueReference> for ExpressionOperandId {

compiler/rustc_middle/src/mir/mod.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ rustc_index::newtype_index! {
657657
#[derive(HashStable)]
658658
#[debug_format = "_{}"]
659659
pub struct Local {
660-
const RETURN_PLACE = 0,
660+
const RETURN_PLACE = 0;
661661
}
662662
}
663663

@@ -1149,7 +1149,7 @@ rustc_index::newtype_index! {
11491149
#[derive(HashStable)]
11501150
#[debug_format = "bb{}"]
11511151
pub struct BasicBlock {
1152-
const START_BLOCK = 0,
1152+
const START_BLOCK = 0;
11531153
}
11541154
}
11551155

@@ -1532,8 +1532,7 @@ rustc_index::newtype_index! {
15321532
/// [mir-datatypes]: https://rustc-dev-guide.rust-lang.org/mir/index.html#mir-data-types
15331533
#[derive(HashStable)]
15341534
#[debug_format = "field[{}]"]
1535-
pub struct Field {
1536-
}
1535+
pub struct Field {}
15371536
}
15381537

15391538
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
@@ -1760,7 +1759,7 @@ rustc_index::newtype_index! {
17601759
#[derive(HashStable)]
17611760
#[debug_format = "scope[{}]"]
17621761
pub struct SourceScope {
1763-
const OUTERMOST_SOURCE_SCOPE = 0,
1762+
const OUTERMOST_SOURCE_SCOPE = 0;
17641763
}
17651764
}
17661765

@@ -2757,8 +2756,7 @@ impl<'tcx> TypeVisitable<'tcx> for UserTypeProjection {
27572756
rustc_index::newtype_index! {
27582757
#[derive(HashStable)]
27592758
#[debug_format = "promoted[{}]"]
2760-
pub struct Promoted {
2761-
}
2759+
pub struct Promoted {}
27622760
}
27632761

27642762
impl<'tcx> Debug for Constant<'tcx> {

compiler/rustc_middle/src/mir/query.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ pub struct UnsafetyCheckResult {
132132
rustc_index::newtype_index! {
133133
#[derive(HashStable)]
134134
#[debug_format = "_{}"]
135-
pub struct GeneratorSavedLocal {
136-
}
135+
pub struct GeneratorSavedLocal {}
137136
}
138137

139138
/// The layout of generator state.

compiler/rustc_middle/src/thir.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ macro_rules! thir_with_elements {
3636
newtype_index! {
3737
#[derive(HashStable)]
3838
#[debug_format = $format]
39-
pub struct $id {
40-
}
39+
pub struct $id {}
4140
}
4241
)*
4342

compiler/rustc_middle/src/ty/sty.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1379,8 +1379,7 @@ rustc_index::newtype_index! {
13791379
/// A **region** (lifetime) **v**ariable **ID**.
13801380
#[derive(HashStable)]
13811381
#[debug_format = "'_#{}r"]
1382-
pub struct RegionVid {
1383-
}
1382+
pub struct RegionVid {}
13841383
}
13851384

13861385
impl Atom for RegionVid {
@@ -1391,7 +1390,7 @@ impl Atom for RegionVid {
13911390

13921391
rustc_index::newtype_index! {
13931392
#[derive(HashStable)]
1394-
pub struct BoundVar { .. }
1393+
pub struct BoundVar {}
13951394
}
13961395

13971396
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]

compiler/rustc_middle/src/ty/typeck_results.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ rustc_index::newtype_index! {
611611
#[derive(HashStable)]
612612
#[debug_format = "UserType({})"]
613613
pub struct UserTypeAnnotationIndex {
614-
const START_INDEX = 0,
614+
const START_INDEX = 0;
615615
}
616616
}
617617

compiler/rustc_mir_build/src/build/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ struct CFG<'tcx> {
372372
}
373373

374374
rustc_index::newtype_index! {
375-
struct ScopeId { .. }
375+
struct ScopeId {}
376376
}
377377

378378
#[derive(Debug)]

compiler/rustc_mir_build/src/build/scope.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ pub(crate) enum BreakableTarget {
185185
}
186186

187187
rustc_index::newtype_index! {
188-
struct DropIdx { .. }
188+
struct DropIdx {}
189189
}
190190

191191
const ROOT_NODE: DropIdx = DropIdx::from_u32(0);

0 commit comments

Comments
 (0)