Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/librustc/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use util::nodemap::{FxHashMap, FxHashSet};
use ty;

use std::mem;
use std::fmt;
use rustc_data_structures::sync::Lrc;
use syntax::source_map;
use syntax::ast;
Expand Down Expand Up @@ -50,7 +51,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
/// `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.
///
Expand Down Expand Up @@ -99,12 +100,29 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
/// 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: {}}}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to use the fmt.debug_struct wrapper, to automate this.

self.id,
fsi.as_u32(),
),
}
}
}

#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Debug, Copy, RustcEncodable, RustcDecodable)]
pub enum ScopeData {
Node,
Expand Down Expand Up @@ -152,14 +170,14 @@ impl_stable_hash_for!(struct ::middle::region::FirstStatementIndex { private });
#[allow(dead_code)]
// only works on stage 1 when the rustc_layout_scalar_valid_range attribute actually exists
#[cfg(not(stage0))]
static ASSERT: () = [()][(mem::size_of::<ScopeData>() != 4) as usize];
static ASSERT: () = [()][!(mem::size_of::<ScopeData>() == 4) as usize];

#[allow(non_snake_case)]
impl Scope {
#[inline]
pub fn data(self) -> ScopeData {
self.data
}
}

#[inline]
pub fn new(id: hir::ItemLocalId, data: ScopeData) -> Self {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,9 +830,9 @@ impl<'tcx> CommonTypes<'tcx> {
fn new(interners: &CtxtInterners<'tcx>) -> CommonTypes<'tcx> {
// Ensure our type representation does not grow
#[cfg(all(not(stage0), target_pointer_width = "64"))]
assert!(mem::size_of::<ty::TyKind>() <= 24);
static ASSERT_TY_KIND: () = [()][!(std::mem::size_of::<ty::TyKind>() <= 24) as usize];
#[cfg(all(not(stage0), target_pointer_width = "64"))]
assert!(mem::size_of::<ty::TyS>() <= 32);
static ASSERT_TYS: () = [()][!(std::mem::size_of::<ty::TyS>() <= 32) as usize];

let mk = |sty| CtxtInterners::intern_ty(interners, interners, sty);
let mk_region = |r| {
Expand Down
6 changes: 3 additions & 3 deletions src/test/mir-opt/validate_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
// }
Expand Down
8 changes: 4 additions & 4 deletions src/test/mir-opt/validate_3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ fn main() {
// 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)]);
Expand All @@ -68,7 +68,7 @@ fn main() {
// 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;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/consts/const-eval/zst_operand_eval.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// compile-pass

static ASSERT: () = [()][(std::mem::size_of::<u32>() != 4) as usize];
static ASSERT: () = [()][!(std::mem::size_of::<u32>() == 4) as usize];

fn main() {}