Skip to content

Commit

Permalink
librustc_borrowck: use #[deriving(Copy)]
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Aparicio committed Dec 19, 2014
1 parent e64a007 commit 392ea79
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 35 deletions.
15 changes: 4 additions & 11 deletions src/librustc_borrowck/borrowck/mod.rs
Expand Up @@ -56,11 +56,9 @@ pub mod gather_loans;

pub mod move_data;

#[deriving(Clone)]
#[deriving(Clone, Copy)]
pub struct LoanDataFlowOperator;

impl Copy for LoanDataFlowOperator {}

pub type LoanDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, LoanDataFlowOperator>;

impl<'a, 'tcx, 'v> Visitor<'v> for BorrowckCtxt<'a, 'tcx> {
Expand Down Expand Up @@ -325,14 +323,12 @@ impl<'tcx> LoanPath<'tcx> {
// b2b39e8700e37ad32b486b9a8409b50a8a53aa51#commitcomment-7892003
static DOWNCAST_PRINTED_OPERATOR : &'static str = " as ";

#[deriving(PartialEq, Eq, Hash, Show)]
#[deriving(Copy, PartialEq, Eq, Hash, Show)]
pub enum LoanPathElem {
LpDeref(mc::PointerKind), // `*LV` in doc.rs
LpInterior(mc::InteriorKind) // `LV.f` in doc.rs
}

impl Copy for LoanPathElem {}

pub fn closure_to_block(closure_id: ast::NodeId,
tcx: &ty::ctxt) -> ast::NodeId {
match tcx.map.get(closure_id) {
Expand Down Expand Up @@ -494,21 +490,18 @@ pub struct BckError<'tcx> {
code: bckerr_code
}

#[deriving(Copy)]
pub enum AliasableViolationKind {
MutabilityViolation,
BorrowViolation(euv::LoanCause)
}

impl Copy for AliasableViolationKind {}

#[deriving(Show)]
#[deriving(Copy, Show)]
pub enum MovedValueUseKind {
MovedInUse,
MovedInCapture,
}

impl Copy for MovedValueUseKind {}

///////////////////////////////////////////////////////////////////////////
// Misc

Expand Down
29 changes: 8 additions & 21 deletions src/librustc_borrowck/borrowck/move_data.rs
Expand Up @@ -78,11 +78,9 @@ pub struct FlowedMoveData<'a, 'tcx: 'a> {
}

/// Index into `MoveData.paths`, used like a pointer
#[deriving(PartialEq, Eq, PartialOrd, Ord, Show)]
#[deriving(Copy, PartialEq, Eq, PartialOrd, Ord, Show)]
pub struct MovePathIndex(uint);

impl Copy for MovePathIndex {}

impl MovePathIndex {
fn get(&self) -> uint {
let MovePathIndex(v) = *self; v
Expand All @@ -100,11 +98,9 @@ static InvalidMovePathIndex: MovePathIndex =
MovePathIndex(uint::MAX);

/// Index into `MoveData.moves`, used like a pointer
#[deriving(PartialEq)]
#[deriving(Copy, PartialEq)]
pub struct MoveIndex(uint);

impl Copy for MoveIndex {}

impl MoveIndex {
fn get(&self) -> uint {
let MoveIndex(v) = *self; v
Expand Down Expand Up @@ -134,16 +130,15 @@ pub struct MovePath<'tcx> {
pub next_sibling: MovePathIndex,
}

#[deriving(PartialEq, Show)]
#[deriving(Copy, PartialEq, Show)]
pub enum MoveKind {
Declared, // When declared, variables start out "moved".
MoveExpr, // Expression or binding that moves a variable
MovePat, // By-move binding
Captured // Closure creation that moves a value
}

impl Copy for MoveKind {}

#[deriving(Copy)]
pub struct Move {
/// Path being moved.
pub path: MovePathIndex,
Expand All @@ -158,8 +153,7 @@ pub struct Move {
pub next_move: MoveIndex
}

impl Copy for Move {}

#[deriving(Copy)]
pub struct Assignment {
/// Path being assigned.
pub path: MovePathIndex,
Expand All @@ -171,8 +165,7 @@ pub struct Assignment {
pub span: Span,
}

impl Copy for Assignment {}

#[deriving(Copy)]
pub struct VariantMatch {
/// downcast to the variant.
pub path: MovePathIndex,
Expand All @@ -187,20 +180,14 @@ pub struct VariantMatch {
pub mode: euv::MatchMode
}

impl Copy for VariantMatch {}

#[deriving(Clone)]
#[deriving(Clone, Copy)]
pub struct MoveDataFlowOperator;

impl Copy for MoveDataFlowOperator {}

pub type MoveDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, MoveDataFlowOperator>;

#[deriving(Clone)]
#[deriving(Clone, Copy)]
pub struct AssignDataFlowOperator;

impl Copy for AssignDataFlowOperator {}

pub type AssignDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, AssignDataFlowOperator>;

fn loan_path_is_precise(loan_path: &LoanPath) -> bool {
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_borrowck/graphviz.rs
Expand Up @@ -25,15 +25,13 @@ use rustc::middle::dataflow::{DataFlowOperator, DataFlowContext, EntryOrExit};
use rustc::middle::dataflow;
use std::rc::Rc;

#[deriving(Show)]
#[deriving(Show, Copy)]
pub enum Variant {
Loans,
Moves,
Assigns,
}

impl Copy for Variant {}

impl Variant {
pub fn short_name(&self) -> &'static str {
match *self {
Expand Down

0 comments on commit 392ea79

Please sign in to comment.