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

Move replace and swap to std::mem. Get rid of std::util #11956

Merged
merged 1 commit into from
Feb 11, 2014
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
3 changes: 1 addition & 2 deletions src/libarena/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ use std::rc::Rc;
use std::rt::global_heap;
use std::unstable::intrinsics::{TyDesc, get_tydesc};
use std::unstable::intrinsics;
use std::util;
use std::vec;

// The way arena uses arrays is really deeply awful. The arrays are
Expand Down Expand Up @@ -404,7 +403,7 @@ impl TypedArenaChunk {
}

// Destroy the next chunk.
let next_opt = util::replace(&mut self.next, None);
let next_opt = mem::replace(&mut self.next, None);
match next_opt {
None => {}
Some(mut next) => {
Expand Down
8 changes: 4 additions & 4 deletions src/libcollections/dlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
// the reverse direction.

use std::cast;
use std::mem::{replace, swap};
use std::ptr;
use std::util;
use std::iter::Rev;
use std::iter;

Expand Down Expand Up @@ -102,7 +102,7 @@ impl<T> Rawlink<T> {

/// Return the `Rawlink` and replace with `Rawlink::none()`
fn take(&mut self) -> Rawlink<T> {
util::replace(self, Rawlink::none())
replace(self, Rawlink::none())
}
}

Expand Down Expand Up @@ -161,7 +161,7 @@ impl<T> DList<T> {
Some(ref mut head) => {
new_head.prev = Rawlink::none();
head.prev = Rawlink::some(new_head);
util::swap(head, &mut new_head);
swap(head, &mut new_head);
head.next = Some(new_head);
}
}
Expand Down Expand Up @@ -319,7 +319,7 @@ impl<T> DList<T> {
/// O(1)
#[inline]
pub fn prepend(&mut self, mut other: DList<T>) {
util::swap(self, &mut other);
swap(self, &mut other);
self.append(other);
}

Expand Down
3 changes: 1 addition & 2 deletions src/libcollections/priority_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
#[allow(missing_doc)];

use std::clone::Clone;
use std::mem::{move_val_init, init};
use std::util::{replace, swap};
use std::mem::{move_val_init, init, replace, swap};
use std::vec;

/// A priority queue implemented with a binary heap
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/smallintmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#[allow(missing_doc)];

use std::iter::{Enumerate, FilterMap, Rev};
use std::util::replace;
use std::mem::replace;
use std::vec;

#[allow(missing_doc)]
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/treemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
//! trees. The only requirement for the types is that the key implements
//! `TotalOrd`.

use std::util::{swap, replace};
use std::iter::{Peekable};
use std::cmp::Ordering;
use std::mem::{replace, swap};
use std::ptr;

use serialize::{Encodable, Decodable, Encoder, Decoder};
Expand Down
5 changes: 3 additions & 2 deletions src/libextra/num/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2592,7 +2592,8 @@ mod bigint_tests {
#[cfg(test)]
mod bench {
use super::*;
use std::{iter, util};
use std::iter;
use std::mem::replace;
use std::num::{FromPrimitive, Zero, One};
use extra::test::BenchHarness;

Expand All @@ -2609,7 +2610,7 @@ mod bench {
let mut f1: BigUint = One::one();
for _ in range(0, n) {
let f2 = f0 + f1;
f0 = util::replace(&mut f1, f2);
f0 = replace(&mut f1, f2);
}
f0
}
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
use std::cmp;
use std::hashmap;
use std::io;
use std::mem;
use std::num;
use std::util;

// NB: this can probably be rewritten in terms of num::Num
// to be less f64-specific.
Expand Down Expand Up @@ -178,7 +178,7 @@ impl<'a> Stats for &'a [f64] {
for i in range(0, partials.len()) {
let mut y = partials[i];
if num::abs(x) < num::abs(y) {
util::swap(&mut x, &mut y);
mem::swap(&mut x, &mut y);
}
// Rounded `x+y` is stored in `hi` with round-off stored in
// `lo`. Together `hi+lo` are exactly equal to `x+y`.
Expand Down
6 changes: 3 additions & 3 deletions src/libgreen/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
//! loop if no other one is provided (and M:N scheduling is desired).

use std::cast;
use std::mem::replace;
use std::rt::rtio::{EventLoop, IoFactory, RemoteCallback, PausableIdleCallback,
Callback};
use std::unstable::sync::Exclusive;
use std::util;

/// This is the only exported function from this module.
pub fn event_loop() -> ~EventLoop {
Expand Down Expand Up @@ -50,7 +50,7 @@ impl BasicLoop {
/// Process everything in the work queue (continually)
fn work(&mut self) {
while self.work.len() > 0 {
for work in util::replace(&mut self.work, ~[]).move_iter() {
for work in replace(&mut self.work, ~[]).move_iter() {
work();
}
}
Expand All @@ -60,7 +60,7 @@ impl BasicLoop {
let messages = unsafe {
self.messages.with(|messages| {
if messages.len() > 0 {
Some(util::replace(messages, ~[]))
Some(replace(messages, ~[]))
} else {
None
}
Expand Down
6 changes: 3 additions & 3 deletions src/libgreen/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
// NB this does *not* include globs, please keep it that way.
#[feature(macro_rules)];

use std::mem::replace;
use std::os;
use std::rt::crate_map;
use std::rt::rtio;
Expand All @@ -182,7 +183,6 @@ use std::rt;
use std::sync::atomics::{SeqCst, AtomicUint, INIT_ATOMIC_UINT};
use std::sync::deque;
use std::task::TaskOpts;
use std::util;
use std::vec;
use std::sync::arc::UnsafeArc;

Expand Down Expand Up @@ -457,10 +457,10 @@ impl SchedPool {
}

// Now that everyone's gone, tell everything to shut down.
for mut handle in util::replace(&mut self.handles, ~[]).move_iter() {
for mut handle in replace(&mut self.handles, ~[]).move_iter() {
handle.send(Shutdown);
}
for thread in util::replace(&mut self.threads, ~[]).move_iter() {
for thread in replace(&mut self.threads, ~[]).move_iter() {
thread.join();
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/privacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//! which are available for use externally when compiled as a library.

use std::hashmap::{HashSet, HashMap};
use std::util;
use std::mem::replace;

use metadata::csearch;
use middle::resolve;
Expand Down Expand Up @@ -679,7 +679,7 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> {
return;
}

let orig_curitem = util::replace(&mut self.curitem, item.id);
let orig_curitem = replace(&mut self.curitem, item.id);
visit::walk_item(self, item, ());
self.curitem = orig_curitem;
}
Expand Down Expand Up @@ -861,7 +861,7 @@ impl Visitor<()> for SanePrivacyVisitor {
self.check_sane_privacy(item);
}

let orig_in_fn = util::replace(&mut self.in_fn, match item.node {
let orig_in_fn = replace(&mut self.in_fn, match item.node {
ast::ItemMod(..) => false, // modules turn privacy back on
_ => self.in_fn, // otherwise we inherit
});
Expand All @@ -872,7 +872,7 @@ impl Visitor<()> for SanePrivacyVisitor {
fn visit_fn(&mut self, fk: &visit::FnKind, fd: &ast::FnDecl,
b: &ast::Block, s: Span, n: ast::NodeId, _: ()) {
// This catches both functions and methods
let orig_in_fn = util::replace(&mut self.in_fn, true);
let orig_in_fn = replace(&mut self.in_fn, true);
visit::walk_fn(self, fk, fd, b, s, n, ());
self.in_fn = orig_in_fn;
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use syntax::visit::Visitor;
use std::cell::{Cell, RefCell};
use std::uint;
use std::hashmap::{HashMap, HashSet};
use std::util;
use std::mem::replace;

// Definition mapping
pub type DefMap = @RefCell<HashMap<NodeId,Def>>;
Expand Down Expand Up @@ -4067,7 +4067,7 @@ impl Resolver {
new_trait_refs.push(def_id_of_def(*def));
}
}
original_trait_refs = Some(util::replace(
original_trait_refs = Some(replace(
&mut this.current_trait_refs,
Some(new_trait_refs)));
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ use util::ppaux::{UserString, Repr};

use std::cell::{Cell, RefCell};
use std::hashmap::HashMap;
use std::mem::replace;
use std::result;
use std::util::replace;
use std::vec;
use syntax::abi::AbiSet;
use syntax::ast::{Provided, Required};
Expand Down
5 changes: 2 additions & 3 deletions src/librustdoc/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std;
use clean::*;
use std::iter::Extendable;
use std::mem::{replace, swap};

pub trait DocFolder {
fn fold_item(&mut self, item: Item) -> Option<Item> {
Expand All @@ -19,7 +19,6 @@ pub trait DocFolder {

/// don't override!
fn fold_item_recur(&mut self, item: Item) -> Option<Item> {
use std::util::swap;
let Item { attrs, name, source, visibility, id, inner } = item;
let inner = inner;
let c = |x| self.fold_item(x);
Expand Down Expand Up @@ -92,7 +91,7 @@ pub trait DocFolder {
}

fn fold_crate(&mut self, mut c: Crate) -> Crate {
c.module = match std::util::replace(&mut c.module, None) {
c.module = match replace(&mut c.module, None) {
Some(module) => self.fold_item(module), None => None
};
return c;
Expand Down
8 changes: 4 additions & 4 deletions src/librustuv/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
// except according to those terms.

use std::libc::c_int;
use std::mem::replace;
use std::rt::local::Local;
use std::rt::rtio::RtioTimer;
use std::rt::task::{BlockedTask, Task};
use std::util;

use homing::{HomeHandle, HomingIO};
use super::{UvHandle, ForbidUnwind, ForbidSwitch};
Expand Down Expand Up @@ -76,7 +76,7 @@ impl RtioTimer for TimerWatcher {
let missile = self.fire_homing_missile();
self.id += 1;
self.stop();
let _missile = match util::replace(&mut self.action, None) {
let _missile = match replace(&mut self.action, None) {
None => missile, // no need to do a homing dance
Some(action) => {
drop(missile); // un-home ourself
Expand Down Expand Up @@ -108,7 +108,7 @@ impl RtioTimer for TimerWatcher {
self.id += 1;
self.stop();
self.start(msecs, 0);
util::replace(&mut self.action, Some(SendOnce(chan)))
replace(&mut self.action, Some(SendOnce(chan)))
};

return port;
Expand All @@ -124,7 +124,7 @@ impl RtioTimer for TimerWatcher {
self.id += 1;
self.stop();
self.start(msecs, msecs);
util::replace(&mut self.action, Some(SendMany(chan, self.id)))
replace(&mut self.action, Some(SendMany(chan, self.id)))
};

return port;
Expand Down
4 changes: 3 additions & 1 deletion src/libstd/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ use result::{Result, Ok, Err};
use to_str::ToStr;
use unstable::intrinsics::TypeId;
use unstable::intrinsics;
use util::Void;

/// A type with no inhabitants
pub enum Void { }

///////////////////////////////////////////////////////////////////////////////
// Any trait
Expand Down
1 change: 0 additions & 1 deletion src/libstd/comm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ macro_rules! test (
use super::*;
use super::super::*;
use task;
use util;

fn f() $b

Expand Down
10 changes: 5 additions & 5 deletions src/libstd/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ will look like `"\\{"`.

*/

use any;
use cast;
use char::Char;
use container::Container;
Expand All @@ -489,7 +490,6 @@ use repr;
use result::{Ok, Err};
use str::StrSlice;
use str;
use util;
use vec::ImmutableVector;
use vec;

Expand Down Expand Up @@ -524,8 +524,8 @@ pub struct Formatter<'a> {
/// compile time it is ensured that the function and the value have the correct
/// types, and then this struct is used to canonicalize arguments to one type.
pub struct Argument<'a> {
priv formatter: extern "Rust" fn(&util::Void, &mut Formatter) -> Result,
priv value: &'a util::Void,
priv formatter: extern "Rust" fn(&any::Void, &mut Formatter) -> Result,
priv value: &'a any::Void,
}

impl<'a> Arguments<'a> {
Expand Down Expand Up @@ -794,11 +794,11 @@ impl<'a> Formatter<'a> {
rt::CountImplied => { None }
rt::CountIsParam(i) => {
let v = self.args[i].value;
unsafe { Some(*(v as *util::Void as *uint)) }
unsafe { Some(*(v as *any::Void as *uint)) }
}
rt::CountIsNextParam => {
let v = self.curarg.next().unwrap().value;
unsafe { Some(*(v as *util::Void as *uint)) }
unsafe { Some(*(v as *any::Void as *uint)) }
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ use hash::Hash;
use iter;
use iter::{Iterator, FromIterator, Extendable};
use iter::{FilterMap, Chain, Repeat, Zip};
use mem::replace;
use num;
use option::{None, Option, Some};
use rand::Rng;
use rand;
use util::replace;
use vec::{ImmutableVector, MutableVector, OwnedVector, Items, MutItems};
use vec_ng;
use vec_ng::Vec;
Expand Down
1 change: 0 additions & 1 deletion src/libstd/io/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,6 @@ mod test {
use io::fs::{File, rmdir, mkdir, readdir, rmdir_recursive,
mkdir_recursive, copy, unlink, stat, symlink, link,
readlink, chmod, lstat, change_file_times};
use util;
use path::Path;
use io;
use ops::Drop;
Expand Down
Loading