Skip to content

Commit 9423bee

Browse files
committed
Move const qualifier from brackets to constant values and remove comma from after identifier
1 parent 35545b3 commit 9423bee

File tree

2 files changed

+46
-57
lines changed

2 files changed

+46
-57
lines changed

src/librustc/mir/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,10 @@ pub enum BorrowKind {
402402
///////////////////////////////////////////////////////////////////////////
403403
// Variables and temps
404404

405-
newtype_index!(Local,
406-
const {
407-
DESCRIPTION = "_",
408-
RETURN_POINTER = 0,
405+
newtype_index!(Local
406+
{
407+
DEBUG_NAME = "_",
408+
const RETURN_POINTER = 0,
409409
});
410410

411411
/// Classifies locals into categories. See `Mir::local_kind`.
@@ -540,7 +540,7 @@ pub struct UpvarDecl {
540540
///////////////////////////////////////////////////////////////////////////
541541
// BasicBlock
542542

543-
newtype_index!(BasicBlock, const { DESCRIPTION = "bb" });
543+
newtype_index!(BasicBlock { DEBUG_NAME = "bb" });
544544

545545
///////////////////////////////////////////////////////////////////////////
546546
// BasicBlockData and Terminator
@@ -1120,7 +1120,7 @@ pub type LvalueProjection<'tcx> = Projection<'tcx, Lvalue<'tcx>, Local, Ty<'tcx>
11201120
/// and the index is a local.
11211121
pub type LvalueElem<'tcx> = ProjectionElem<'tcx, Local, Ty<'tcx>>;
11221122

1123-
newtype_index!(Field, const { DESCRIPTION = "field" });
1123+
newtype_index!(Field { DEBUG_NAME = "field" });
11241124

11251125
impl<'tcx> Lvalue<'tcx> {
11261126
pub fn field(self, f: Field, ty: Ty<'tcx>) -> Lvalue<'tcx> {
@@ -1185,10 +1185,10 @@ impl<'tcx> Debug for Lvalue<'tcx> {
11851185
///////////////////////////////////////////////////////////////////////////
11861186
// Scopes
11871187

1188-
newtype_index!(VisibilityScope,
1189-
const {
1190-
DESCRIPTION = "scope",
1191-
ARGUMENT_VISIBILITY_SCOPE = 0,
1188+
newtype_index!(VisibilityScope
1189+
{
1190+
DEBUG_NAME = "scope",
1191+
const ARGUMENT_VISIBILITY_SCOPE = 0,
11921192
});
11931193

11941194
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
@@ -1514,7 +1514,7 @@ pub struct Constant<'tcx> {
15141514
pub literal: Literal<'tcx>,
15151515
}
15161516

1517-
newtype_index!(Promoted, const { DESCRIPTION = "promoted" });
1517+
newtype_index!(Promoted { DEBUG_NAME = "promoted" });
15181518

15191519
#[derive(Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
15201520
pub enum Literal<'tcx> {

src/librustc_data_structures/indexed_vec.rs

Lines changed: 35 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,29 @@ impl Idx for u32 {
4040

4141
#[macro_export]
4242
macro_rules! newtype_index {
43+
// ---- public rules ----
44+
45+
// Use default constants
46+
($name:ident) => (
47+
newtype_index!(
48+
@type[$name]
49+
@max[::std::u32::MAX]
50+
@debug_name[unsafe {::std::intrinsics::type_name::<$name>() }]);
51+
);
52+
53+
// Define any constants
54+
($name:ident { $($tokens:tt)+ }) => (
55+
newtype_index!(
56+
@type[$name]
57+
@max[::std::u32::MAX]
58+
@debug_name[unsafe {::std::intrinsics::type_name::<$name>() }]
59+
$($tokens)+);
60+
);
61+
4362
// ---- private rules ----
4463

4564
// Base case, user-defined constants (if any) have already been defined
46-
(@type[$type:ident] @max[$max:expr] @descr[$descr:expr]) => (
65+
(@type[$type:ident] @max[$max:expr] @debug_name[$debug_name:expr]) => (
4766
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord,
4867
RustcEncodable, RustcDecodable)]
4968
pub struct $type(u32);
@@ -60,65 +79,35 @@ macro_rules! newtype_index {
6079

6180
impl ::std::fmt::Debug for $type {
6281
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
63-
write!(fmt, "{}{}", $descr, self.0)
82+
write!(fmt, "{}{}", $debug_name, self.0)
6483
}
6584
}
6685
);
6786

68-
// Replace existing default for max (as final param)
69-
(@type[$type:ident] @max[$_max:expr] @descr[$descr:expr] MAX = $max:expr) => (
70-
newtype_index!(@type[$type] @max[$max] @descr[$descr]);
87+
// Rewrite final without comma to one that includes comma
88+
(@type[$type:ident] @max[$max:expr] @debug_name[$debug_name:expr] $name:ident = $constant:expr) => (
89+
newtype_index!(@type[$type] @max[$max] @debug_name[$debug_name] $name = $constant,);
7190
);
7291

73-
// Replace existing default for max
74-
(@type[$type:ident] @max[$_max:expr] @descr[$descr:expr] MAX = $max:expr, $($idents:ident = $constants:expr),*) => (
75-
newtype_index!(@type[$type] @max[$max] @descr[$descr]);
92+
// Rewrite final const without comma to one that includes comma
93+
(@type[$type:ident] @max[$_max:expr] @debug_name[$debug_name:expr] const $name:ident = $constant:expr) => (
94+
newtype_index!(@type[$type] @max[$max] @debug_name[$debug_name] const $name = $constant,);
7695
);
7796

78-
// Replace existing default for description (as final param)
79-
(@type[$type:ident] @max[$max:expr] @descr[$_descr:expr] DESCRIPTION = $descr:expr) => (
80-
newtype_index!(@type[$type] @max[$max] @descr[$descr]);
97+
// Replace existing default for max
98+
(@type[$type:ident] @max[$_max:expr] @debug_name[$debug_name:expr] MAX = $max:expr, $($tokens:tt)*) => (
99+
newtype_index!(@type[$type] @max[$max] @debug_name[$debug_name] $(tokens)*);
81100
);
82101

83-
// Replace existing default for description
84-
(@type[$type:ident] @max[$max:expr] @descr[$_descr:expr] DESCRIPTION = $descr:expr, $($idents:ident = $constants:expr),*) => (
85-
newtype_index!(@type[$type] @max[$max] @descr[$descr] $($idents = $constants),*);
102+
// Replace existing default for debug_name
103+
(@type[$type:ident] @max[$max:expr] @debug_name[$_debug_name:expr] DEBUG_NAME = $debug_name:expr, $($tokens:tt)*) => (
104+
newtype_index!(@type[$type] @max[$max] @debug_name[$debug_name] $($tokens)*);
86105
);
87106

88107
// Assign a user-defined constant (as final param)
89-
(@type[$type:ident] @max[$max:expr] @descr[$descr:expr] $name:ident = $constant:expr) => (
108+
(@type[$type:ident] @max[$max:expr] @debug_name[$debug_name:expr] const $name:ident = $constant:expr, $($tokens:tt)*) => (
90109
pub const $name: $type = $type($constant);
91-
newtype_index!(@type[$type] @max[$max] @descr[$descr]);
92-
);
93-
94-
// Assign a user-defined constant
95-
(@type[$type:ident] @max[$max:expr] @descr[$descr:expr] $name:ident = $constant:expr, $($idents:ident = $constants:expr),*) => (
96-
pub const $name: $type = $type($constant);
97-
newtype_index!(@type[$type] @max[$max] @descr[$descr] $($idents = $constants),*);
98-
);
99-
100-
// ---- public rules ----
101-
102-
// Use default constants
103-
($name:ident) => (
104-
newtype_index!(
105-
@type[$name]
106-
@max[::std::u32::MAX]
107-
@descr[unsafe {::std::intrinsics::type_name::<$name>() }]);
108-
);
109-
110-
// Define any constants
111-
($name:ident, const { $($idents:ident = $constants:expr,)+ }) => (
112-
newtype_index!(
113-
@type[$name]
114-
@max[::std::u32::MAX]
115-
@descr[unsafe {::std::intrinsics::type_name::<$name>() }]
116-
$($idents = $constants),+);
117-
);
118-
119-
// Rewrite missing trailing comma in const to version with trailing comma
120-
($name:ident, const { $($idents:ident = $constants:expr),+ }) => (
121-
newtype_index!($name, const { $($idents = $constants,)+ });
110+
newtype_index!(@type[$type] @max[$max] @debug_name[$debug_name] $($tokens)*);
122111
);
123112
}
124113

0 commit comments

Comments
 (0)