Skip to content

Commit a243360

Browse files
committed
Move std::util::ignore to std::prelude::drop
It's a more fitting name for the most common use case of this function.
1 parent 693ec73 commit a243360

13 files changed

+19
-29
lines changed

Diff for: src/librustuv/timer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ impl RtioTimer for TimerWatcher {
7777
let _missile = match util::replace(&mut self.action, None) {
7878
None => missile, // no need to do a homing dance
7979
Some(action) => {
80-
util::ignore(missile); // un-home ourself
81-
util::ignore(action); // destroy the previous action
80+
drop(missile); // un-home ourself
81+
drop(action); // destroy the previous action
8282
self.fire_homing_missile() // re-home ourself
8383
}
8484
};

Diff for: src/librustuv/uvio.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use std::libc::{O_CREAT, O_APPEND, O_TRUNC, O_RDWR, O_RDONLY, O_WRONLY,
2626
use std::io::{FileMode, FileAccess, Open, Append, Truncate, Read, Write,
2727
ReadWrite, FileStat};
2828
use std::io::signal::Signum;
29-
use std::util;
3029
use ai = std::io::net::addrinfo;
3130

3231
#[cfg(test)] use std::unstable::run_in_bare_thread;
@@ -104,7 +103,7 @@ impl HomingMissile {
104103

105104
impl Drop for HomingMissile {
106105
fn drop(&mut self) {
107-
let f = ForbidUnwind::new("leaving home");
106+
let _f = ForbidUnwind::new("leaving home");
108107

109108
// It would truly be a sad day if we had moved off the home I/O
110109
// scheduler while we were doing I/O.
@@ -120,8 +119,6 @@ impl Drop for HomingMissile {
120119
});
121120
})
122121
}
123-
124-
util::ignore(f);
125122
}
126123
}
127124

Diff for: src/libstd/io/fs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ mod test {
11791179
file.write(bytes!("foo"));
11801180
file.fsync();
11811181
file.datasync();
1182-
util::ignore(file);
1182+
drop(file);
11831183
})
11841184

