Skip to content

Commit 3cc3ad1

Browse files
authoredJul 15, 2016
Auto merge of #34819 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 7 pull requests - Successful merges: #34456, #34733, #34777, #34794, #34799, #34804, #34818 - Failed merges: #33951
·
1.88.01.12.0
2 parents b6c1ef3 + 8959374 commit 3cc3ad1

File tree

19 files changed

+200
-80
lines changed

19 files changed

+200
-80
lines changed
 

‎src/doc/book/ffi.md

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,62 @@ pub fn uncompress(src: &[u8]) -> Option<Vec<u8>> {
183183
}
184184
```
185185

186-
For reference, the examples used here are also available as a [library on
187-
GitHub](https://github.com/thestinger/rust-snappy).
186+
Then, we can add some tests to show how to use them.
187+
188+
```rust
189+
# #![feature(libc)]
190+
# extern crate libc;
191+
# use libc::{c_int, size_t};
192+
# unsafe fn snappy_compress(input: *const u8,
193+
# input_length: size_t,
194+
# compressed: *mut u8,
195+
# compressed_length: *mut size_t)
196+
# -> c_int { 0 }
197+
# unsafe fn snappy_uncompress(compressed: *const u8,
198+
# compressed_length: size_t,
199+
# uncompressed: *mut u8,
200+
# uncompressed_length: *mut size_t)
201+
# -> c_int { 0 }
202+
# unsafe fn snappy_max_compressed_length(source_length: size_t) -> size_t { 0 }
203+
# unsafe fn snappy_uncompressed_length(compressed: *const u8,
204+
# compressed_length: size_t,
205+
# result: *mut size_t)
206+
# -> c_int { 0 }
207+
# unsafe fn snappy_validate_compressed_buffer(compressed: *const u8,
208+
# compressed_length: size_t)
209+
# -> c_int { 0 }
210+
# fn main() { }
211+
212+
#[cfg(test)]
213+
mod tests {
214+
use super::*;
215+
216+
#[test]
217+
fn valid() {
218+
let d = vec![0xde, 0xad, 0xd0, 0x0d];
219+
let c: &[u8] = &compress(&d);
220+
assert!(validate_compressed_buffer(c));
221+
assert!(uncompress(c) == Some(d));
222+
}
223+
224+
#[test]
225+
fn invalid() {
226+
let d = vec![0, 0, 0, 0];
227+
assert!(!validate_compressed_buffer(&d));
228+
assert!(uncompress(&d).is_none());
229+
}
230+
231+
#[test]
232+
fn empty() {
233+
let d = vec![];
234+
assert!(!validate_compressed_buffer(&d));
235+
assert!(uncompress(&d).is_none());
236+
let c = compress(&d);
237+
assert!(validate_compressed_buffer(&c));
238+
assert!(uncompress(&c) == Some(d));
239+
}
240+
}
241+
```
188242

189243
# Destructors
190244

‎src/liballoc/arc.rs

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,11 @@
1212

1313
//! Threadsafe reference-counted boxes (the `Arc<T>` type).
1414
//!
15-
//! The `Arc<T>` type provides shared ownership of an immutable value.
16-
//! Destruction is deterministic, and will occur as soon as the last owner is
17-
//! gone. It is marked as `Send` because it uses atomic reference counting.
18-
//!
19-
//! If you do not need thread-safety, and just need shared ownership, consider
20-
//! the [`Rc<T>` type](../rc/struct.Rc.html). It is the same as `Arc<T>`, but
21-
//! does not use atomics, making it both thread-unsafe as well as significantly
22-
//! faster when updating the reference count.
23-
//!
24-
//! The `downgrade` method can be used to create a non-owning `Weak<T>` pointer
25-
//! to the box. A `Weak<T>` pointer can be upgraded to an `Arc<T>` pointer, but
26-
//! will return `None` if the value has already been dropped.
27-
//!
28-
//! For example, a tree with parent pointers can be represented by putting the
29-
//! nodes behind strong `Arc<T>` pointers, and then storing the parent pointers
30-
//! as `Weak<T>` pointers.
15+
//! The `Arc<T>` type provides shared ownership of an immutable value through
16+
//! atomic reference counting.
3117
//!
18+
//! `Weak<T>` is a weak reference to the `Arc<T>` box, and it is created by
19+
//! the `downgrade` method.
3220
//! # Examples
3321
//!
3422
//! Sharing some immutable data between threads:
@@ -47,27 +35,6 @@
4735
//! });
4836
//! }
4937
//! ```
50-
//!
51-
//! Sharing mutable data safely between threads with a `Mutex`:
52-
//!
53-
//! ```no_run
54-
//! use std::sync::{Arc, Mutex};
55-
//! use std::thread;
56-
//!
57-
//! let five = Arc::new(Mutex::new(5));
58-
//!
59-
//! for _ in 0..10 {
60-
//! let five = five.clone();
61-
//!
62-
//! thread::spawn(move || {
63-
//! let mut number = five.lock().unwrap();
64-
//!
65-
//! *number += 1;
66-
//!
67-
//! println!("{}", *number); // prints 6
68-
//! });
69-
//! }
70-
//! ```
7138
7239
use boxed::Box;
7340

