From 6ff6b935608f7c5b6b53517f3fc5bafec911a79d Mon Sep 17 00:00:00 2001 From: Thayne McCombs Date: Thu, 5 Oct 2017 23:49:36 -0600 Subject: [PATCH 1/9] Add current_pid function Fixes #44971 --- src/libstd/process.rs | 18 ++++++++++++++++++ src/libstd/sys/redox/os.rs | 4 ++++ src/libstd/sys/unix/os.rs | 4 ++++ src/libstd/sys/windows/os.rs | 4 ++++ 4 files changed, 30 insertions(+) diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 1869ad3ed707a..38035e1fa6bee 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -1167,6 +1167,24 @@ pub fn abort() -> ! { unsafe { ::sys::abort_internal() }; } +/// Returns the OS-assigned process identifier associated with this process. +/// +/// # Examples +/// +/// Basic usage: +/// +/// ```no_run +/// use std::process:current_pid; +/// +/// println!("My pid is {}", current_pid()); +/// ``` +/// +/// +#[unstable(feature = "getpid", issue = "44971", reason = "recently added")] +pub fn current_pid() -> u32 { + ::sys::os::getpid() +} + #[cfg(all(test, not(target_os = "emscripten")))] mod tests { use io::prelude::*; diff --git a/src/libstd/sys/redox/os.rs b/src/libstd/sys/redox/os.rs index efddd5f029484..c27e2ee172c6b 100644 --- a/src/libstd/sys/redox/os.rs +++ b/src/libstd/sys/redox/os.rs @@ -209,3 +209,7 @@ pub fn exit(code: i32) -> ! { let _ = syscall::exit(code as usize); unreachable!(); } + +pub fn getpid() -> u32 { + syscall::getpid().unwrap() as u32 +} diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 5ef98d247105e..132f59b999d4f 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -513,3 +513,7 @@ pub fn home_dir() -> Option { pub fn exit(code: i32) -> ! { unsafe { libc::exit(code as c_int) } } + +pub fn getpid() -> u32 { + unsafe { libc::getpid() as u32 } +} diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index a51b458451e86..b94482435597e 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -318,6 +318,10 @@ pub fn exit(code: i32) -> ! { unsafe { c::ExitProcess(code as c::UINT) } } +pub fn getpid() -> u32 { + unsafe { c::GetCurrentProcessId() as u32 } +} + #[cfg(test)] mod tests { use io::Error; From ba7575886e6a294b8185f51a1701574f72abe5a8 Mon Sep 17 00:00:00 2001 From: Thayne McCombs Date: Sat, 7 Oct 2017 00:55:58 -0600 Subject: [PATCH 2/9] Add missing colon. --- src/libstd/process.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 38035e1fa6bee..711d8df1b605d 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -1174,7 +1174,7 @@ pub fn abort() -> ! { /// Basic usage: /// /// ```no_run -/// use std::process:current_pid; +/// use std::process::current_pid; /// /// println!("My pid is {}", current_pid()); /// ``` From 29b319b6b20bb8e18b7e3c14528f9933de2f5e92 Mon Sep 17 00:00:00 2001 From: Thayne McCombs Date: Sat, 7 Oct 2017 20:59:58 -0600 Subject: [PATCH 3/9] Change current_pid to just `id`. --- src/libstd/process.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 711d8df1b605d..dee01df651d11 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -1174,14 +1174,15 @@ pub fn abort() -> ! { /// Basic usage: /// /// ```no_run -/// use std::process::current_pid; +/// #![feature(getpid)] +/// use std::process; /// -/// println!("My pid is {}", current_pid()); +/// println!("My pid is {}", process::id()); /// ``` /// /// #[unstable(feature = "getpid", issue = "44971", reason = "recently added")] -pub fn current_pid() -> u32 { +pub fn id() -> u32 { ::sys::os::getpid() } From 3b815730a711186a3bbe105800fb2dfa5f4d8caf Mon Sep 17 00:00:00 2001 From: kennytm Date: Wed, 25 Oct 2017 00:32:28 +0800 Subject: [PATCH 4/9] rustbuild: Fix `no output generated` error for next bootstrap cargo. Due to rust-lang/cargo#4570, a `*.dll.lib` file is uplifted when building dynamic libraries on Windows. The current bootstrap code does not understand files with multiple extensions, and will instead assume `xxxx.dll` is the file name. This caused a `no output generated` error because it tries to search for `xxxx.dll-hash.lib` inside the `deps/` folder, while it should check for `xxxx-hash.dll.lib` instead. This PR is blocking #45285 (Bump to 1.23 and update bootstrap). --- src/bootstrap/compile.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index a8162f0a92fb3..4540f62087228 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -860,10 +860,18 @@ fn run_cargo(build: &Build, cargo: &mut Command, stamp: &Path) { // have a hash in the name, but there's a version of this file in // the `deps` folder which *does* have a hash in the name. That's // the one we'll want to we'll probe for it later. - toplevel.push((filename.file_stem().unwrap() - .to_str().unwrap().to_string(), - filename.extension().unwrap().to_owned() - .to_str().unwrap().to_string())); + // + // We do not use `Path::file_stem` or `Path::extension` here, + // because some generated files may have multiple extensions e.g. + // `std-.dll.lib` on Windows. The aforementioned methods only + // split the file name by the last extension (`.lib`) while we need + // to split by all extensions (`.dll.lib`). + let filename = filename.file_name().unwrap().to_str().unwrap(); + let mut parts = filename.splitn(2, '.'); + let file_stem = parts.next().unwrap().to_owned(); + let extension = parts.next().unwrap().to_owned(); + + toplevel.push((file_stem, extension)); } } From 9ce41f2544706bc3fc89f134668b607b0598e453 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 11 Oct 2017 20:08:17 +0200 Subject: [PATCH 5/9] Fix the sidebar height --- src/librustdoc/html/static/rustdoc.css | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 27574e67bc87b..c7e3860748091 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -171,10 +171,11 @@ nav.sub { .sidebar { width: 200px; - position: absolute; + position: fixed; left: 0; top: 0; - min-height: 100%; + height: 100vh; + overflow: auto; } .sidebar .current { From 7bab5dabddc858d7213e2d4d453caa90a86d8586 Mon Sep 17 00:00:00 2001 From: bgermann Date: Wed, 25 Oct 2017 00:52:56 +0200 Subject: [PATCH 6/9] Disable jemalloc for sparcv9-sun-solaris Similar to #36994, rust programs segfault on SPARC64 Solaris machines. --- src/librustc_back/target/sparcv9_sun_solaris.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_back/target/sparcv9_sun_solaris.rs b/src/librustc_back/target/sparcv9_sun_solaris.rs index bfe1afebdb3a3..1d9027275db82 100644 --- a/src/librustc_back/target/sparcv9_sun_solaris.rs +++ b/src/librustc_back/target/sparcv9_sun_solaris.rs @@ -17,6 +17,7 @@ pub fn target() -> TargetResult { // llvm calls this "v9" base.cpu = "v9".to_string(); base.max_atomic_width = Some(64); + base.exe_allocation_crate = None; Ok(Target { llvm_target: "sparcv9-sun-solaris".to_string(), From 0e46cf4db4fdb8b2fd8cc0dde2425a16d478d8ed Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Wed, 25 Oct 2017 11:29:14 -0400 Subject: [PATCH 7/9] Reword to avoid using either re-assignment or reassignment in errors --- src/librustc_borrowck/borrowck/mod.rs | 2 +- src/librustc_mir/borrow_check.rs | 2 +- src/librustc_mir/util/borrowck_errors.rs | 2 +- src/test/compile-fail/asm-out-assign-imm.rs | 4 ++-- src/test/compile-fail/assign-imm-local-twice.rs | 4 ++-- .../borrowck/borrowck-match-binding-is-assignment.rs | 10 +++++----- .../compile-fail/liveness-assign-imm-local-in-loop.rs | 4 ++-- .../compile-fail/liveness-assign-imm-local-in-op-eq.rs | 4 ++-- .../liveness-assign-imm-local-with-init.rs | 4 ++-- .../compile-fail/mut-pattern-internal-mutability.rs | 6 +++--- 10 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index d29250ac57cfb..add128cc2cf6a 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -744,7 +744,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { let mut err = self.cannot_reassign_immutable(span, &self.loan_path_to_string(lp), Origin::Ast); - err.span_label(span, "re-assignment of immutable variable"); + err.span_label(span, "cannot assign twice to immutable variable"); if span != assign.span { err.span_label(assign.span, format!("first assignment to `{}`", self.loan_path_to_string(lp))); diff --git a/src/librustc_mir/borrow_check.rs b/src/librustc_mir/borrow_check.rs index ff923ce259fb4..ee2ef00be57b6 100644 --- a/src/librustc_mir/borrow_check.rs +++ b/src/librustc_mir/borrow_check.rs @@ -1161,7 +1161,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx> self.tcx.cannot_reassign_immutable(span, &self.describe_lvalue(lvalue), Origin::Mir) - .span_label(span, "re-assignment of immutable variable") + .span_label(span, "cannot assign twice to immutable variable") .span_label(assigned_span, format!("first assignment to `{}`", self.describe_lvalue(lvalue))) .emit(); diff --git a/src/librustc_mir/util/borrowck_errors.rs b/src/librustc_mir/util/borrowck_errors.rs index 216f6e4457096..5451da2148e7d 100644 --- a/src/librustc_mir/util/borrowck_errors.rs +++ b/src/librustc_mir/util/borrowck_errors.rs @@ -232,7 +232,7 @@ pub trait BorrowckErrors { -> DiagnosticBuilder { struct_span_err!(self, span, E0384, - "re-assignment of immutable variable `{}`{OGN}", + "cannot assign twice to immutable variable `{}`{OGN}", desc, OGN=o) } diff --git a/src/test/compile-fail/asm-out-assign-imm.rs b/src/test/compile-fail/asm-out-assign-imm.rs index 546d402252e27..f2629fa52ffdd 100644 --- a/src/test/compile-fail/asm-out-assign-imm.rs +++ b/src/test/compile-fail/asm-out-assign-imm.rs @@ -27,8 +27,8 @@ pub fn main() { foo(x); unsafe { asm!("mov $1, $0" : "=r"(x) : "r"(5)); - //~^ ERROR re-assignment of immutable variable `x` - //~| NOTE re-assignment of immutable + //~^ ERROR cannot assign twice to immutable variable `x` + //~| NOTE cannot assign twice to immutable } foo(x); } diff --git a/src/test/compile-fail/assign-imm-local-twice.rs b/src/test/compile-fail/assign-imm-local-twice.rs index 9a5d6289b589e..5b3b7d44bd2b9 100644 --- a/src/test/compile-fail/assign-imm-local-twice.rs +++ b/src/test/compile-fail/assign-imm-local-twice.rs @@ -12,8 +12,8 @@ fn test() { let v: isize; v = 1; //~ NOTE first assignment println!("v={}", v); - v = 2; //~ ERROR re-assignment of immutable variable - //~| NOTE re-assignment of immutable + v = 2; //~ ERROR cannot assign twice to immutable variable + //~| NOTE cannot assign twice to immutable println!("v={}", v); } diff --git a/src/test/compile-fail/borrowck/borrowck-match-binding-is-assignment.rs b/src/test/compile-fail/borrowck/borrowck-match-binding-is-assignment.rs index 3639db5cfc4cd..ea30911b3cc79 100644 --- a/src/test/compile-fail/borrowck/borrowck-match-binding-is-assignment.rs +++ b/src/test/compile-fail/borrowck/borrowck-match-binding-is-assignment.rs @@ -26,7 +26,7 @@ struct S { pub fn main() { match 1 { x => { - x += 1; //[ast]~ ERROR re-assignment of immutable variable `x` + x += 1; //[ast]~ ERROR cannot assign twice to immutable variable `x` //[mir]~^ ERROR (Mir) [E0384] //[mir]~| ERROR (Ast) [E0384] } @@ -34,7 +34,7 @@ pub fn main() { match E::Foo(1) { E::Foo(x) => { - x += 1; //[ast]~ ERROR re-assignment of immutable variable `x` + x += 1; //[ast]~ ERROR cannot assign twice to immutable variable `x` //[mir]~^ ERROR (Mir) [E0384] //[mir]~| ERROR (Ast) [E0384] } @@ -42,7 +42,7 @@ pub fn main() { match (S { bar: 1 }) { S { bar: x } => { - x += 1; //[ast]~ ERROR re-assignment of immutable variable `x` + x += 1; //[ast]~ ERROR cannot assign twice to immutable variable `x` //[mir]~^ ERROR (Mir) [E0384] //[mir]~| ERROR (Ast) [E0384] } @@ -50,7 +50,7 @@ pub fn main() { match (1,) { (x,) => { - x += 1; //[ast]~ ERROR re-assignment of immutable variable `x` + x += 1; //[ast]~ ERROR cannot assign twice to immutable variable `x` //[mir]~^ ERROR (Mir) [E0384] //[mir]~| ERROR (Ast) [E0384] } @@ -58,7 +58,7 @@ pub fn main() { match [1,2,3] { [x,_,_] => { - x += 1; //[ast]~ ERROR re-assignment of immutable variable `x` + x += 1; //[ast]~ ERROR cannot assign twice to immutable variable `x` //[mir]~^ ERROR (Mir) [E0384] //[mir]~| ERROR (Ast) [E0384] } diff --git a/src/test/compile-fail/liveness-assign-imm-local-in-loop.rs b/src/test/compile-fail/liveness-assign-imm-local-in-loop.rs index 9d246f8ea5e0e..fa8f264eb5a5f 100644 --- a/src/test/compile-fail/liveness-assign-imm-local-in-loop.rs +++ b/src/test/compile-fail/liveness-assign-imm-local-in-loop.rs @@ -11,8 +11,8 @@ fn test() { let v: isize; loop { - v = 1; //~ ERROR re-assignment of immutable variable - //~^ NOTE re-assignment of immutable variable + v = 1; //~ ERROR cannot assign twice to immutable variable + //~^ NOTE cannot assign twice to immutable variable v.clone(); // just to prevent liveness warnings } } diff --git a/src/test/compile-fail/liveness-assign-imm-local-in-op-eq.rs b/src/test/compile-fail/liveness-assign-imm-local-in-op-eq.rs index e1eb3246137d2..bfdd4347de74e 100644 --- a/src/test/compile-fail/liveness-assign-imm-local-in-op-eq.rs +++ b/src/test/compile-fail/liveness-assign-imm-local-in-op-eq.rs @@ -11,8 +11,8 @@ fn test() { let v: isize; v = 2; //~ NOTE first assignment - v += 1; //~ ERROR re-assignment of immutable variable - //~| NOTE re-assignment of immutable + v += 1; //~ ERROR cannot assign twice to immutable variable + //~| NOTE cannot assign twice to immutable v.clone(); } diff --git a/src/test/compile-fail/liveness-assign-imm-local-with-init.rs b/src/test/compile-fail/liveness-assign-imm-local-with-init.rs index 2468c91f34bbd..f35c1c69acdf8 100644 --- a/src/test/compile-fail/liveness-assign-imm-local-with-init.rs +++ b/src/test/compile-fail/liveness-assign-imm-local-with-init.rs @@ -11,8 +11,8 @@ fn test() { let v: isize = 1; //~ NOTE first assignment v.clone(); - v = 2; //~ ERROR re-assignment of immutable variable - //~| NOTE re-assignment of immutable + v = 2; //~ ERROR cannot assign twice to immutable variable + //~| NOTE cannot assign twice to immutable v.clone(); } diff --git a/src/test/compile-fail/mut-pattern-internal-mutability.rs b/src/test/compile-fail/mut-pattern-internal-mutability.rs index 3a84bd6565e8d..1c7bc9d73037c 100644 --- a/src/test/compile-fail/mut-pattern-internal-mutability.rs +++ b/src/test/compile-fail/mut-pattern-internal-mutability.rs @@ -15,9 +15,9 @@ fn main() { let foo = &mut 1; let &mut x = foo; - x += 1; //[ast]~ ERROR re-assignment of immutable variable - //[mir]~^ ERROR re-assignment of immutable variable `x` (Ast) - //[mir]~| ERROR re-assignment of immutable variable `x` (Mir) + x += 1; //[ast]~ ERROR cannot assign twice to immutable variable + //[mir]~^ ERROR cannot assign twice to immutable variable `x` (Ast) + //[mir]~| ERROR cannot assign twice to immutable variable `x` (Mir) // explicitly mut-ify internals let &mut mut x = foo; From 36822ba39a40f29c16147c0408adc01a188f5984 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 25 Oct 2017 09:58:48 -0700 Subject: [PATCH 8/9] ci: Test more asmjs again This was accidentally added in #45352, forgot to back it out! --- src/ci/docker/asmjs/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/asmjs/Dockerfile b/src/ci/docker/asmjs/Dockerfile index c0bf689e39db9..07849a20d0045 100644 --- a/src/ci/docker/asmjs/Dockerfile +++ b/src/ci/docker/asmjs/Dockerfile @@ -31,4 +31,4 @@ ENV TARGETS=asmjs-unknown-emscripten ENV RUST_CONFIGURE_ARGS --target=$TARGETS -ENV SCRIPT python2.7 ../x.py test --target $TARGETS src/test/run-pass +ENV SCRIPT python2.7 ../x.py test --target $TARGETS From c2c1910d69086827629d37deb5ce6a2febdb36fd Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Mon, 23 Oct 2017 14:21:00 -0700 Subject: [PATCH 9/9] Implement Hash for raw pointers to unsized types --- src/libcore/hash/mod.rs | 28 ++++++++++++++++++++++++---- src/libcore/tests/hash/mod.rs | 8 ++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/libcore/hash/mod.rs b/src/libcore/hash/mod.rs index bc1b911cd78cc..b3c11ed1b5ac4 100644 --- a/src/libcore/hash/mod.rs +++ b/src/libcore/hash/mod.rs @@ -665,16 +665,36 @@ mod impls { } #[stable(feature = "rust1", since = "1.0.0")] - impl Hash for *const T { + impl Hash for *const T { fn hash(&self, state: &mut H) { - state.write_usize(*self as usize) + if mem::size_of::() == mem::size_of::() { + // Thin pointer + state.write_usize(*self as *const () as usize); + } else { + // Fat pointer + let (a, b) = unsafe { + *(self as *const Self as *const (usize, usize)) + }; + state.write_usize(a); + state.write_usize(b); + } } } #[stable(feature = "rust1", since = "1.0.0")] - impl Hash for *mut T { + impl Hash for *mut T { fn hash(&self, state: &mut H) { - state.write_usize(*self as usize) + if mem::size_of::() == mem::size_of::() { + // Thin pointer + state.write_usize(*self as *const () as usize); + } else { + // Fat pointer + let (a, b) = unsafe { + *(self as *const Self as *const (usize, usize)) + }; + state.write_usize(a); + state.write_usize(b); + } } } } diff --git a/src/libcore/tests/hash/mod.rs b/src/libcore/tests/hash/mod.rs index 43ba941f13bfc..8716421b424de 100644 --- a/src/libcore/tests/hash/mod.rs +++ b/src/libcore/tests/hash/mod.rs @@ -79,6 +79,14 @@ fn test_writer_hasher() { let ptr = 5_usize as *mut i32; assert_eq!(hash(&ptr), 5); + + let cs: &mut [u8] = &mut [1, 2, 3]; + let ptr = cs.as_ptr(); + let slice_ptr = cs as *const [u8]; + assert_eq!(hash(&slice_ptr), hash(&ptr) + cs.len() as u64); + + let slice_ptr = cs as *mut [u8]; + assert_eq!(hash(&slice_ptr), hash(&ptr) + cs.len() as u64); } struct Custom { hash: u64 }