Skip to content

Commit dfd98eb

Browse files
authored
Auto merge of #37289 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 7 pull requests - Successful merges: #37165, #37187, #37241, #37283, #37285, #37287, #37288 - Failed merges:
2 parents d337f34 + dd3a014 commit dfd98eb

File tree

25 files changed

+190
-252
lines changed

25 files changed

+190
-252
lines changed

Diff for: src/doc/book/testing.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,9 @@ the `tests` directory.
380380

381381
# The `tests` directory
382382

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

387387
```rust,ignore
388388
extern crate adder;

Diff for: src/libcollections/borrow.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,29 @@ impl<T> ToOwned for T where T: Clone {
8686
/// ```
8787
/// use std::borrow::Cow;
8888
///
89-
/// # #[allow(dead_code)]
9089
/// fn abs_all(input: &mut Cow<[i32]>) {
9190
/// for i in 0..input.len() {
9291
/// let v = input[i];
9392
/// if v < 0 {
94-
/// // clones into a vector the first time (if not already owned)
93+
/// // Clones into a vector if not already owned.
9594
/// input.to_mut()[i] = -v;
9695
/// }
9796
/// }
9897
/// }
98+
///
99+
/// // No clone occurs because `input` doesn't need to be mutated.
100+
/// let slice = [0, 1, 2];
101+
/// let mut input = Cow::from(&slice[..]);
102+
/// abs_all(&mut input);
103+
///
104+
/// // Clone occurs because `input` needs to be mutated.
105+
/// let slice = [-1, 0, 1];
106+
/// let mut input = Cow::from(&slice[..]);
107+
/// abs_all(&mut input);
108+
///
109+
/// // No clone occurs because `input` is already owned.
110+
/// let mut input = Cow::from(vec![-1, 0, 1]);
111+
/// abs_all(&mut input);
99112
/// ```
100113
#[stable(feature = "rust1", since = "1.0.0")]
101114
pub enum Cow<'a, B: ?Sized + 'a>

