Skip to content

Commit bf1198e

Browse files
committed
newtype_index: Support simpler serializable override, custom derive, and fix mir_opt tests
1 parent b46e42f commit bf1198e

File tree

6 files changed

+213
-142
lines changed

6 files changed

+213
-142
lines changed

src/librustc/dep_graph/serialized.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use dep_graph::DepNode;
1414
use ich::Fingerprint;
1515
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
1616

17-
newtype_index!(SerializedDepNodeIndex { derive[RustcEncodable, RustcDecodable] });
17+
newtype_index!(SerializedDepNodeIndex);
1818

1919
/// Data for use when recompiling the **current crate**.
2020
#[derive(Debug, RustcEncodable, RustcDecodable)]

src/librustc/hir/def_id.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ use std::u32;
1818

1919
newtype_index!(CrateNum nopub
2020
{
21+
derive[Debug]
22+
ENCODABLE = custom
23+
2124
/// Item definitions in the currently-compiled crate would have the CrateNum
2225
/// LOCAL_CRATE in their DefId.
2326
const LOCAL_CRATE = 0,

src/librustc/middle/region.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,7 @@ pub struct BlockRemainder {
156156
pub first_statement_index: FirstStatementIndex,
157157
}
158158

159-
newtype_index!(FirstStatementIndex
160-
{
161-
derive[RustcEncodable, RustcDecodable]
162-
DEBUG_NAME = "",
163-
MAX = SCOPE_DATA_REMAINDER_MAX,
164-
});
159+
newtype_index!(FirstStatementIndex { MAX = SCOPE_DATA_REMAINDER_MAX });
165160

166161
impl From<ScopeData> for Scope {
167162
#[inline]

src/librustc/mir/mod.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,7 @@ pub enum BorrowKind {
417417

418418
newtype_index!(Local
419419
{
420-
derive[RustcEncodable, RustcDecodable]
421-
DEBUG_NAME = "_",
420+
DEBUG_FORMAT = "_{}",
422421
const RETURN_POINTER = 0,
423422
});
424423

@@ -554,11 +553,7 @@ pub struct UpvarDecl {
554553
///////////////////////////////////////////////////////////////////////////
555554
// BasicBlock
556555

557-
newtype_index!(BasicBlock
558-
{
559-
derive[RustcEncodable, RustcDecodable]
560-
DEBUG_NAME = "bb"
561-
});
556+
newtype_index!(BasicBlock { DEBUG_FORMAT = "bb{}" });
562557

563558
///////////////////////////////////////////////////////////////////////////
564559
// BasicBlockData and Terminator
@@ -1140,11 +1135,7 @@ pub type LvalueProjection<'tcx> = Projection<'tcx, Lvalue<'tcx>, Local, Ty<'tcx>
11401135
/// and the index is a local.
11411136
pub type LvalueElem<'tcx> = ProjectionElem<'tcx, Local, Ty<'tcx>>;
11421137

1143-
newtype_index!(Field
1144-
{
1145-
derive[RustcEncodable, RustcDecodable]
1146-
DEBUG_NAME = "field"
1147-
});
1138+
newtype_index!(Field { DEBUG_FORMAT = "field[{}]" });
11481139

11491140
impl<'tcx> Lvalue<'tcx> {
11501141
pub fn field(self, f: Field, ty: Ty<'tcx>) -> Lvalue<'tcx> {
@@ -1211,8 +1202,7 @@ impl<'tcx> Debug for Lvalue<'tcx> {
12111202

12121203
newtype_index!(VisibilityScope
12131204
{
1214-
derive[RustcEncodable, RustcDecodable]
1215-
DEBUG_NAME = "scope",
1205+
DEBUG_FORMAT = "scope[{}]",
12161206
const ARGUMENT_VISIBILITY_SCOPE = 0,
12171207
});
12181208

@@ -1539,11 +1529,7 @@ pub struct Constant<'tcx> {
15391529
pub literal: Literal<'tcx>,
15401530
}
15411531

1542-
newtype_index!(Promoted
1543-
{
1544-
derive[RustcEncodable, RustcDecodable]
1545-
DEBUG_NAME = "promoted"
1546-
});
1532+
newtype_index!(Promoted { DEBUG_FORMAT = "promoted[{}]" });
15471533

15481534

15491535
#[derive(Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]

0 commit comments

Comments
 (0)