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

librustc: Require the ref keyword to get by-reference closure #16610

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ pub fn make_tests(config: &Config) -> Vec<test::TestDescAndFn> {
let file = file.clone();
debug!("inspecting file {}", file.display());
if is_test(config, &file) {
let t = make_test(config, &file, || {
let t = make_test(config, &file, ref || {
match config.mode {
Codegen => make_metrics_test_closure(config, &file),
_ => make_test_closure(config, &file)
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn load_props(testfile: &Path) -> TestProps {
let mut no_pretty_expanded = false;
let mut pretty_mode = None;
let mut pretty_compare_only = false;
iter_header(testfile, |ln| {
iter_header(testfile, ref |ln| {
match parse_error_pattern(ln) {
Some(ep) => error_patterns.push(ep),
None => ()
Expand Down
4 changes: 2 additions & 2 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,13 +643,13 @@ fn parse_debugger_commands(file_path: &Path, debugger_prefix: &str)

header::parse_name_value_directive(
line.as_slice(),
command_directive.as_slice()).map(|cmd| {
command_directive.as_slice()).map(ref |cmd| {
commands.push(cmd)
});

header::parse_name_value_directive(
line.as_slice(),
check_directive.as_slice()).map(|cmd| {
check_directive.as_slice()).map(ref |cmd| {
check_lines.push(cmd)
});
}
Expand Down
10 changes: 5 additions & 5 deletions src/doc/guide-container.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ into a single value:

~~~
let xs = [1i, 9, 2, 3, 14, 12];
let result = xs.iter().fold(0, |accumulator, item| accumulator - *item);
let result = xs.iter().fold(0, ref |accumulator, item| accumulator - *item);
assert_eq!(result, -41);
~~~

Expand All @@ -165,7 +165,7 @@ Most adaptors return an adaptor object implementing the `Iterator` trait itself:
~~~
let xs = [1i, 9, 2, 3, 14, 12];
let ys = [5i, 2, 1, 8];
let sum = xs.iter().chain(ys.iter()).fold(0, |a, b| a + *b);
let sum = xs.iter().chain(ys.iter()).fold(0, ref |a, b| a + *b);
assert_eq!(sum, 57);
~~~

Expand All @@ -184,7 +184,7 @@ let xs = [1i,2,3,4,5];
let mut calls = 0i;

{
let it = xs.iter().scan((), |_, x| {
let it = xs.iter().scan((), ref |_, x| {
calls += 1;
if *x < 3 { Some(x) } else { None }});

Expand Down Expand Up @@ -266,7 +266,7 @@ Iterators offer generic conversion to containers with the `collect` adaptor:

~~~
let xs = [0i, 1, 1, 2, 3, 5, 8];
let ys = xs.iter().rev().skip(1).map(|&x| x * 2).collect::<Vec<int>>();
let ys = xs.iter().rev().skip(1).map(ref |&x| x * 2).collect::<Vec<int>>();
assert_eq!(ys, vec![10, 6, 4, 2, 2, 0]);
~~~

Expand Down Expand Up @@ -365,7 +365,7 @@ The `chain`, `map`, `filter`, `filter_map` and `inspect` adaptors are
~~~
let xs = [1i, 2, 3, 4];
let ys = [5i, 6, 7, 8];
let mut it = xs.iter().chain(ys.iter()).map(|&x| x * 2);
let mut it = xs.iter().chain(ys.iter()).map(ref |&x| x * 2);

println!("{}", it.next()); // prints `Some(2)`

Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ mod bench {

#[bench]
fn alloc_owned_small(b: &mut Bencher) {
b.iter(|| {
b.iter(ref || {
box 10i
})
}
Expand Down
20 changes: 10 additions & 10 deletions src/libarena/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ fn test_arena_alloc_nested() {

let arena = Arena::new();

let result = arena.alloc(|| Outer {
inner: arena.alloc(|| Inner { value: 10 })
let result = arena.alloc(ref || Outer {
inner: arena.alloc(ref || Inner { value: 10 })
});

assert_eq!(result.inner.value, 10);
Expand Down Expand Up @@ -527,7 +527,7 @@ mod tests {
#[bench]
pub fn bench_copy(b: &mut Bencher) {
let arena = TypedArena::new();
b.iter(|| {
b.iter(ref || {
arena.alloc(Point {
x: 1,
y: 2,
Expand All @@ -538,7 +538,7 @@ mod tests {

#[bench]
pub fn bench_copy_nonarena(b: &mut Bencher) {
b.iter(|| {
b.iter(ref || {
box Point {
x: 1,
y: 2,
Expand All @@ -550,8 +550,8 @@ mod tests {
#[bench]
pub fn bench_copy_old_arena(b: &mut Bencher) {
let arena = Arena::new();
b.iter(|| {
arena.alloc(|| {
b.iter(ref || {
arena.alloc(ref || {
Point {
x: 1,
y: 2,
Expand Down Expand Up @@ -580,7 +580,7 @@ mod tests {
#[bench]
pub fn bench_noncopy(b: &mut Bencher) {
let arena = TypedArena::new();
b.iter(|| {
b.iter(ref || {
arena.alloc(Noncopy {
string: "hello world".to_string(),
array: vec!( 1, 2, 3, 4, 5 ),
Expand All @@ -590,7 +590,7 @@ mod tests {

#[bench]
pub fn bench_noncopy_nonarena(b: &mut Bencher) {
b.iter(|| {
b.iter(ref || {
box Noncopy {
string: "hello world".to_string(),
array: vec!( 1, 2, 3, 4, 5 ),
Expand All @@ -601,8 +601,8 @@ mod tests {
#[bench]
pub fn bench_noncopy_old_arena(b: &mut Bencher) {
let arena = Arena::new();
b.iter(|| {
arena.alloc(|| Noncopy {
b.iter(ref || {
arena.alloc(ref || Noncopy {
string: "hello world".to_string(),
array: vec!( 1, 2, 3, 4, 5 ),
})
Expand Down
25 changes: 14 additions & 11 deletions src/libcollections/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,11 @@ impl Bitv {
pub fn all(&self) -> bool {
let mut last_word = !0u;
// Check that every word but the last is all-ones...
self.mask_words(0).all(|(_, elem)|
{ let tmp = last_word; last_word = elem; tmp == !0u }) &&
self.mask_words(0).all(ref |(_, elem)| {
let tmp = last_word;
last_word = elem;
tmp == !0u
}) &&
// ...and that the last word is ones as far as it needs to be
(last_word == ((1 << self.nbits % uint::BITS) - 1) || last_word == !0u)
}
Expand Down Expand Up @@ -2560,7 +2563,7 @@ mod tests {
fn bench_uint_small(b: &mut Bencher) {
let mut r = rng();
let mut bitv = 0 as uint;
b.iter(|| {
b.iter(ref || {
bitv |= 1 << ((r.next_u32() as uint) % uint::BITS);
&bitv
})
Expand All @@ -2570,7 +2573,7 @@ mod tests {
fn bench_bitv_big(b: &mut Bencher) {
let mut r = rng();
let mut bitv = Bitv::with_capacity(BENCH_BITS, false);
b.iter(|| {
b.iter(ref || {
bitv.set((r.next_u32() as uint) % BENCH_BITS, true);
&bitv
})
Expand All @@ -2580,7 +2583,7 @@ mod tests {
fn bench_bitv_small(b: &mut Bencher) {
let mut r = rng();
let mut bitv = Bitv::with_capacity(uint::BITS, false);
b.iter(|| {
b.iter(ref || {
bitv.set((r.next_u32() as uint) % uint::BITS, true);
&bitv
})
Expand All @@ -2590,7 +2593,7 @@ mod tests {
fn bench_bitv_set_small(b: &mut Bencher) {
let mut r = rng();
let mut bitv = BitvSet::new();
b.iter(|| {
b.iter(ref || {
bitv.insert((r.next_u32() as uint) % uint::BITS);
&bitv
})
Expand All @@ -2600,7 +2603,7 @@ mod tests {
fn bench_bitv_set_big(b: &mut Bencher) {
let mut r = rng();
let mut bitv = BitvSet::new();
b.iter(|| {
b.iter(ref || {
bitv.insert((r.next_u32() as uint) % BENCH_BITS);
&bitv
})
Expand All @@ -2610,15 +2613,15 @@ mod tests {
fn bench_bitv_big_union(b: &mut Bencher) {
let mut b1 = Bitv::with_capacity(BENCH_BITS, false);
let b2 = Bitv::with_capacity(BENCH_BITS, false);
b.iter(|| {
b.iter(ref || {
b1.union(&b2);
})
}

#[bench]
fn bench_btv_small_iter(b: &mut Bencher) {
let bitv = Bitv::with_capacity(uint::BITS, false);
b.iter(|| {
b.iter(ref || {
let mut _sum = 0;
for pres in bitv.iter() {
_sum += pres as uint;
Expand All @@ -2629,7 +2632,7 @@ mod tests {
#[bench]
fn bench_bitv_big_iter(b: &mut Bencher) {
let bitv = Bitv::with_capacity(BENCH_BITS, false);
b.iter(|| {
b.iter(ref || {
let mut _sum = 0;
for pres in bitv.iter() {
_sum += pres as uint;
Expand All @@ -2641,7 +2644,7 @@ mod tests {
fn bench_bitvset_iter(b: &mut Bencher) {
let bitv = BitvSet::from_bitv(from_fn(BENCH_BITS,
|idx| {idx % 3 == 0}));
b.iter(|| {
b.iter(ref || {
let mut _sum = 0;
for idx in bitv.iter() {
_sum += idx;
Expand Down
14 changes: 8 additions & 6 deletions src/libcollections/btree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ impl<K: Clone + Ord, V: Clone> Leaf<K, V> {
if self.elts.len() > ub {
let midpoint_opt = self.elts.remove(ub / 2);
let midpoint = midpoint_opt.unwrap();
let (left_leaf, right_leaf) = self.elts.partition(|le|
le.key.cmp(&midpoint.key.clone())
== Less);
let (left_leaf, right_leaf) = self.elts.partition(ref |le| {
le.key.cmp(&midpoint.key.clone()) == Less
});
let branch_return = Node::new_branch(vec!(BranchElt::new(midpoint.key.clone(),
midpoint.value.clone(),
box Node::new_leaf(left_leaf))),
Expand Down Expand Up @@ -613,9 +613,11 @@ impl<K: Clone + Ord, V: Clone> Branch<K, V> {
//and two children.
if self.elts.len() > ub {
let midpoint = self.elts.remove(ub / 2).unwrap();
let (new_left, new_right) = self.clone().elts.partition(|le|
midpoint.key.cmp(&le.key)
== Greater);
let (new_left, new_right) = self.clone()
.elts
.partition(ref |le| {
midpoint.key.cmp(&le.key) == Greater
});
new_branch = Node::new_branch(
vec!(BranchElt::new(midpoint.clone().key,
midpoint.clone().value,
Expand Down
8 changes: 4 additions & 4 deletions src/libcollections/deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub mod bench {
}

// measure
b.iter(|| {
b.iter(ref || {
let k = rng.gen::<uint>() % n;
map.insert(k, 1);
map.remove(&k);
Expand All @@ -48,7 +48,7 @@ pub mod bench {

// measure
let mut i = 1;
b.iter(|| {
b.iter(ref || {
map.insert(i, 1);
map.remove(&i);
i = (i + 2) % n;
Expand All @@ -70,7 +70,7 @@ pub mod bench {

// measure
let mut i = 0;
b.iter(|| {
b.iter(ref || {
map.find(&keys[i]);
i = (i + 1) % n;
})
Expand All @@ -86,7 +86,7 @@ pub mod bench {

// measure
let mut i = 0;
b.iter(|| {
b.iter(ref || {
let x = map.find(&i);
i = (i + 1) % n;
x
Expand Down
Loading