Diff for: src/librustc/infer/freshen.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ impl<'a, 'gcx, 'tcx> TypeFreshener<'a, 'gcx, 'tcx> {
6161
-> Ty<'tcx> where
6262
F: FnOnce(u32) -> ty::InferTy,
6363
{
64-
match opt_ty {
65-
Some(ty) => { return ty.fold_with(self); }
66-
None => { }
64+
if let Some(ty) = opt_ty {
65+
return ty.fold_with(self);
6766
}
6867

6968
match self.freshen_map.entry(key) {

Diff for: src/librustc/middle/region.rs

+13-24
Original file line numberDiff line numberDiff line change
@@ -478,12 +478,9 @@ impl RegionMaps {
478478
//! Returns the scope when temp created by expr_id will be cleaned up
479479
480480
// check for a designated rvalue scope
481-
match self.rvalue_scopes.borrow().get(&expr_id) {
482-
Some(&s) => {
483-
debug!("temporary_scope({:?}) = {:?} [custom]", expr_id, s);
484-
return Some(s);
485-
}
486-
None => { }
481+
if let Some(&s) = self.rvalue_scopes.borrow().get(&expr_id) {
482+
debug!("temporary_scope({:?}) = {:?} [custom]", expr_id, s);
483+
return Some(s);
487484
}
488485

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

931-
match local.init {
932-
Some(ref expr) => {
933-
record_rvalue_scope_if_borrow_expr(visitor, &expr, blk_scope);
928+
if let Some(ref expr) = local.init {
929+
record_rvalue_scope_if_borrow_expr(visitor, &expr, blk_scope);
934930

935-
let is_borrow =
936-
if let Some(ref ty) = local.ty { is_borrowed_ty(&ty) } else { false };
931+
let is_borrow =
932+
if let Some(ref ty) = local.ty { is_borrowed_ty(&ty) } else { false };
937933

938-
if is_binding_pat(&local.pat) || is_borrow {
939-
record_rvalue_scope(visitor, &expr, blk_scope);
940-
}
934+
if is_binding_pat(&local.pat) || is_borrow {
935+
record_rvalue_scope(visitor, &expr, blk_scope);
941936
}
942-
943-
None => { }
944937
}
945938

946939
intravisit::walk_local(visitor, local);
@@ -1023,16 +1016,12 @@ fn resolve_local(visitor: &mut RegionResolutionVisitor, local: &hir::Local) {
10231016
record_rvalue_scope_if_borrow_expr(visitor, &subexpr, blk_id)
10241017
}
10251018
hir::ExprBlock(ref block) => {
1026-
match block.expr {
1027-
Some(ref subexpr) => {
1028-
record_rvalue_scope_if_borrow_expr(
1029-
visitor, &subexpr, blk_id);
1030-
}
1031-
None => { }
1019+
if let Some(ref subexpr) = block.expr {
1020+
record_rvalue_scope_if_borrow_expr(
1021+
visitor, &subexpr, blk_id);
10321022
}
10331023
}
1034-
_ => {
1035-
}
1024+
_ => {}
10361025
}
10371026
}
10381027

Diff for: src/librustc/traits/project.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1405,9 +1405,8 @@ impl<'tcx> ProjectionCache<'tcx> {
14051405
/// cache hit, so it's actually a good thing).
14061406
fn try_start(&mut self, key: ty::ProjectionTy<'tcx>)
14071407
-> Result<(), ProjectionCacheEntry<'tcx>> {
1408-
match self.map.get(&key) {
1409-
Some(entry) => return Err(entry.clone()),
1410-
None => { }
1408+
if let Some(entry) = self.map.get(&key) {
1409+
return Err(entry.clone());
14111410
}
14121411

14131412
self.map.insert(key, ProjectionCacheEntry::InProgress);

Diff for: src/librustc/traits/select.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -788,14 +788,11 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
788788
stack);
789789
assert!(!stack.obligation.predicate.has_escaping_regions());
790790

791-
match self.check_candidate_cache(&cache_fresh_trait_pred) {
792-
Some(c) => {
793-
debug!("CACHE HIT: SELECT({:?})={:?}",
794-
cache_fresh_trait_pred,
795-
c);
796-
return c;
797-
}
798-
None => { }
791+
if let Some(c) = self.check_candidate_cache(&cache_fresh_trait_pred) {
792+
debug!("CACHE HIT: SELECT({:?})={:?}",
793+
cache_fresh_trait_pred,
794+
c);
795+
return c;
799796
}
800797

801798
// If no match, compute result and insert into cache.

Diff for: src/librustc_borrowck/borrowck/check_loans.rs

+51-61
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,12 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckLoanCtxt<'a, 'tcx> {
135135
borrow_id, cmt, loan_region,
136136
bk, loan_cause);
137137

138-
match opt_loan_path(&cmt) {
139-
Some(lp) => {
140-
let moved_value_use_kind = match loan_cause {
141-
euv::ClosureCapture(_) => MovedInCapture,
142-
_ => MovedInUse,
143-
};
144-
self.check_if_path_is_moved(borrow_id, borrow_span, moved_value_use_kind, &lp);
145-
}
146-
None => { }
138+
if let Some(lp) = opt_loan_path(&cmt) {
139+
let moved_value_use_kind = match loan_cause {
140+
euv::ClosureCapture(_) => MovedInCapture,
141+
_ => MovedInUse,
142+
};
143+
self.check_if_path_is_moved(borrow_id, borrow_span, moved_value_use_kind, &lp);
147144
}
148145

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

161-
match opt_loan_path(&assignee_cmt) {
162-
Some(lp) => {
163-
match mode {
164-
MutateMode::Init | MutateMode::JustWrite => {
165-
// In a case like `path = 1`, then path does not
166-
// have to be *FULLY* initialized, but we still
167-
// must be careful lest it contains derefs of
168-
// pointers.
169-
self.check_if_assigned_path_is_moved(assignee_cmt.id,
170-
assignment_span,
171-
MovedInUse,
172-
&lp);
173-
}
174-
MutateMode::WriteAndRead => {
175-
// In a case like `path += 1`, then path must be
176-
// fully initialized, since we will read it before
177-
// we write it.
178-
self.check_if_path_is_moved(assignee_cmt.id,
179-
assignment_span,
180-
MovedInUse,
181-
&lp);
182-
}
158+
if let Some(lp) = opt_loan_path(&assignee_cmt) {
159+
match mode {
160+
MutateMode::Init | MutateMode::JustWrite => {
161+
// In a case like `path = 1`, then path does not
162+
// have to be *FULLY* initialized, but we still
163+
// must be careful lest it contains derefs of
164+
// pointers.
165+
self.check_if_assigned_path_is_moved(assignee_cmt.id,
166+
assignment_span,
167+
MovedInUse,
168+
&lp);
169+
}
170+
MutateMode::WriteAndRead => {
171+
// In a case like `path += 1`, then path must be
172+
// fully initialized, since we will read it before
173+
// we write it.
174+
self.check_if_path_is_moved(assignee_cmt.id,
175+
assignment_span,
176+
MovedInUse,
177+
&lp);
183178
}
184179
}
185-
None => { }
186180
}
187-
188181
self.check_assignment(assignment_id, assignment_span, assignee_cmt);
189182
}
190183

@@ -601,39 +594,36 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
601594
span: Span,
602595
cmt: mc::cmt<'tcx>,
603596
mode: euv::ConsumeMode) {
604-
match opt_loan_path(&cmt) {
605-
Some(lp) => {
606-
let moved_value_use_kind = match mode {
607-
euv::Copy => {
608-
self.check_for_copy_of_frozen_path(id, span, &lp);
609-
MovedInUse
610-
}
611-
euv::Move(_) => {
612-
match self.move_data.kind_of_move_of_path(id, &lp) {
613-
None => {
614-
// Sometimes moves don't have a move kind;
615-
// this either means that the original move
616-
// was from something illegal to move,
617-
// or was moved from referent of an unsafe
618-
// pointer or something like that.
597+
if let Some(lp) = opt_loan_path(&cmt) {
598+
let moved_value_use_kind = match mode {
599+
euv::Copy => {
600+
self.check_for_copy_of_frozen_path(id, span, &lp);
601+
MovedInUse
602+
}
603+
euv::Move(_) => {
604+
match self.move_data.kind_of_move_of_path(id, &lp) {
605+
None => {
606+
// Sometimes moves don't have a move kind;
607+
// this either means that the original move
608+
// was from something illegal to move,
609+
// or was moved from referent of an unsafe
610+
// pointer or something like that.
611+
MovedInUse
612+
}
613+
Some(move_kind) => {
614+
self.check_for_move_of_borrowed_path(id, span,
615+
&lp, move_kind);
616+
if move_kind == move_data::Captured {
617+
MovedInCapture
618+
} else {
619619
MovedInUse
620620
}
621-
Some(move_kind) => {
622-
self.check_for_move_of_borrowed_path(id, span,
623-
&lp, move_kind);
624-
if move_kind == move_data::Captured {
625-
MovedInCapture
626-
} else {
627-
MovedInUse
628-
}
629-
}
630621
}
631622
}
632-
};
623+
}
624+
};
633625

634-
self.check_if_path_is_moved(id, span, moved_value_use_kind, &lp);
635-
}
636-
None => { }
626+
self.check_if_path_is_moved(id, span, moved_value_use_kind, &lp);
637627
}
638628
}
639629

Diff for: src/librustc_data_structures/control_flow_graph/dominators/mod.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ pub fn dominators_given_rpo<G: ControlFlowGraph>(graph: &G,
5757
// (*)
5858
// (*) dominators for `pred` have been calculated
5959
new_idom = intersect_opt(&post_order_rank,
60-
&immediate_dominators,
61-
new_idom,
62-
Some(pred));
60+
&immediate_dominators,
61+
new_idom,
62+
Some(pred));
6363
}
6464
}
6565

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

7979
fn intersect_opt<Node: Idx>(post_order_rank: &IndexVec<Node, usize>,
80-
immediate_dominators: &IndexVec<Node, Option<Node>>,
81-
node1: Option<Node>,
82-
node2: Option<Node>)
83-
-> Option<Node> {
80+
immediate_dominators: &IndexVec<Node, Option<Node>>,
81+
node1: Option<Node>,
82+
node2: Option<Node>)
83+
-> Option<Node> {
8484
match (node1, node2) {
8585
(None, None) => None,
8686
(Some(n), None) | (None, Some(n)) => Some(n),
@@ -89,10 +89,10 @@ fn intersect_opt<Node: Idx>(post_order_rank: &IndexVec<Node, usize>,
8989
}
9090

9191
fn intersect<Node: Idx>(post_order_rank: &IndexVec<Node, usize>,
92-
immediate_dominators: &IndexVec<Node, Option<Node>>,
93-
mut node1: Node,
94-
mut node2: Node)
95-
-> Node {
92+
immediate_dominators: &IndexVec<Node, Option<Node>>,
93+
mut node1: Node,
94+
mut node2: Node)
95+
-> Node {
9696
while node1 != node2 {
9797
while post_order_rank[node1] < post_order_rank[node2] {
9898
node1 = immediate_dominators[node1].unwrap();
@@ -142,9 +142,9 @@ impl<Node: Idx> Dominators<Node> {
142142
"node {:?} is not reachable",
143143
node2);
144144
intersect::<Node>(&self.post_order_rank,
145-
&self.immediate_dominators,
146-
node1,
147-
node2)
145+
&self.immediate_dominators,
146+
node1,
147+
node2)
148148
}
149149

150150
pub fn mutual_dominator<I>(&self, iter: I) -> Option<Node>

Diff for: src/librustc_data_structures/control_flow_graph/dominators/test.rs

+4-18
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@ use super::*;
1414

1515
#[test]
1616
fn diamond() {
17-
let graph = TestGraph::new(0, &[
18-
(0, 1),
19-
(0, 2),
20-
(1, 3),
21-
(2, 3),
22-
]);
17+
let graph = TestGraph::new(0, &[(0, 1), (0, 2), (1, 3), (2, 3)]);
2318

2419
let dominators = dominators(&graph);
2520
let immediate_dominators = dominators.all_immediate_dominators();
@@ -32,17 +27,9 @@ fn diamond() {
3227
#[test]
3328
fn paper() {
3429
// example from the paper:
35-
let graph = TestGraph::new(6, &[
36-
(6, 5),
37-
(6, 4),
38-
(5, 1),
39-
(4, 2),
40-
(4, 3),
41-
(1, 2),
42-
(2, 3),
43-
(3, 2),
44-
(2, 1),
45-
]);
30+
let graph = TestGraph::new(6,
31+
&[(6, 5), (6, 4), (5, 1), (4, 2), (4, 3), (1, 2), (2, 3), (3, 2),
32+
(2, 1)]);
4633

4734
let dominators = dominators(&graph);
4835
let immediate_dominators = dominators.all_immediate_dominators();
@@ -54,4 +41,3 @@ fn paper() {
5441
assert_eq!(immediate_dominators[5], Some(6));
5542
assert_eq!(immediate_dominators[6], Some(6));
5643
}
57-

0 commit comments

Comments
 (0)