Skip to content

Commit caeb1ae

Browse files
committed
Extract debug name via "reflection"
1 parent b0904fa commit caeb1ae

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

src/librustc/mir/mod.rs

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

405-
newtype_index!(Local, "_");
405+
newtype_index!(Local);
406406

407407
pub const RETURN_POINTER: Local = Local(0);
408408

@@ -538,7 +538,7 @@ pub struct UpvarDecl {
538538
///////////////////////////////////////////////////////////////////////////
539539
// BasicBlock
540540

541-
newtype_index!(BasicBlock, "bb");
541+
newtype_index!(BasicBlock);
542542

543543
///////////////////////////////////////////////////////////////////////////
544544
// BasicBlockData and Terminator
@@ -1118,7 +1118,7 @@ pub type LvalueProjection<'tcx> = Projection<'tcx, Lvalue<'tcx>, Local, Ty<'tcx>
11181118
/// and the index is a local.
11191119
pub type LvalueElem<'tcx> = ProjectionElem<'tcx, Local, Ty<'tcx>>;
11201120

1121-
newtype_index!(Field, "field");
1121+
newtype_index!(Field);
11221122

11231123
impl<'tcx> Lvalue<'tcx> {
11241124
pub fn field(self, f: Field, ty: Ty<'tcx>) -> Lvalue<'tcx> {
@@ -1183,7 +1183,7 @@ impl<'tcx> Debug for Lvalue<'tcx> {
11831183
///////////////////////////////////////////////////////////////////////////
11841184
// Scopes
11851185

1186-
newtype_index!(VisibilityScope, "scope");
1186+
newtype_index!(VisibilityScope);
11871187
pub const ARGUMENT_VISIBILITY_SCOPE : VisibilityScope = VisibilityScope(0);
11881188

11891189
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
@@ -1509,7 +1509,7 @@ pub struct Constant<'tcx> {
15091509
pub literal: Literal<'tcx>,
15101510
}
15111511

1512-
newtype_index!(Promoted, "promoted");
1512+
newtype_index!(Promoted);
15131513

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

src/librustc_data_structures/indexed_vec.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl Idx for u32 {
4040

4141
#[macro_export]
4242
macro_rules! newtype_index {
43-
($name:ident, $debug_name:expr) => (
43+
($name:ident) => (
4444
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord,
4545
RustcEncodable, RustcDecodable)]
4646
pub struct $name(u32);
@@ -57,7 +57,8 @@ macro_rules! newtype_index {
5757

5858
impl ::std::fmt::Debug for $name {
5959
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
60-
write!(fmt, "{}{}", $debug_name, self.0)
60+
let debug_name = unsafe { ::std::intrinsics::type_name::<$name>() };
61+
write!(fmt, "{}{}", debug_name, self.0)
6162
}
6263
}
6364
)

src/librustc_mir/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
1818

1919
#![feature(box_patterns)]
2020
#![feature(box_syntax)]
21+
#![feature(core_intrinsics)]
2122
#![feature(i128_type)]
2223
#![feature(rustc_diagnostic_macros)]
2324
#![feature(placement_in_syntax)]

src/librustc_mir/transform/nll.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,4 @@ struct Region {
155155
points: FxHashSet<Location>,
156156
}
157157

158-
newtype_index!(RegionIndex, "region_index");
158+
newtype_index!(RegionIndex);

0 commit comments

Comments
 (0)