From 5f42a0f005ea0d4c34ab2a29d1c4a8a4bd615467 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 11 Sep 2018 13:49:10 +0200 Subject: [PATCH] Change debug printing to print in the old concise style --- src/librustc/middle/region.rs | 24 +++++++++++++++++++++--- src/test/mir-opt/validate_1.rs | 6 +++--- src/test/mir-opt/validate_3.rs | 8 ++++---- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index b1d6cce11f4..2f99743cfbd 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -21,6 +21,7 @@ use ty; use std::mem; +use std::fmt; use rustc_data_structures::sync::Lrc; use syntax::source_map; use syntax::ast; @@ -50,7 +51,7 @@ /// `DestructionScope`, but those that are `terminating_scopes` do; /// see discussion with `ScopeTree`. /// -/// `Remainder(BlockRemainder { block, statement_index })` represents +/// `Remainder { block, statement_index }` represents /// the scope of user code running immediately after the initializer /// expression for the indexed statement, until the end of the block. /// @@ -99,12 +100,29 @@ /// placate the same deriving in `ty::FreeRegion`, but we may want to /// actually attach a more meaningful ordering to scopes than the one /// generated via deriving here. -#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Debug, Copy, RustcEncodable, RustcDecodable)] +#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Copy, RustcEncodable, RustcDecodable)] pub struct Scope { pub(crate) id: hir::ItemLocalId, pub(crate) data: ScopeData, } +impl fmt::Debug for Scope { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.data { + ScopeData::Node => write!(fmt, "Node({:?})", self.id), + ScopeData::CallSite => write!(fmt, "CallSite({:?})", self.id), + ScopeData::Arguments => write!(fmt, "Arguments({:?})", self.id), + ScopeData::Destruction => write!(fmt, "Destruction({:?})", self.id), + ScopeData::Remainder(fsi) => write!( + fmt, + "Remainder {{ block: {:?}, first_statement_index: {}}}", + self.id, + fsi.as_u32(), + ), + } + } +} + #[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Debug, Copy, RustcEncodable, RustcDecodable)] pub enum ScopeData { Node, @@ -159,7 +177,7 @@ impl Scope { #[inline] pub fn data(self) -> ScopeData { self.data - } + } #[inline] pub fn new(id: hir::ItemLocalId, data: ScopeData) -> Self { diff --git a/src/test/mir-opt/validate_1.rs b/src/test/mir-opt/validate_1.rs index 2d5c98ff0ed..882579c5710 100644 --- a/src/test/mir-opt/validate_1.rs +++ b/src/test/mir-opt/validate_1.rs @@ -64,11 +64,11 @@ fn main() { // bb0: { // Validate(Acquire, [_1: &ReFree(DefId(0/1:11 ~ validate_1[317d]::main[0]::{{closure}}[0]), BrEnv) [closure@NodeId(50)], _2: &ReFree(DefId(0/1:11 ~ validate_1[317d]::main[0]::{{closure}}[0]), BrAnon(0)) mut i32]); // StorageLive(_3); -// Validate(Suspend(ReScope(Remainder(BlockRemainder { block: ItemLocalId(25), first_statement_index: 0 }))), [(*_2): i32]); +// Validate(Suspend(ReScope(Remainder { block: ItemLocalId(25), first_statement_index: 0 })), [(*_2): i32]); // _3 = &ReErased (*_2); -// Validate(Acquire, [(*_3): i32/ReScope(Remainder(BlockRemainder { block: ItemLocalId(25), first_statement_index: 0 })) (imm)]); +// Validate(Acquire, [(*_3): i32/ReScope(Remainder { block: ItemLocalId(25), first_statement_index: 0 }) (imm)]); // _0 = (*_3); -// EndRegion(ReScope(Remainder(BlockRemainder { block: ItemLocalId(25), first_statement_index: 0 }))); +// EndRegion(ReScope(Remainder { block: ItemLocalId(25), first_statement_index: 0 })); // StorageDead(_3); // return; // } diff --git a/src/test/mir-opt/validate_3.rs b/src/test/mir-opt/validate_3.rs index 72ec9ce400f..07f5b2aa84b 100644 --- a/src/test/mir-opt/validate_3.rs +++ b/src/test/mir-opt/validate_3.rs @@ -48,12 +48,12 @@ fn _unused2(x: *const i32) -> i32 { unsafe { *x }} // StorageLive(_1); // _1 = Test { x: const 0i32 }; // StorageLive(_2); -// Validate(Suspend(ReScope(Remainder(BlockRemainder { block: ItemLocalId(20), first_statement_index: 3 }))), [_1: Test]); +// Validate(Suspend(ReScope(Remainder { block: ItemLocalId(20), first_statement_index: 3 })), [_1: Test]); // _2 = &ReErased _1; -// Validate(Acquire, [(*_2): Test/ReScope(Remainder(BlockRemainder { block: ItemLocalId(20), first_statement_index: 3 })) (imm)]); +// Validate(Acquire, [(*_2): Test/ReScope(Remainder { block: ItemLocalId(20), first_statement_index: 3 }) (imm)]); // StorageLive(_4); // StorageLive(_5); -// Validate(Suspend(ReScope(Node(ItemLocalId(18)))), [((*_2).0: i32): i32/ReScope(Remainder(BlockRemainder { block: ItemLocalId(20), first_statement_index: 3 })) (imm)]); +// Validate(Suspend(ReScope(Node(ItemLocalId(18)))), [((*_2).0: i32): i32/ReScope(Remainder { block: ItemLocalId(20), first_statement_index: 3 }) (imm)]); // _5 = &ReErased ((*_2).0: i32); // Validate(Acquire, [(*_5): i32/ReScope(Node(ItemLocalId(18))) (imm)]); // Validate(Suspend(ReScope(Node(ItemLocalId(18)))), [(*_5): i32/ReScope(Node(ItemLocalId(18))) (imm)]); @@ -68,7 +68,7 @@ fn _unused2(x: *const i32) -> i32 { unsafe { *x }} // StorageDead(_4); // StorageDead(_5); // _0 = (); -// EndRegion(ReScope(Remainder(BlockRemainder { block: ItemLocalId(20), first_statement_index: 3 }))); +// EndRegion(ReScope(Remainder { block: ItemLocalId(20), first_statement_index: 3 })); // StorageDead(_2); // StorageDead(_1); // return; -- 2.44.0