11851185
test!(fn truncate_works() {
@@ -1210,7 +1210,7 @@ mod test {
12101210
assert_eq!(stat(&path).size, 9);
12111211
assert_eq!(File::open(&path).read_to_end(),
12121212
(bytes!("fo", 0, 0, 0, 0, "wut")).to_owned());
1213-
util::ignore(file);
1213+
drop(file);
12141214
})
12151215

12161216
test!(fn open_flavors() {

Diff for: src/libstd/prelude.rs

+4
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,7 @@ pub use vec::{Vector, VectorVector, CopyableVector, ImmutableVector};
8686
// Reexported runtime types
8787
pub use comm::{stream, Port, Chan, GenericChan, GenericSmartChan, GenericPort, Peekable};
8888
pub use task::spawn;
89+
90+
/// Disposes of a value.
91+
#[inline]
92+
pub fn drop<T>(_x: T) { }

Diff for: src/libstd/rt/sched.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,6 @@ mod test {
11731173
use rt::sleeper_list::SleeperList;
11741174
use rt::stack::StackPool;
11751175
use rt::sched::{Shutdown, TaskFromFriend};
1176-
use util;
11771176

11781177
do run_in_bare_thread {
11791178
stress_factor().times(|| {
@@ -1205,7 +1204,7 @@ mod test {
12051204
handle.send(TaskFromFriend(task));
12061205

12071206
handle.send(Shutdown);
1208-
util::ignore(handle);
1207+
drop(handle);
12091208

12101209
thread.join();
12111210
})

Diff for: src/libstd/unstable/sync.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,6 @@ mod tests {
467467
use prelude::*;
468468
use super::{Exclusive, UnsafeArc, atomically};
469469
use task;
470-
use util;
471470
use mem::size_of;
472471

473472
//#[unsafe_no_drop_flag] FIXME: #9758
@@ -571,7 +570,7 @@ mod tests {
571570
let x2 = x.clone();
572571
let left_x = x.try_unwrap();
573572
assert!(left_x.is_self());
574-
util::ignore(left_x);
573+
drop(left_x);
575574
assert!(x2.try_unwrap().expect_t("try_unwrap none") == ~~"hello");
576575
}
577576
@@ -590,7 +589,7 @@ mod tests {
590589
task::deschedule(); // Try to make the unwrapper get blocked first.
591590
let left_x = x.try_unwrap();
592591
assert!(left_x.is_self());
593-
util::ignore(left_x);
592+
drop(left_x);
594593
p.recv();
595594
}
596595
@@ -620,7 +619,7 @@ mod tests {
620619
assert!(x2.unwrap() == ~~"hello");
621620
}
622621
// Have to get rid of our reference before blocking.
623-
util::ignore(x);
622+
drop(x);
624623
res.recv();
625624
}
626625

Diff for: src/libstd/util.rs

-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ use unstable::intrinsics;
1919
#[inline]
2020
pub fn id<T>(x: T) -> T { x }
2121

22-
/// Ignores a value.
23-
#[inline]
24-
pub fn ignore<T>(_x: T) { }
25-
2622
/**
2723
* Swap the values at two mutable locations of the same type, without
2824
* deinitialising or copying either one.

Diff for: src/test/compile-fail/lint-unused-imports.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ mod bar {
6363
fn main() {
6464
cal(foo::Point{x:3, y:9});
6565
let a = 3;
66-
ignore(a);
66+
id(a);
6767
test::C.b();
6868
let _a = from_elem(0, 0);
6969
}

Diff for: src/test/compile-fail/once-cant-call-twice-on-heap.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#[feature(once_fns)];
1515
extern mod extra;
1616
use extra::arc;
17-
use std::util;
1817

1918
fn foo(blk: proc()) {
2019
blk();
@@ -25,6 +24,6 @@ fn main() {
2524
let x = arc::Arc::new(true);
2625
do foo {
2726
assert!(*x.get());
28-
util::ignore(x);
27+
drop(x);
2928
}
3029
}

Diff for: src/test/compile-fail/once-cant-call-twice-on-stack.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#[feature(once_fns)];
1515
extern mod extra;
1616
use extra::arc;
17-
use std::util;
1817

1918
fn foo(blk: once ||) {
2019
blk();
@@ -25,6 +24,6 @@ fn main() {
2524
let x = arc::Arc::new(true);
2625
foo(|| {
2726
assert!(*x.get());
28-
util::ignore(x);
27+
drop(x);
2928
})
3029
}

Diff for: src/test/compile-fail/once-cant-move-out-of-non-once-on-stack.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
extern mod extra;
1515
use extra::arc;
16-
use std::util;
1716

1817
fn foo(blk: ||) {
1918
blk();
@@ -24,6 +23,6 @@ fn main() {
2423
let x = arc::Arc::new(true);
2524
foo(|| {
2625
assert!(*x.get());
27-
util::ignore(x); //~ ERROR cannot move out of captured outer variable
26+
drop(x); //~ ERROR cannot move out of captured outer variable
2827
})
2928
}

Diff for: src/test/run-pass/once-move-out-on-heap.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#[feature(once_fns)];
1616
extern mod extra;
1717
use extra::arc;
18-
use std::util;
1918

2019
fn foo(blk: proc()) {
2120
blk();
@@ -25,6 +24,6 @@ fn main() {
2524
let x = arc::Arc::new(true);
2625
do foo {
2726
assert!(*x.get());
28-
util::ignore(x);
27+
drop(x);
2928
}
3029
}

Diff for: src/test/run-pass/once-move-out-on-stack.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#[feature(once_fns)];
1616
extern mod extra;
1717
use extra::arc;
18-
use std::util;
1918

2019
fn foo(blk: once ||) {
2120
blk();
@@ -25,6 +24,6 @@ fn main() {
2524
let x = arc::Arc::new(true);
2625
foo(|| {
2726
assert!(*x.get());
28-
util::ignore(x);
27+
drop(x);
2928
})
3029
}

0 commit comments

Comments
 (0)