Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #37289

Merged
merged 14 commits into from
Oct 20, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions src/doc/book/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,9 @@ the `tests` directory.

# The `tests` directory

Each file in `tests/*.rs` directory is treated as individual crate.
So, to write an integration test, let's make a `tests` directory, and
put a `tests/integration_test.rs` file inside, with this as its contents:
Each file in `tests/*.rs` directory is treated as an individual crate.
To write an integration test, let's make a `tests` directory and
put a `tests/integration_test.rs` file inside with this as its contents:

```rust,ignore
extern crate adder;
Expand Down
17 changes: 15 additions & 2 deletions src/libcollections/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,29 @@ impl<T> ToOwned for T where T: Clone {
/// ```
/// use std::borrow::Cow;
///
/// # #[allow(dead_code)]
/// fn abs_all(input: &mut Cow<[i32]>) {
/// for i in 0..input.len() {
/// let v = input[i];
/// if v < 0 {
/// // clones into a vector the first time (if not already owned)
/// // Clones into a vector if not already owned.
/// input.to_mut()[i] = -v;
/// }
/// }
/// }
///
/// // No clone occurs because `input` doesn't need to be mutated.
/// let slice = [0, 1, 2];
/// let mut input = Cow::from(&slice[..]);
/// abs_all(&mut input);
///
/// // Clone occurs because `input` needs to be mutated.
/// let slice = [-1, 0, 1];
/// let mut input = Cow::from(&slice[..]);
/// abs_all(&mut input);
///
/// // No clone occurs because `input` is already owned.
/// let mut input = Cow::from(vec![-1, 0, 1]);
/// abs_all(&mut input);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub enum Cow<'a, B: ?Sized + 'a>
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/infer/freshen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ impl<'a, 'gcx, 'tcx> TypeFreshener<'a, 'gcx, 'tcx> {
-> Ty<'tcx> where
F: FnOnce(u32) -> ty::InferTy,
{
match opt_ty {
Some(ty) => { return ty.fold_with(self); }
None => { }
if let Some(ty) = opt_ty {
return ty.fold_with(self);
}

match self.freshen_map.entry(key) {
Expand Down
37 changes: 13 additions & 24 deletions src/librustc/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,12 +478,9 @@ impl RegionMaps {
//! Returns the scope when temp created by expr_id will be cleaned up

// check for a designated rvalue scope
match self.rvalue_scopes.borrow().get(&expr_id) {
Some(&s) => {
debug!("temporary_scope({:?}) = {:?} [custom]", expr_id, s);
return Some(s);
}
None => { }
if let Some(&s) = self.rvalue_scopes.borrow().get(&expr_id) {
debug!("temporary_scope({:?}) = {:?} [custom]", expr_id, s);
return Some(s);
}

let scope_map : &[CodeExtent] = &self.scope_map.borrow();
Expand Down Expand Up @@ -928,19 +925,15 @@ fn resolve_local(visitor: &mut RegionResolutionVisitor, local: &hir::Local) {
//
// FIXME(#6308) -- Note that `[]` patterns work more smoothly post-DST.

match local.init {
Some(ref expr) => {
record_rvalue_scope_if_borrow_expr(visitor, &expr, blk_scope);
if let Some(ref expr) = local.init {
record_rvalue_scope_if_borrow_expr(visitor, &expr, blk_scope);

let is_borrow =
if let Some(ref ty) = local.ty { is_borrowed_ty(&ty) } else { false };
let is_borrow =
if let Some(ref ty) = local.ty { is_borrowed_ty(&ty) } else { false };

if is_binding_pat(&local.pat) || is_borrow {
record_rvalue_scope(visitor, &expr, blk_scope);
}
if is_binding_pat(&local.pat) || is_borrow {
record_rvalue_scope(visitor, &expr, blk_scope);
}

None => { }
}

intravisit::walk_local(visitor, local);
Expand Down Expand Up @@ -1023,16 +1016,12 @@ fn resolve_local(visitor: &mut RegionResolutionVisitor, local: &hir::Local) {
record_rvalue_scope_if_borrow_expr(visitor, &subexpr, blk_id)
}
hir::ExprBlock(ref block) => {
match block.expr {
Some(ref subexpr) => {
record_rvalue_scope_if_borrow_expr(
visitor, &subexpr, blk_id);
}
None => { }
if let Some(ref subexpr) = block.expr {
record_rvalue_scope_if_borrow_expr(
visitor, &subexpr, blk_id);
}
}
_ => {
}
_ => {}
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/librustc/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1405,9 +1405,8 @@ impl<'tcx> ProjectionCache<'tcx> {
/// cache hit, so it's actually a good thing).
fn try_start(&mut self, key: ty::ProjectionTy<'tcx>)
-> Result<(), ProjectionCacheEntry<'tcx>> {
match self.map.get(&key) {
Some(entry) => return Err(entry.clone()),
None => { }
if let Some(entry) = self.map.get(&key) {
return Err(entry.clone());
}

self.map.insert(key, ProjectionCacheEntry::InProgress);
Expand Down
13 changes: 5 additions & 8 deletions src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,14 +788,11 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
stack);
assert!(!stack.obligation.predicate.has_escaping_regions());

match self.check_candidate_cache(&cache_fresh_trait_pred) {
Some(c) => {
debug!("CACHE HIT: SELECT({:?})={:?}",
cache_fresh_trait_pred,
c);
return c;
}
None => { }
if let Some(c) = self.check_candidate_cache(&cache_fresh_trait_pred) {
debug!("CACHE HIT: SELECT({:?})={:?}",
cache_fresh_trait_pred,
c);
return c;
}

// If no match, compute result and insert into cache.
Expand Down
112 changes: 51 additions & 61 deletions src/librustc_borrowck/borrowck/check_loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,12 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckLoanCtxt<'a, 'tcx> {
borrow_id, cmt, loan_region,
bk, loan_cause);

match opt_loan_path(&cmt) {
Some(lp) => {
let moved_value_use_kind = match loan_cause {
euv::ClosureCapture(_) => MovedInCapture,
_ => MovedInUse,
};
self.check_if_path_is_moved(borrow_id, borrow_span, moved_value_use_kind, &lp);
}
None => { }
if let Some(lp) = opt_loan_path(&cmt) {
let moved_value_use_kind = match loan_cause {
euv::ClosureCapture(_) => MovedInCapture,
_ => MovedInUse,
};
self.check_if_path_is_moved(borrow_id, borrow_span, moved_value_use_kind, &lp);
}

self.check_for_conflicting_loans(borrow_id);
Expand All @@ -158,33 +155,29 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckLoanCtxt<'a, 'tcx> {
debug!("mutate(assignment_id={}, assignee_cmt={:?})",
assignment_id, assignee_cmt);

match opt_loan_path(&assignee_cmt) {
Some(lp) => {
match mode {
MutateMode::Init | MutateMode::JustWrite => {
// In a case like `path = 1`, then path does not
// have to be *FULLY* initialized, but we still
// must be careful lest it contains derefs of
// pointers.
self.check_if_assigned_path_is_moved(assignee_cmt.id,
assignment_span,
MovedInUse,
&lp);
}
MutateMode::WriteAndRead => {
// In a case like `path += 1`, then path must be
// fully initialized, since we will read it before
// we write it.
self.check_if_path_is_moved(assignee_cmt.id,
assignment_span,
MovedInUse,
&lp);
}
if let Some(lp) = opt_loan_path(&assignee_cmt) {
match mode {
MutateMode::Init | MutateMode::JustWrite => {
// In a case like `path = 1`, then path does not
// have to be *FULLY* initialized, but we still
// must be careful lest it contains derefs of
// pointers.
self.check_if_assigned_path_is_moved(assignee_cmt.id,
assignment_span,
MovedInUse,
&lp);
}
MutateMode::WriteAndRead => {
// In a case like `path += 1`, then path must be
// fully initialized, since we will read it before
// we write it.
self.check_if_path_is_moved(assignee_cmt.id,
assignment_span,
MovedInUse,
&lp);
}
}
None => { }
}

self.check_assignment(assignment_id, assignment_span, assignee_cmt);
}

Expand Down Expand Up @@ -601,39 +594,36 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
span: Span,
cmt: mc::cmt<'tcx>,
mode: euv::ConsumeMode) {
match opt_loan_path(&cmt) {
Some(lp) => {
let moved_value_use_kind = match mode {
euv::Copy => {
self.check_for_copy_of_frozen_path(id, span, &lp);
MovedInUse
}
euv::Move(_) => {
match self.move_data.kind_of_move_of_path(id, &lp) {
None => {
// Sometimes moves don't have a move kind;
// this either means that the original move
// was from something illegal to move,
// or was moved from referent of an unsafe
// pointer or something like that.
if let Some(lp) = opt_loan_path(&cmt) {
let moved_value_use_kind = match mode {
euv::Copy => {
self.check_for_copy_of_frozen_path(id, span, &lp);
MovedInUse
}
euv::Move(_) => {
match self.move_data.kind_of_move_of_path(id, &lp) {
None => {
// Sometimes moves don't have a move kind;
// this either means that the original move
// was from something illegal to move,
// or was moved from referent of an unsafe
// pointer or something like that.
MovedInUse
}
Some(move_kind) => {
self.check_for_move_of_borrowed_path(id, span,
&lp, move_kind);
if move_kind == move_data::Captured {
MovedInCapture
} else {
MovedInUse
}
Some(move_kind) => {
self.check_for_move_of_borrowed_path(id, span,
&lp, move_kind);
if move_kind == move_data::Captured {
MovedInCapture
} else {
MovedInUse
}
}
}
}
};
}
};

self.check_if_path_is_moved(id, span, moved_value_use_kind, &lp);
}
None => { }
self.check_if_path_is_moved(id, span, moved_value_use_kind, &lp);
}
}

Expand Down
28 changes: 14 additions & 14 deletions src/librustc_data_structures/control_flow_graph/dominators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ pub fn dominators_given_rpo<G: ControlFlowGraph>(graph: &G,
// (*)
// (*) dominators for `pred` have been calculated
new_idom = intersect_opt(&post_order_rank,
&immediate_dominators,
new_idom,
Some(pred));
&immediate_dominators,
new_idom,
Some(pred));
}
}

Expand All @@ -77,10 +77,10 @@ pub fn dominators_given_rpo<G: ControlFlowGraph>(graph: &G,
}

fn intersect_opt<Node: Idx>(post_order_rank: &IndexVec<Node, usize>,
immediate_dominators: &IndexVec<Node, Option<Node>>,
node1: Option<Node>,
node2: Option<Node>)
-> Option<Node> {
immediate_dominators: &IndexVec<Node, Option<Node>>,
node1: Option<Node>,
node2: Option<Node>)
-> Option<Node> {
match (node1, node2) {
(None, None) => None,
(Some(n), None) | (None, Some(n)) => Some(n),
Expand All @@ -89,10 +89,10 @@ fn intersect_opt<Node: Idx>(post_order_rank: &IndexVec<Node, usize>,
}

fn intersect<Node: Idx>(post_order_rank: &IndexVec<Node, usize>,
immediate_dominators: &IndexVec<Node, Option<Node>>,
mut node1: Node,
mut node2: Node)
-> Node {
immediate_dominators: &IndexVec<Node, Option<Node>>,
mut node1: Node,
mut node2: Node)
-> Node {
while node1 != node2 {
while post_order_rank[node1] < post_order_rank[node2] {
node1 = immediate_dominators[node1].unwrap();
Expand Down Expand Up @@ -142,9 +142,9 @@ impl<Node: Idx> Dominators<Node> {
"node {:?} is not reachable",
node2);
intersect::<Node>(&self.post_order_rank,
&self.immediate_dominators,
node1,
node2)
&self.immediate_dominators,
node1,
node2)
}

pub fn mutual_dominator<I>(&self, iter: I) -> Option<Node>
Expand Down
22 changes: 4 additions & 18 deletions src/librustc_data_structures/control_flow_graph/dominators/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ use super::*;

#[test]
fn diamond() {
let graph = TestGraph::new(0, &[
(0, 1),
(0, 2),
(1, 3),
(2, 3),
]);
let graph = TestGraph::new(0, &[(0, 1), (0, 2), (1, 3), (2, 3)]);

let dominators = dominators(&graph);
let immediate_dominators = dominators.all_immediate_dominators();
Expand All @@ -32,17 +27,9 @@ fn diamond() {
#[test]
fn paper() {
// example from the paper:
let graph = TestGraph::new(6, &[
(6, 5),
(6, 4),
(5, 1),
(4, 2),
(4, 3),
(1, 2),
(2, 3),
(3, 2),
(2, 1),
]);
let graph = TestGraph::new(6,
&[(6, 5), (6, 4), (5, 1), (4, 2), (4, 3), (1, 2), (2, 3), (3, 2),
(2, 1)]);

let dominators = dominators(&graph);
let immediate_dominators = dominators.all_immediate_dominators();
Expand All @@ -54,4 +41,3 @@ fn paper() {
assert_eq!(immediate_dominators[5], Some(6));
assert_eq!(immediate_dominators[6], Some(6));
}

Loading