From 1ec7a697328fb10e7135b87557ff0a5ea702dd8d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 16 Apr 2015 09:44:05 -0700 Subject: [PATCH 01/10] std: Add an unstable method Child::id This commits adds a method to the `std::process` module to get the process identifier of the child as a `u32`. On Windows the underlying identifier is already a `u32`, and on Unix the type is typically defined as `c_int` (`i32` for almost all our supported platforms), but the actually pid is normally a small positive number. Eventually we may add functions to load information about a process based on its identifier or the ability to terminate a process based on its identifier, but for now this function should enable this sort of functionality to exist outside the standard library. --- src/libstd/process.rs | 6 ++++++ src/libstd/sys/unix/process.rs | 4 ++++ src/libstd/sys/windows/c.rs | 1 + src/libstd/sys/windows/process.rs | 6 ++++++ 4 files changed, 17 insertions(+) diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 61398e16ba036..ae9316ddd622b 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -456,6 +456,12 @@ impl Child { unsafe { self.handle.kill() } } + /// Returns the OS-assigned process identifier associated with this child. + #[unstable(feature = "process_id", reason = "api recently added")] + pub fn id(&self) -> u32 { + self.handle.id() + } + /// Waits for the child to exit completely, returning the status that it /// exited with. This function will continue to have the same return value /// after it has been called at least once. diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs index 290310f4ad901..f4bc597304097 100644 --- a/src/libstd/sys/unix/process.rs +++ b/src/libstd/sys/unix/process.rs @@ -315,6 +315,10 @@ impl Process { fail(&mut output) } + pub fn id(&self) -> u32 { + self.pid as u32 + } + pub fn wait(&self) -> io::Result { let mut status = 0 as c_int; try!(cvt_r(|| unsafe { c::waitpid(self.pid, &mut status, 0) })); diff --git a/src/libstd/sys/windows/c.rs b/src/libstd/sys/windows/c.rs index b07d063de45c9..e9b850856e1f8 100644 --- a/src/libstd/sys/windows/c.rs +++ b/src/libstd/sys/windows/c.rs @@ -482,6 +482,7 @@ extern "system" { dwMilliseconds: libc::DWORD) -> libc::DWORD; pub fn SwitchToThread() -> libc::BOOL; pub fn Sleep(dwMilliseconds: libc::DWORD); + pub fn GetProcessId(handle: libc::HANDLE) -> libc::DWORD; } #[link(name = "userenv")] diff --git a/src/libstd/sys/windows/process.rs b/src/libstd/sys/windows/process.rs index 032a349b00eff..bc4762c197e14 100644 --- a/src/libstd/sys/windows/process.rs +++ b/src/libstd/sys/windows/process.rs @@ -193,6 +193,12 @@ impl Process { Ok(()) } + pub fn id(&self) -> u32 { + unsafe { + c::GetProcessId(self.handle.raw()) as u32 + } + } + pub fn wait(&self) -> io::Result { use libc::{STILL_ACTIVE, INFINITE, WAIT_OBJECT_0}; use libc::{GetExitCodeProcess, WaitForSingleObject}; From 1254c34032673d5f9d7775d894bc58e7ad68ba01 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Mon, 18 May 2015 16:58:29 -0400 Subject: [PATCH 02/10] Add example for from_str_radix Fixes #25517 --- src/libcore/num/mod.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 011830ddb7882..75040b4c425c6 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -132,15 +132,11 @@ macro_rules! int_impl { /// /// Leading and trailing whitespace represent an error. /// - /// # Arguments - /// - /// * src - A string slice - /// * radix - The base to use. Must lie in the range [2 .. 36] - /// - /// # Return value + /// # Examples /// - /// `Err(ParseIntError)` if the string did not represent a valid number. - /// Otherwise, `Ok(n)` where `n` is the integer represented by `src`. + /// ``` + /// assert_eq!(u32::from_str_radix("A", 16), Some(10)); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[allow(deprecated)] pub fn from_str_radix(src: &str, radix: u32) -> Result<$T, ParseIntError> { From 733e7eea5c459c67173e369c1deac3bcde8f03ef Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 19 May 2015 19:21:52 +0700 Subject: [PATCH 03/10] fmt.rs: add note about lack of padding support for some types --- src/libcollections/fmt.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libcollections/fmt.rs b/src/libcollections/fmt.rs index 80fa6d397c829..cb023bcb7a586 100644 --- a/src/libcollections/fmt.rs +++ b/src/libcollections/fmt.rs @@ -353,6 +353,10 @@ //! * `^` - the argument is center-aligned in `width` columns //! * `>` - the argument is right-aligned in `width` columns //! +//! Note that alignment may not be implemented by some types. A good way +//! to ensure padding is applied is to format your input, then use this +//! resulting string to pad your output. +//! //! ## Sign/#/0 //! //! These can all be interpreted as flags for a particular formatter. From aa570bce3e35f1fba5a5fe488e40c31ceff1207c Mon Sep 17 00:00:00 2001 From: Mohammed Attia Date: Tue, 19 May 2015 14:38:54 +0200 Subject: [PATCH 04/10] Fix lifetimes trpl typo --- src/doc/trpl/lifetimes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/lifetimes.md b/src/doc/trpl/lifetimes.md index 342de413f0b9a..0039f90b82c35 100644 --- a/src/doc/trpl/lifetimes.md +++ b/src/doc/trpl/lifetimes.md @@ -219,7 +219,7 @@ to it. ## Lifetime Elision Rust supports powerful local type inference in function bodies, but it’s -forbidden in item signatures to allow reasoning about the types just based in +forbidden in item signatures to allow reasoning about the types based on the item signature alone. However, for ergonomic reasons a very restricted secondary inference algorithm called “lifetime elision” applies in function signatures. It infers only based on the signature components themselves and not From afbe15d103dd12e177b7fa875b8c21d43e2f15a3 Mon Sep 17 00:00:00 2001 From: peferron Date: Mon, 18 May 2015 13:39:19 -0700 Subject: [PATCH 05/10] Fix description of assert! --- src/doc/trpl/macros.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/doc/trpl/macros.md b/src/doc/trpl/macros.md index d504fab206ddf..5660f7c198f98 100644 --- a/src/doc/trpl/macros.md +++ b/src/doc/trpl/macros.md @@ -683,9 +683,9 @@ let v = vec![0; 100]; ## assert! and assert_eq! -These two macros are used in tests. `assert!` takes a boolean, and `assert_eq!` -takes two values and compares them. Truth passes, success `panic!`s. Like -this: +These two macros are used in tests. `assert!` takes a boolean. `assert_eq!` +takes two values and checks them for equality. `true` passes, `false` `panic!`s. +Like this: ```rust,no_run // A-ok! From c9c474cb862a02eb15c15882fe331c6f9bdb7524 Mon Sep 17 00:00:00 2001 From: parir Date: Tue, 19 May 2015 19:19:42 +0200 Subject: [PATCH 06/10] doc: add missing fences --- src/libcollections/str.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 198627ad2fc3a..a3ffdedb8c1e3 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -1841,8 +1841,10 @@ impl str { /// /// # Examples /// + /// ``` /// let s = "HELLO"; /// assert_eq!(s.to_lowercase(), "hello"); + /// ``` #[unstable(feature = "collections")] pub fn to_lowercase(&self) -> String { let mut s = String::with_capacity(self.len()); @@ -1854,8 +1856,10 @@ impl str { /// /// # Examples /// + /// ``` /// let s = "hello"; /// assert_eq!(s.to_uppercase(), "HELLO"); + /// ``` #[unstable(feature = "collections")] pub fn to_uppercase(&self) -> String { let mut s = String::with_capacity(self.len()); From 3b95cd71fe9e84a37f98c655ac8bf39e44bdb0b3 Mon Sep 17 00:00:00 2001 From: parir Date: Tue, 19 May 2015 19:36:10 +0200 Subject: [PATCH 07/10] doc: fix a broken link --- src/librustc_unicode/char.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_unicode/char.rs b/src/librustc_unicode/char.rs index 3118619220958..9dfd172707d7b 100644 --- a/src/librustc_unicode/char.rs +++ b/src/librustc_unicode/char.rs @@ -429,7 +429,7 @@ impl char { /// /// [1]: ftp://ftp.unicode.org/Public/UNIDATA/UnicodeData.txt /// - /// [`SpecialCasing`.txt`]: ftp://ftp.unicode.org/Public/UNIDATA/SpecialCasing.txt + /// [`SpecialCasing.txt`]: ftp://ftp.unicode.org/Public/UNIDATA/SpecialCasing.txt /// /// [2]: http://www.unicode.org/versions/Unicode4.0.0/ch03.pdf#G33992 #[stable(feature = "rust1", since = "1.0.0")] From 01c93a59e8bc7588d43e75125cdca769b0b3571c Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 19 May 2015 11:34:34 -0700 Subject: [PATCH 08/10] mk: Report the prerelease version on beta again. Fixes #25618 --- mk/main.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mk/main.mk b/mk/main.mk index b3c0284134040..291920cf7a8cf 100644 --- a/mk/main.mk +++ b/mk/main.mk @@ -32,7 +32,7 @@ CFG_PACKAGE_VERS=$(CFG_RELEASE_NUM) CFG_DISABLE_UNSTABLE_FEATURES=1 endif ifeq ($(CFG_RELEASE_CHANNEL),beta) -CFG_RELEASE=$(CFG_RELEASE_NUM)-beta +CFG_RELEASE=$(CFG_RELEASE_NUM)-beta$(CFG_PRERELEASE_VERSION) # When building beta distributables just reuse the same "beta" name # so when we upload we'll always override the previous beta. This # doesn't actually impact the version reported by rustc - it's just From 55da4c69752119b80f17351784de45f66540066f Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 19 May 2015 21:26:21 -0400 Subject: [PATCH 09/10] Small fix for https://github.com/rust-lang/rust/pull/25611 --- src/libcollections/str.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index a3ffdedb8c1e3..b390055664ba0 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -1842,6 +1842,8 @@ impl str { /// # Examples /// /// ``` + /// #![feature(collections)] + /// /// let s = "HELLO"; /// assert_eq!(s.to_lowercase(), "hello"); /// ``` @@ -1857,6 +1859,8 @@ impl str { /// # Examples /// /// ``` + /// #![feature(collections)] + /// /// let s = "hello"; /// assert_eq!(s.to_uppercase(), "HELLO"); /// ``` From 395d01cf64579312b9b6924d8056264abaaf33f7 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 19 May 2015 23:22:28 -0400 Subject: [PATCH 10/10] Fix for https://github.com/rust-lang/rust/pull/25583 --- src/libcore/num/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 91faba7376bca..e560fae31a17e 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -135,7 +135,7 @@ macro_rules! int_impl { /// # Examples /// /// ``` - /// assert_eq!(u32::from_str_radix("A", 16), Some(10)); + /// assert_eq!(u32::from_str_radix("A", 16), Ok(10)); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[allow(deprecated)]