@@ -92,15 +59,19 @@ use heap::deallocate;
9259
const MAX_REFCOUNT: usize = (isize::MAX) as usize;
9360

9461
/// An atomically reference counted wrapper for shared state.
62+
/// Destruction is deterministic, and will occur as soon as the last owner is
63+
/// gone. It is marked as `Send` because it uses atomic reference counting.
9564
///
96-
/// # Examples
65+
/// If you do not need thread-safety, and just need shared ownership, consider
66+
/// the [`Rc<T>` type](../rc/struct.Rc.html). It is the same as `Arc<T>`, but
67+
/// does not use atomics, making it both thread-unsafe as well as significantly
68+
/// faster when updating the reference count.
9769
///
98-
/// In this example, a large vector is shared between several threads.
99-
/// With simple pipes, without `Arc`, a copy would have to be made for each
100-
/// thread.
70+
/// # Examples
10171
///
102-
/// When you clone an `Arc<T>`, it will create another pointer to the data and
103-
/// increase the reference counter.
72+
/// In this example, a large vector of data will be shared by several threads. First we
73+
/// wrap it with a `Arc::new` and then clone the `Arc<T>` reference for every thread (which will
74+
/// increase the reference count atomically).
10475
///
10576
/// ```
10677
/// use std::sync::Arc;
@@ -111,6 +82,7 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
11182
/// let shared_numbers = Arc::new(numbers);
11283
///
11384
/// for _ in 0..10 {
85+
/// // prepare a copy of reference here and it will be moved to the thread
11486
/// let child_numbers = shared_numbers.clone();
11587
///
11688
/// thread::spawn(move || {
@@ -121,6 +93,29 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
12193
/// }
12294
/// }
12395
/// ```
96+
/// You can also share mutable data between threads safely
97+
/// by putting it inside `Mutex` and then share `Mutex` immutably
98+
/// with `Arc<T>` as shown below.
99+
///
100+
/// ```
101+
/// use std::sync::{Arc, Mutex};
102+
/// use std::thread;
103+
///
104+
/// let five = Arc::new(Mutex::new(5));
105+
///
106+
/// for _ in 0..10 {
107+
/// let five = five.clone();
108+
///
109+
/// thread::spawn(move || {
110+
/// let mut number = five.lock().unwrap();
111+
///
112+
/// *number += 1;
113+
///
114+
/// println!("{}", *number); // prints 6
115+
/// });
116+
/// }
117+
/// ```
118+
124119
#[unsafe_no_drop_flag]
125120
#[stable(feature = "rust1", since = "1.0.0")]
126121
pub struct Arc<T: ?Sized> {
@@ -139,6 +134,14 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Arc<U>> for Arc<T> {}
139134
///
140135
/// Weak pointers will not keep the data inside of the `Arc` alive, and can be
141136
/// used to break cycles between `Arc` pointers.
137+
///
138+
/// A `Weak<T>` pointer can be upgraded to an `Arc<T>` pointer, but
139+
/// will return `None` if the value has already been dropped.
140+
///
141+
/// For example, a tree with parent pointers can be represented by putting the
142+
/// nodes behind strong `Arc<T>` pointers, and then storing the parent pointers
143+
/// as `Weak<T>` pointers.
144+
142145
#[unsafe_no_drop_flag]
143146
#[stable(feature = "arc_weak", since = "1.4.0")]
144147
pub struct Weak<T: ?Sized> {

‎src/libcollections/vec.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,6 +1603,12 @@ impl<'a, T> FromIterator<T> for Cow<'a, [T]> where T: Clone {
16031603
////////////////////////////////////////////////////////////////////////////////
16041604

16051605
/// An iterator that moves out of a vector.
1606+
///
1607+
/// This `struct` is created by the `into_iter` method on [`Vec`][`Vec`] (provided
1608+
/// by the [`IntoIterator`] trait).
1609+
///
1610+
/// [`Vec`]: struct.Vec.html
1611+
/// [`IntoIterator`]: ../../std/iter/trait.IntoIterator.html
16061612
#[stable(feature = "rust1", since = "1.0.0")]
16071613
pub struct IntoIter<T> {
16081614
_buf: RawVec<T>,
@@ -1710,6 +1716,11 @@ impl<T> Drop for IntoIter<T> {
17101716
}
17111717

17121718
/// A draining iterator for `Vec<T>`.
1719+
///
1720+
/// This `struct` is created by the [`drain`] method on [`Vec`].
1721+
///
1722+
/// [`drain`]: struct.Vec.html#method.drain
1723+
/// [`Vec`]: struct.Vec.html
17131724
#[stable(feature = "drain", since = "1.6.0")]
17141725
pub struct Drain<'a, T: 'a> {
17151726
/// Index of tail to preserve

‎src/libcore/macros.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ macro_rules! write {
238238
}
239239

240240
/// Use the `format!` syntax to write data into a buffer, appending a newline.
241+
/// On all platforms, the newline is the LINE FEED character (`\n`/`U+000A`)
242+
/// alone (no additional CARRIAGE RETURN (`\r`/`U+000D`).
241243
///
242244
/// This macro is typically used with a buffer of `&mut `[`Write`][write].
243245
///

‎src/libcore/num/mod.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,26 +2308,45 @@ impl usize {
23082308
///
23092309
/// [`f32::classify()`]: ../../std/primitive.f32.html#method.classify
23102310
/// [`f64::classify()`]: ../../std/primitive.f64.html#method.classify
2311+
///
2312+
/// # Examples
2313+
///
2314+
/// ```
2315+
/// use std::num::FpCategory;
2316+
/// use std::f32;
2317+
///
2318+
/// let num = 12.4_f32;
2319+
/// let inf = f32::INFINITY;
2320+
/// let zero = 0f32;
2321+
/// let sub: f32 = 0.000000000000000000000000000000000000011754942;
2322+
/// let nan = f32::NAN;
2323+
///
2324+
/// assert_eq!(num.classify(), FpCategory::Normal);
2325+
/// assert_eq!(inf.classify(), FpCategory::Infinite);
2326+
/// assert_eq!(zero.classify(), FpCategory::Zero);
2327+
/// assert_eq!(nan.classify(), FpCategory::Nan);
2328+
/// assert_eq!(sub.classify(), FpCategory::Subnormal);
2329+
/// ```
23112330
#[derive(Copy, Clone, PartialEq, Debug)]
23122331
#[stable(feature = "rust1", since = "1.0.0")]
23132332
pub enum FpCategory {
2314-
/// "Not a Number", often obtained by dividing by zero
2333+
/// "Not a Number", often obtained by dividing by zero.
23152334
#[stable(feature = "rust1", since = "1.0.0")]
23162335
Nan,
23172336

2318-
/// Positive or negative infinity
2337+
/// Positive or negative infinity.
23192338
#[stable(feature = "rust1", since = "1.0.0")]
23202339
Infinite ,
23212340

2322-
/// Positive or negative zero
2341+
/// Positive or negative zero.
23232342
#[stable(feature = "rust1", since = "1.0.0")]
23242343
Zero,
23252344

2326-
/// De-normalized floating point representation (less precise than `Normal`)
2345+
/// De-normalized floating point representation (less precise than `Normal`).
23272346
#[stable(feature = "rust1", since = "1.0.0")]
23282347
Subnormal,
23292348

2330-
/// A regular floating point number
2349+
/// A regular floating point number.
23312350
#[stable(feature = "rust1", since = "1.0.0")]
23322351
Normal,
23332352
}

‎src/libpanic_unwind/gcc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#![allow(private_no_mangle_fns)]
5858

5959
use core::any::Any;
60+
use core::ptr;
6061
use alloc::boxed::Box;
6162

6263
use unwind as uw;
@@ -88,7 +89,7 @@ pub unsafe fn panic(data: Box<Any + Send>) -> u32 {
8889
}
8990

9091
pub fn payload() -> *mut u8 {
91-
0 as *mut u8
92+
ptr::null_mut()
9293
}
9394

9495
pub unsafe fn cleanup(ptr: *mut u8) -> Box<Any + Send> {

‎src/libpanic_unwind/seh64_gnu.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use alloc::boxed::Box;
1818

1919
use core::any::Any;
2020
use core::intrinsics;
21+
use core::ptr;
2122
use dwarf::eh;
2223
use windows as c;
2324

@@ -50,7 +51,7 @@ pub unsafe fn panic(data: Box<Any + Send>) -> u32 {
5051
}
5152

5253
pub fn payload() -> *mut u8 {
53-
0 as *mut u8
54+
ptr::null_mut()
5455
}
5556

5657
pub unsafe fn cleanup(ptr: *mut u8) -> Box<Any + Send> {

‎src/librustc_trans/base.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ use libc::c_uint;
9696
use std::ffi::{CStr, CString};
9797
use std::cell::{Cell, RefCell};
9898
use std::collections::{HashMap, HashSet};
99+
use std::ptr;
99100
use std::rc::Rc;
100101
use std::str;
101102
use std::{i8, i16, i32, i64};
@@ -2201,7 +2202,7 @@ pub fn maybe_create_entry_wrapper(ccx: &CrateContext) {
22012202
start_fn,
22022203
args.as_ptr(),
22032204
args.len() as c_uint,
2204-
0 as *mut _,
2205+
ptr::null_mut(),
22052206
noname());
22062207

22072208
llvm::LLVMBuildRet(bld, result);

‎src/librustc_trans/builder.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
177177

178178
check_call("invoke", llfn, args);
179179

180-
let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(0 as *mut _);
180+
let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(ptr::null_mut());
181181

182182
unsafe {
183183
llvm::LLVMRustBuildInvoke(self.llbuilder,
@@ -859,7 +859,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
859859

860860
check_call("call", llfn, args);
861861

862-
let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(0 as *mut _);
862+
let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(ptr::null_mut());
863863

864864
unsafe {
865865
llvm::LLVMRustBuildCall(self.llbuilder, llfn, args.as_ptr(),
@@ -961,7 +961,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
961961
self.count_insn("trap");
962962
llvm::LLVMRustBuildCall(self.llbuilder, t,
963963
args.as_ptr(), args.len() as c_uint,
964-
0 as *mut _,
964+
ptr::null_mut(),
965965
noname());
966966
}
967967
}
@@ -1000,7 +1000,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
10001000
parent: Option<ValueRef>,
10011001
args: &[ValueRef]) -> ValueRef {
10021002
self.count_insn("cleanuppad");
1003-
let parent = parent.unwrap_or(0 as *mut _);
1003+
let parent = parent.unwrap_or(ptr::null_mut());
10041004
let name = CString::new("cleanuppad").unwrap();
10051005
let ret = unsafe {
10061006
llvm::LLVMRustBuildCleanupPad(self.llbuilder,
@@ -1016,7 +1016,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
10161016
pub fn cleanup_ret(&self, cleanup: ValueRef,
10171017
unwind: Option<BasicBlockRef>) -> ValueRef {
10181018
self.count_insn("cleanupret");
1019-
let unwind = unwind.unwrap_or(0 as *mut _);
1019+
let unwind = unwind.unwrap_or(ptr::null_mut());
10201020
let ret = unsafe {
10211021
llvm::LLVMRustBuildCleanupRet(self.llbuilder, cleanup, unwind)
10221022
};
@@ -1052,8 +1052,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
10521052
unwind: Option<BasicBlockRef>,
10531053
num_handlers: usize) -> ValueRef {
10541054
self.count_insn("catchswitch");
1055-
let parent = parent.unwrap_or(0 as *mut _);
1056-
let unwind = unwind.unwrap_or(0 as *mut _);
1055+
let parent = parent.unwrap_or(ptr::null_mut());
1056+
let unwind = unwind.unwrap_or(ptr::null_mut());
10571057
let name = CString::new("catchswitch").unwrap();
10581058
let ret = unsafe {
10591059
llvm::LLVMRustBuildCatchSwitch(self.llbuilder, parent, unwind,

‎src/libstd/macros.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ macro_rules! print {
9898
($($arg:tt)*) => ($crate::io::_print(format_args!($($arg)*)));
9999
}
100100

101-
/// Macro for printing to the standard output, with a newline.
101+
/// Macro for printing to the standard output, with a newline. On all
102+
/// platforms, the newline is the LINE FEED character (`\n`/`U+000A`) alone
103+
/// (no additional CARRIAGE RETURN (`\r`/`U+000D`).
102104
///
103105
/// Use the `format!` syntax to write data to the standard output.
104106
/// See `std::fmt` for more information.

‎src/libstd/process.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,23 @@ pub struct ExitStatus(imp::ExitStatus);
605605
impl ExitStatus {
606606
/// Was termination successful? Signal termination not considered a success,
607607
/// and success is defined as a zero exit status.
608+
///
609+
/// # Examples
610+
///
611+
/// ```rust,no_run
612+
/// use std::process::Command;
613+
///
614+
/// let status = Command::new("mkdir")
615+
/// .arg("projects")
616+
/// .status()
617+
/// .expect("failed to execute mkdir");
618+
///
619+
/// if status.success() {
620+
/// println!("'projects/' directory created");
621+
/// } else {
622+
/// println!("failed to create 'projects/' directory");
623+
/// }
624+
/// ```
608625
#[stable(feature = "process", since = "1.0.0")]
609626
pub fn success(&self) -> bool {
610627
self.0.success()

‎src/libstd/sync/once.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
// it!
6666

6767
use marker;
68+
use ptr;
6869
use sync::atomic::{AtomicUsize, AtomicBool, Ordering};
6970
use thread::{self, Thread};
7071

@@ -297,7 +298,7 @@ impl Once {
297298
let mut node = Waiter {
298299
thread: Some(thread::current()),
299300
signaled: AtomicBool::new(false),
300-
next: 0 as *mut Waiter,
301+
next: ptr::null_mut(),
301302
};
302303
let me = &mut node as *mut Waiter as usize;
303304
assert!(me & STATE_MASK == 0);

‎src/libstd/sys/unix/os.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,11 @@ pub fn current_exe() -> io::Result<PathBuf> {
236236
libc::KERN_PROC_ARGV];
237237
let mib = mib.as_mut_ptr();
238238
let mut argv_len = 0;
239-
cvt(libc::sysctl(mib, 4, 0 as *mut _, &mut argv_len,
240-
0 as *mut _, 0))?;
239+
cvt(libc::sysctl(mib, 4, ptr::null_mut(), &mut argv_len,
240+
ptr::null_mut(), 0))?;
241241
let mut argv = Vec::<*const libc::c_char>::with_capacity(argv_len as usize);
242242
cvt(libc::sysctl(mib, 4, argv.as_mut_ptr() as *mut _,
243-
&mut argv_len, 0 as *mut _, 0))?;
243+
&mut argv_len, ptr::null_mut(), 0))?;
244244
argv.set_len(argv_len as usize);
245245
if argv[0].is_null() {
246246
return Err(io::Error::new(io::ErrorKind::Other,

‎src/libstd/sys/unix/pipe.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use cmp;
1414
use io;
1515
use libc::{self, c_int};
1616
use mem;
17+
use ptr;
1718
use sys::cvt_r;
1819
use sys::fd::FileDesc;
1920

@@ -92,8 +93,8 @@ pub fn read2(p1: AnonPipe,
9293
let mut read: libc::fd_set = mem::zeroed();
9394
libc::FD_SET(p1.raw(), &mut read);
9495
libc::FD_SET(p2.raw(), &mut read);
95-
libc::select(max + 1, &mut read, 0 as *mut _, 0 as *mut _,
96-
0 as *mut _)
96+
libc::select(max + 1, &mut read, ptr::null_mut(), ptr::null_mut(),
97+
ptr::null_mut())
9798
})?;
9899

99100
// Read as much as we can from each pipe, ignoring EWOULDBLOCK or

‎src/libstd/sys/unix/process.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl Command {
9696
let mut saw_nul = false;
9797
let program = os2c(program, &mut saw_nul);
9898
Command {
99-
argv: vec![program.as_ptr(), 0 as *const _],
99+
argv: vec![program.as_ptr(), ptr::null()],
100100
program: program,
101101
args: Vec::new(),
102102
env: None,
@@ -117,7 +117,7 @@ impl Command {
117117
// pointer.
118118
let arg = os2c(arg, &mut self.saw_nul);
119119
self.argv[self.args.len() + 1] = arg.as_ptr();
120-
self.argv.push(0 as *const _);
120+
self.argv.push(ptr::null());
121121

122122
// Also make sure we keep track of the owned value to schedule a
123123
// destructor for this memory.
@@ -134,7 +134,7 @@ impl Command {
134134
envp.push(s.as_ptr());
135135
map.insert(k, (envp.len() - 1, s));
136136
}
137-
envp.push(0 as *const _);
137+
envp.push(ptr::null());
138138
self.env = Some(map);
139139
self.envp = Some(envp);
140140
}
@@ -158,7 +158,7 @@ impl Command {
158158
Entry::Vacant(e) => {
159159
let len = envp.len();
160160
envp[len - 1] = new_key.as_ptr();
161-
envp.push(0 as *const _);
161+
envp.push(ptr::null());
162162
e.insert((len - 1, new_key));
163163
}
164164
}
@@ -183,7 +183,7 @@ impl Command {
183183

184184
pub fn env_clear(&mut self) {
185185
self.env = Some(HashMap::new());
186-
self.envp = Some(vec![0 as *const _]);
186+
self.envp = Some(vec![ptr::null()]);
187187
}
188188

189189
pub fn cwd(&mut self, dir: &OsStr) {

‎src/libstd/sys/unix/time.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
// except according to those terms.
1010

1111
use cmp::Ordering;
12-
use time::Duration;
1312
use libc;
13+
use time::Duration;
1414

1515
pub use self::inner::{Instant, SystemTime, UNIX_EPOCH};
1616

@@ -164,12 +164,14 @@ mod inner {
164164

165165
impl SystemTime {
166166
pub fn now() -> SystemTime {
167+
use ptr;
168+
167169
let mut s = libc::timeval {
168170
tv_sec: 0,
169171
tv_usec: 0,
170172
};
171173
cvt(unsafe {
172-
libc::gettimeofday(&mut s, 0 as *mut _)
174+
libc::gettimeofday(&mut s, ptr::null_mut())
173175
}).unwrap();
174176
return SystemTime::from(s)
175177
}

‎src/libstd/sys/windows/handle.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ impl Handle {
4646

4747
pub fn new_event(manual: bool, init: bool) -> io::Result<Handle> {
4848
unsafe {
49-
let event = c::CreateEventW(0 as *mut _,
49+
let event = c::CreateEventW(ptr::null_mut(),
5050
manual as c::BOOL,
5151
init as c::BOOL,
52-
0 as *const _);
52+
ptr::null());
5353
if event.is_null() {
5454
Err(io::Error::last_os_error())
5555
} else {

‎src/libstd/sys/windows/pipe.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ use prelude::v1::*;
1212
use os::windows::prelude::*;
1313

1414
use ffi::OsStr;
15-
use path::Path;
1615
use io;
1716
use mem;
17+
use path::Path;
18+
use ptr;
1819
use rand::{self, Rng};
1920
use slice;
2021
use sys::c;
@@ -66,7 +67,7 @@ pub fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
6667
4096,
6768
4096,
6869
0,
69-
0 as *mut _);
70+
ptr::null_mut());
7071

7172
// We pass the FILE_FLAG_FIRST_PIPE_INSTANCE flag above, and we're
7273
// also just doing a best effort at selecting a unique name. If

‎src/libtest/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,8 @@ fn get_concurrency() -> usize {
959959
target_os = "bitrig",
960960
target_os = "netbsd"))]
961961
fn num_cpus() -> usize {
962+
use std::ptr;
963+
962964
let mut cpus: libc::c_uint = 0;
963965
let mut cpus_size = std::mem::size_of_val(&cpus);
964966

@@ -972,7 +974,7 @@ fn get_concurrency() -> usize {
972974
2,
973975
&mut cpus as *mut _ as *mut _,
974976
&mut cpus_size as *mut _ as *mut _,
975-
0 as *mut _,
977+
ptr::null_mut(),
976978
0);
977979
}
978980
if cpus < 1 {
@@ -984,6 +986,8 @@ fn get_concurrency() -> usize {
984986

985987
#[cfg(target_os = "openbsd")]
986988
fn num_cpus() -> usize {
989+
use std::ptr;
990+
987991
let mut cpus: libc::c_uint = 0;
988992
let mut cpus_size = std::mem::size_of_val(&cpus);
989993
let mut mib = [libc::CTL_HW, libc::HW_NCPU, 0, 0];
@@ -993,7 +997,7 @@ fn get_concurrency() -> usize {
993997
2,
994998
&mut cpus as *mut _ as *mut _,
995999
&mut cpus_size as *mut _ as *mut _,
996-
0 as *mut _,
1000+
ptr::null_mut(),
9971001
0);
9981002
}
9991003
if cpus < 1 {

0 commit comments

Comments
 (0)
Please sign in to comment.