From 45832383af02a377877c2701d90dbe29883532a2 Mon Sep 17 00:00:00 2001 From: "@amit.chandra" <@amit.chandra> Date: Sat, 22 Jun 2019 22:59:24 +0530 Subject: [PATCH 01/21] squash commit for nth_back on chunks exact wip nth_back for chunks_exact working nth_back for chunks exact Signed-off-by: wizAmit --- src/libcore/slice/mod.rs | 15 +++++++++++++++ src/libcore/tests/slice.rs | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index c6d44324ef5ee..fe48e2458cd16 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -4453,6 +4453,21 @@ impl<'a, T> DoubleEndedIterator for ChunksExact<'a, T> { Some(snd) } } + + #[inline] + fn nth_back(&mut self, n: usize) -> Option { + let len = self.len(); + if n >= len { + self.v = &[]; + None + } else { + let start = (len - 1 - n) * self.chunk_size; + let end = start + self.chunk_size; + let nth_back = &self.v[start..end]; + self.v = &self.v[..start]; + Some(nth_back) + } + } } #[stable(feature = "chunks_exact", since = "1.31.0")] diff --git a/src/libcore/tests/slice.rs b/src/libcore/tests/slice.rs index 03e65d2fe0b81..13b02c7184234 100644 --- a/src/libcore/tests/slice.rs +++ b/src/libcore/tests/slice.rs @@ -275,6 +275,25 @@ fn test_chunks_exact_nth() { assert_eq!(c2.next(), None); } +#[test] +fn test_chunks_exact_nth_back() { + let v: &[i32] = &[0, 1, 2, 3, 4, 5]; + let mut c = v.chunks_exact(2); + assert_eq!(c.nth_back(1).unwrap(), &[2, 3]); + assert_eq!(c.next().unwrap(), &[0, 1]); + assert_eq!(c.next(), None); + + let v2: &[i32] = &[0, 1, 2, 3, 4]; + let mut c2 = v2.chunks_exact(3); + assert_eq!(c2.nth_back(0).unwrap(), &[0, 1, 2]); + assert_eq!(c2.next(), None); + assert_eq!(c2.next_back(), None); + + let v3: &[i32] = &[0, 1, 2, 3, 4]; + let mut c3 = v3.chunks_exact(10); + assert_eq!(c3.nth_back(0), None); +} + #[test] fn test_chunks_exact_last() { let v: &[i32] = &[0, 1, 2, 3, 4, 5]; From 1e9e4b0a7acce29ab00c3e5cc51dc5fbf650807d Mon Sep 17 00:00:00 2001 From: CrLF0710 Date: Fri, 21 Jun 2019 18:13:41 +0800 Subject: [PATCH 02/21] Add mention of VS 2019 in link error output. --- src/librustc_codegen_ssa/back/link.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs index 0ba5451bd72f5..6789f35ff4934 100644 --- a/src/librustc_codegen_ssa/back/link.rs +++ b/src/librustc_codegen_ssa/back/link.rs @@ -630,10 +630,14 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(sess: &'a Session, linker_error.emit(); if sess.target.target.options.is_like_msvc && linker_not_found { - sess.note_without_error("the msvc targets depend on the msvc linker \ - but `link.exe` was not found"); - sess.note_without_error("please ensure that VS 2013, VS 2015 or VS 2017 \ - was installed with the Visual C++ option"); + sess.note_without_error( + "the msvc targets depend on the msvc linker \ + but `link.exe` was not found", + ); + sess.note_without_error( + "please ensure that VS 2013, VS 2015, VS 2017 or VS 2019 \ + was installed with the Visual C++ option", + ); } sess.abort_if_errors(); } From 19f86224a6f0cba0b1563f62a6b43bc888d517db Mon Sep 17 00:00:00 2001 From: CrLF0710 Date: Mon, 24 Jun 2019 19:56:19 +0800 Subject: [PATCH 03/21] Just switch to English linker output using environment variable when using msvc. --- src/librustc_target/spec/windows_msvc_base.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_target/spec/windows_msvc_base.rs b/src/librustc_target/spec/windows_msvc_base.rs index fdd747cdb865a..db4b6e252c664 100644 --- a/src/librustc_target/spec/windows_msvc_base.rs +++ b/src/librustc_target/spec/windows_msvc_base.rs @@ -19,6 +19,7 @@ pub fn opts() -> TargetOptions { target_family: Some("windows".to_string()), is_like_windows: true, is_like_msvc: true, + link_env: vec![("VSLANG".to_string(), "1033".to_string())], pre_link_args: args, crt_static_allows_dylibs: true, crt_static_respected: true, From 9d798b71988fd70e9f8147c48edd13a9d8555a32 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 25 Jun 2019 13:31:05 -0700 Subject: [PATCH 04/21] Adjust warning of -C extra-filename with -o. --- src/librustc_interface/util.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc_interface/util.rs b/src/librustc_interface/util.rs index a86d3cc43948d..6ae5e94b11af3 100644 --- a/src/librustc_interface/util.rs +++ b/src/librustc_interface/util.rs @@ -642,14 +642,14 @@ pub fn build_output_filenames( ); None } else { + if !sess.opts.cg.extra_filename.is_empty() { + sess.warn("ignoring -C extra-filename flag due to -o flag"); + } Some(out_file.clone()) }; if *odir != None { sess.warn("ignoring --out-dir flag due to -o flag"); } - if !sess.opts.cg.extra_filename.is_empty() { - sess.warn("ignoring -C extra-filename flag due to -o flag"); - } OutputFilenames { out_directory: out_file.parent().unwrap_or_else(|| Path::new("")).to_path_buf(), From e1e95a83861271e144f65903c652ab9fa9bd64b8 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 26 Jun 2019 18:50:20 -0500 Subject: [PATCH 05/21] Use force_bits when casting from a pointer --- src/librustc_mir/interpret/cast.rs | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/librustc_mir/interpret/cast.rs b/src/librustc_mir/interpret/cast.rs index fbacdf6cd93bb..bd012d4c2bf57 100644 --- a/src/librustc_mir/interpret/cast.rs +++ b/src/librustc_mir/interpret/cast.rs @@ -242,14 +242,31 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { ty: Ty<'tcx> ) -> InterpResult<'tcx, Scalar> { use rustc::ty::TyKind::*; - match ty.sty { + + let size = match ty.sty { // Casting to a reference or fn pointer is not permitted by rustc, // no need to support it here. - RawPtr(_) | - Int(IntTy::Isize) | - Uint(UintTy::Usize) => Ok(ptr.into()), - Int(_) | Uint(_) => err!(ReadPointerAsBytes), - _ => err!(Unimplemented(format!("ptr to {:?} cast", ty))), + RawPtr(_) => return Ok(ptr.into()), + Int(IntTy::Isize) | Uint(UintTy::Usize) => { + let size = self.memory.pointer_size(); + if let Ok(bits) = self.force_bits(Scalar::Ptr(ptr), size) { + return Ok(Scalar::from_uint(bits, size)); + } + return Ok(ptr.into()); + } + // If the target type is a sized integer, we need the its size to perform the pointer cast + Int(i) => i.bit_width().unwrap(), + Uint(i) => i.bit_width().unwrap(), + // Casting to any other type is not implemented + _ => return err!(Unimplemented(format!("ptr to {:?} cast", ty))), + }; + + let size = Size::from_bits(size as u64); + + if let Ok(bits) = self.force_bits(Scalar::Ptr(ptr), size) { + Ok(Scalar::from_uint(bits, size)) + } else { + err!(ReadPointerAsBytes) } } From 8339211809987bcdc4a627214f03e4479182bfc2 Mon Sep 17 00:00:00 2001 From: CrLF0710 Date: Thu, 27 Jun 2019 20:59:17 +0800 Subject: [PATCH 06/21] Added comment description. --- src/librustc_target/spec/windows_msvc_base.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/librustc_target/spec/windows_msvc_base.rs b/src/librustc_target/spec/windows_msvc_base.rs index db4b6e252c664..b139083e99fc1 100644 --- a/src/librustc_target/spec/windows_msvc_base.rs +++ b/src/librustc_target/spec/windows_msvc_base.rs @@ -19,6 +19,9 @@ pub fn opts() -> TargetOptions { target_family: Some("windows".to_string()), is_like_windows: true, is_like_msvc: true, + // set VSLANG to 1033 can prevent link.exe from using + // language packs, and avoid generating Non-UTF-8 error + // messages if a link error occurred. link_env: vec![("VSLANG".to_string(), "1033".to_string())], pre_link_args: args, crt_static_allows_dylibs: true, From 2a375827ab56900bf550161ee08ada664e68b267 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 27 Jun 2019 06:38:57 -0700 Subject: [PATCH 07/21] std: Move a process test out of libstd This commit moves a test out of libstd which is causing deadlocks on musl on CI. Looks like the recent update in musl versions brings in some internal updates to musl which makes `setgid` and `setuid` invalid to call after a `fork` in a multithreaded program. The issue seen here is that the child thread was attempting to grab a lock held by a nonexistent thread, meaning that the child process simply deadlocked causing the whole test to deadlock. This commit moves the test to its own file with no threads which should work. --- src/libstd/process.rs | 27 --------------------------- src/test/run-pass/command-uid-gid.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 27 deletions(-) create mode 100644 src/test/run-pass/command-uid-gid.rs diff --git a/src/libstd/process.rs b/src/libstd/process.rs index a568f46663730..000f80f99e7a9 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -1765,33 +1765,6 @@ mod tests { assert_eq!(out, "foobar\n"); } - - #[test] - #[cfg_attr(target_os = "android", ignore)] - #[cfg(unix)] - fn uid_works() { - use crate::os::unix::prelude::*; - - let mut p = Command::new("/bin/sh") - .arg("-c").arg("true") - .uid(unsafe { libc::getuid() }) - .gid(unsafe { libc::getgid() }) - .spawn().unwrap(); - assert!(p.wait().unwrap().success()); - } - - #[test] - #[cfg_attr(target_os = "android", ignore)] - #[cfg(unix)] - fn uid_to_root_fails() { - use crate::os::unix::prelude::*; - - // if we're already root, this isn't a valid test. Most of the bots run - // as non-root though (android is an exception). - if unsafe { libc::getuid() == 0 } { return } - assert!(Command::new("/bin/ls").uid(0).gid(0).spawn().is_err()); - } - #[test] #[cfg_attr(target_os = "android", ignore)] fn test_process_status() { diff --git a/src/test/run-pass/command-uid-gid.rs b/src/test/run-pass/command-uid-gid.rs new file mode 100644 index 0000000000000..2b52c5d104c24 --- /dev/null +++ b/src/test/run-pass/command-uid-gid.rs @@ -0,0 +1,26 @@ +#![feature(rustc_private)] + +fn main() { + #[cfg(unix)] + run() +} + +#[cfg(unix)] +fn run() { + extern crate libc; + use std::process::Command; + use std::os::unix::prelude::*; + + let mut p = Command::new("/bin/sh") + .arg("-c").arg("true") + .uid(unsafe { libc::getuid() }) + .gid(unsafe { libc::getgid() }) + .spawn().unwrap(); + assert!(p.wait().unwrap().success()); + + // if we're already root, this isn't a valid test. Most of the bots run + // as non-root though (android is an exception). + if unsafe { libc::getuid() != 0 } { + assert!(Command::new("/bin/ls").uid(0).gid(0).spawn().is_err()); + } +} From a0e5fcf14624250ce93230cba5924b6175a176b5 Mon Sep 17 00:00:00 2001 From: cclauss Date: Fri, 28 Jun 2019 06:43:03 +0200 Subject: [PATCH 08/21] import gdb for explicit access to gdb.current_objfile() --- src/etc/gdb_load_rust_pretty_printers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/etc/gdb_load_rust_pretty_printers.py b/src/etc/gdb_load_rust_pretty_printers.py index c551346bb00bf..fe38c49d2707d 100644 --- a/src/etc/gdb_load_rust_pretty_printers.py +++ b/src/etc/gdb_load_rust_pretty_printers.py @@ -1,2 +1,3 @@ +import gdb import gdb_rust_pretty_printing gdb_rust_pretty_printing.register_printers(gdb.current_objfile()) From 7f1e160e02112d4d23a72e52b2ab23860e6a956f Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 28 Jun 2019 14:25:33 -0500 Subject: [PATCH 09/21] Reorganize code for readabilty and fixed problem with type sizes --- src/librustc_mir/interpret/cast.rs | 47 ++++++++++++++++++------------ 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/src/librustc_mir/interpret/cast.rs b/src/librustc_mir/interpret/cast.rs index bd012d4c2bf57..e8bca0c712399 100644 --- a/src/librustc_mir/interpret/cast.rs +++ b/src/librustc_mir/interpret/cast.rs @@ -151,7 +151,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { "Unexpected cast from type {:?}", src_layout.ty ); match val.to_bits_or_ptr(src_layout.size, self) { - Err(ptr) => self.cast_from_ptr(ptr, dest_layout.ty), + Err(ptr) => self.cast_from_ptr(ptr, src_layout, dest_layout), Ok(data) => self.cast_from_int(data, src_layout, dest_layout), } } @@ -239,34 +239,43 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { fn cast_from_ptr( &self, ptr: Pointer, - ty: Ty<'tcx> + src_layout: TyLayout<'tcx>, + dest_layout: TyLayout<'tcx>, ) -> InterpResult<'tcx, Scalar> { use rustc::ty::TyKind::*; - let size = match ty.sty { + fn int_size<'tcx>(layout: TyLayout<'tcx>) -> Option { + match layout.ty.sty { + Int(i) => i.bit_width(), + Uint(i) => i.bit_width(), + _ => bug!("Not an integer"), + } + } + + match dest_layout.ty.sty { // Casting to a reference or fn pointer is not permitted by rustc, // no need to support it here. - RawPtr(_) => return Ok(ptr.into()), + RawPtr(_) => Ok(ptr.into()), Int(IntTy::Isize) | Uint(UintTy::Usize) => { let size = self.memory.pointer_size(); + if let Ok(bits) = self.force_bits(Scalar::Ptr(ptr), size) { - return Ok(Scalar::from_uint(bits, size)); - } - return Ok(ptr.into()); + self.cast_from_int(bits, src_layout, dest_layout) + } else { + Ok(ptr.into()) + } } - // If the target type is a sized integer, we need the its size to perform the pointer cast - Int(i) => i.bit_width().unwrap(), - Uint(i) => i.bit_width().unwrap(), + Int(_) | Uint(_) => { + let size = Size::from_bits(int_size(dest_layout).unwrap() as u64); + + if let Ok(bits) = self.force_bits(Scalar::Ptr(ptr), size) { + self.cast_from_int(bits, src_layout, dest_layout) + } else { + err!(ReadPointerAsBytes) + } + }, // Casting to any other type is not implemented - _ => return err!(Unimplemented(format!("ptr to {:?} cast", ty))), - }; - - let size = Size::from_bits(size as u64); - - if let Ok(bits) = self.force_bits(Scalar::Ptr(ptr), size) { - Ok(Scalar::from_uint(bits, size)) - } else { - err!(ReadPointerAsBytes) + _ => return err!(Unimplemented(format!("ptr to {:?} cast", dest_layout.ty))), } } From 95275658f26e0e83fb26f946e716fa5de28fe43a Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Thu, 27 Jun 2019 16:11:46 -0700 Subject: [PATCH 10/21] Add Vec::leak --- src/liballoc/vec.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 92fe0834dd029..c0544d7469ca7 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -1367,6 +1367,40 @@ impl Vec { self.truncate(new_len); } } + + /// Consumes and leaks the `Vec`, returning a mutable reference to the contents, + /// `&'a mut [T]`. Note that the type `T` must outlive the chosen lifetime + /// `'a`. If the type has only static references, or none at all, then this + /// may be chosen to be `'static`. + /// + /// This function is similar to the `leak` function on `Box`. + /// + /// This function is mainly useful for data that lives for the remainder of + /// the program's life. Dropping the returned reference will cause a memory + /// leak. + /// + /// # Examples + /// + /// Simple usage: + /// + /// ``` + /// #![feature(vec_leak)] + /// + /// fn main() { + /// let x = vec![1, 2, 3]; + /// let static_ref: &'static mut [usize] = Vec::leak(x); + /// static_ref[0] += 1; + /// assert_eq!(static_ref, &[2, 2, 3]); + /// } + /// ``` + #[unstable(feature = "vec_leak", issue = "62195")] + #[inline] + pub fn leak<'a>(vec: Vec) -> &'a mut [T] + where + T: 'a // Technically not needed, but kept to be explicit. + { + Box::leak(vec.into_boxed_slice()) + } } impl Vec { From 95bc72052c65e22cbf23f80bfa314528abcb981b Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sat, 29 Jun 2019 07:59:45 -0500 Subject: [PATCH 11/21] Use pointer size as the source size --- src/librustc_mir/interpret/cast.rs | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/librustc_mir/interpret/cast.rs b/src/librustc_mir/interpret/cast.rs index e8bca0c712399..73ef0bd6dacb6 100644 --- a/src/librustc_mir/interpret/cast.rs +++ b/src/librustc_mir/interpret/cast.rs @@ -244,37 +244,24 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { ) -> InterpResult<'tcx, Scalar> { use rustc::ty::TyKind::*; - fn int_size<'tcx>(layout: TyLayout<'tcx>) -> Option { - match layout.ty.sty { - Int(i) => i.bit_width(), - Uint(i) => i.bit_width(), - _ => bug!("Not an integer"), - } - } - match dest_layout.ty.sty { // Casting to a reference or fn pointer is not permitted by rustc, // no need to support it here. RawPtr(_) => Ok(ptr.into()), Int(IntTy::Isize) | Uint(UintTy::Usize) => { - let size = self.memory.pointer_size(); - - if let Ok(bits) = self.force_bits(Scalar::Ptr(ptr), size) { + if let Ok(bits) = self.force_bits(Scalar::Ptr(ptr), self.memory.pointer_size()) { self.cast_from_int(bits, src_layout, dest_layout) } else { Ok(ptr.into()) } } Int(_) | Uint(_) => { - let size = Size::from_bits(int_size(dest_layout).unwrap() as u64); - - if let Ok(bits) = self.force_bits(Scalar::Ptr(ptr), size) { + if let Ok(bits) = self.force_bits(Scalar::Ptr(ptr), self.memory.pointer_size()) { self.cast_from_int(bits, src_layout, dest_layout) } else { err!(ReadPointerAsBytes) } - }, - // Casting to any other type is not implemented + } _ => return err!(Unimplemented(format!("ptr to {:?} cast", dest_layout.ty))), } } From 51793bd318a162752def38a6ae1ec9292861d0cc Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sat, 29 Jun 2019 13:19:37 -0500 Subject: [PATCH 12/21] Simplify control flow --- src/librustc_mir/interpret/cast.rs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/librustc_mir/interpret/cast.rs b/src/librustc_mir/interpret/cast.rs index 73ef0bd6dacb6..2777ada14f9ad 100644 --- a/src/librustc_mir/interpret/cast.rs +++ b/src/librustc_mir/interpret/cast.rs @@ -1,7 +1,7 @@ use rustc::ty::{self, Ty, TypeAndMut}; use rustc::ty::layout::{self, TyLayout, Size}; use rustc::ty::adjustment::{PointerCast}; -use syntax::ast::{FloatTy, IntTy, UintTy}; +use syntax::ast::FloatTy; use syntax::symbol::sym; use rustc_apfloat::ieee::{Single, Double}; @@ -248,18 +248,13 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { // Casting to a reference or fn pointer is not permitted by rustc, // no need to support it here. RawPtr(_) => Ok(ptr.into()), - Int(IntTy::Isize) | Uint(UintTy::Usize) => { - if let Ok(bits) = self.force_bits(Scalar::Ptr(ptr), self.memory.pointer_size()) { - self.cast_from_int(bits, src_layout, dest_layout) - } else { - Ok(ptr.into()) - } - } Int(_) | Uint(_) => { - if let Ok(bits) = self.force_bits(Scalar::Ptr(ptr), self.memory.pointer_size()) { - self.cast_from_int(bits, src_layout, dest_layout) - } else { - err!(ReadPointerAsBytes) + let size = self.memory.pointer_size(); + + match self.force_bits(Scalar::Ptr(ptr), size) { + Ok(bits) => self.cast_from_int(bits, src_layout, dest_layout), + Err(_) if dest_layout.size == size => Ok(ptr.into()), + Err(e) => Err(e), } } _ => return err!(Unimplemented(format!("ptr to {:?} cast", dest_layout.ty))), From dfb9f5be30c7fefbe4458fb873c2bdc0604f9a17 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 29 Jun 2019 22:24:32 +0200 Subject: [PATCH 13/21] Add missing links for TryFrom docs --- src/libcore/convert.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index a697b7bd6e589..34d19748e5609 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -410,12 +410,12 @@ pub trait TryInto: Sized { /// /// This is useful when you are doing a type conversion that may /// trivially succeed but may also need special handling. -/// For example, there is no way to convert an `i64` into an `i32` -/// using the [`From`] trait, because an `i64` may contain a value -/// that an `i32` cannot represent and so the conversion would lose data. -/// This might be handled by truncating the `i64` to an `i32` (essentially -/// giving the `i64`'s value modulo `i32::MAX`) or by simply returning -/// `i32::MAX`, or by some other method. The `From` trait is intended +/// For example, there is no way to convert an [`i64`] into an [`i32`] +/// using the [`From`] trait, because an [`i64`] may contain a value +/// that an [`i32`] cannot represent and so the conversion would lose data. +/// This might be handled by truncating the [`i64`] to an [`i32`] (essentially +/// giving the [`i64`]'s value modulo [`i32::MAX`]) or by simply returning +/// [`i32::MAX`], or by some other method. The [`From`] trait is intended /// for perfect conversions, so the `TryFrom` trait informs the /// programmer when a type conversion could go bad and lets them /// decide how to handle it. @@ -425,8 +425,8 @@ pub trait TryInto: Sized { /// - `TryFrom for U` implies [`TryInto`]` for T` /// - [`try_from`] is reflexive, which means that `TryFrom for T` /// is implemented and cannot fail -- the associated `Error` type for -/// calling `T::try_from()` on a value of type `T` is `Infallible`. -/// When the `!` type is stablized `Infallible` and `!` will be +/// calling `T::try_from()` on a value of type `T` is [`Infallible`]. +/// When the [`!`] type is stablized [`Infallible`] and [`!`] will be /// equivalent. /// /// `TryFrom` can be implemented as follows: @@ -451,7 +451,7 @@ pub trait TryInto: Sized { /// /// # Examples /// -/// As described, [`i32`] implements `TryFrom`: +/// As described, [`i32`] implements `TryFrom<`[`i64`]`>`: /// /// ``` /// use std::convert::TryFrom; @@ -474,6 +474,8 @@ pub trait TryInto: Sized { /// /// [`try_from`]: trait.TryFrom.html#tymethod.try_from /// [`TryInto`]: trait.TryInto.html +/// [`i32::MAX`]: ../../std/i32/constant.MAX.html +/// [`!`]: ../../std/primitive.never.html #[stable(feature = "try_from", since = "1.34.0")] pub trait TryFrom: Sized { /// The type returned in the event of a conversion error. From 3e83728ddde9d8cb2ae3b35b99d570e7a9c5fbd6 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 27 Jun 2019 18:01:31 +0200 Subject: [PATCH 14/21] Add missing type urls in Into trait --- src/libcore/convert.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index a697b7bd6e589..d9f192c0e217a 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -251,12 +251,12 @@ pub trait AsMut { /// /// # Examples /// -/// [`String`] implements `Into>`: +/// [`String`] implements [`Into`]`<`[`Vec`]`<`[`u8`]`>>`: /// /// In order to express that we want a generic function to take all arguments that can be /// converted to a specified type `T`, we can use a trait bound of [`Into`]``. /// For example: The function `is_hello` takes all arguments that can be converted into a -/// `Vec`. +/// [`Vec`]`<`[`u8`]`>`. /// /// ``` /// fn is_hello>>(s: T) { @@ -274,6 +274,7 @@ pub trait AsMut { /// [`String`]: ../../std/string/struct.String.html /// [`From`]: trait.From.html /// [`Into`]: trait.Into.html +/// [`Vec`]: ../../std/vec/struct.Vec.html #[stable(feature = "rust1", since = "1.0.0")] pub trait Into: Sized { /// Performs the conversion. From 92c28bfabcbbbbf864308cd71750d4b20f306b37 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sat, 29 Jun 2019 22:50:37 -0500 Subject: [PATCH 15/21] Replace error by bug macro --- src/librustc_mir/interpret/cast.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_mir/interpret/cast.rs b/src/librustc_mir/interpret/cast.rs index 2777ada14f9ad..e6c9d9f5c79d8 100644 --- a/src/librustc_mir/interpret/cast.rs +++ b/src/librustc_mir/interpret/cast.rs @@ -257,7 +257,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { Err(e) => Err(e), } } - _ => return err!(Unimplemented(format!("ptr to {:?} cast", dest_layout.ty))), + _ => bug!("invalid MIR: ptr to {:?} cast", dest_layout.ty) } } From fc70c37d167237023df1e75d154d1e6bebd44aee Mon Sep 17 00:00:00 2001 From: Chris Gregory Date: Sun, 30 Jun 2019 11:56:21 -0700 Subject: [PATCH 16/21] Improve box clone doctests to ensure the documentation is valid --- src/liballoc/boxed.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 9109a730cce2d..19b0f82db4335 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -367,12 +367,19 @@ impl Clone for Box { /// ``` /// let x = Box::new(5); /// let y = x.clone(); + /// + /// // The value is the same + /// assert_eq!(x, y); + /// + /// // But they are unique objects + /// assert_ne!(&*x as *const i32, &*y as *const i32); /// ``` #[rustfmt::skip] #[inline] fn clone(&self) -> Box { box { (**self).clone() } } + /// Copies `source`'s contents into `self` without creating a new allocation. /// /// # Examples @@ -380,10 +387,15 @@ impl Clone for Box { /// ``` /// let x = Box::new(5); /// let mut y = Box::new(10); + /// let yp: *const i32 = &*y; /// /// y.clone_from(&x); /// - /// assert_eq!(*y, 5); + /// // The value is the same + /// assert_eq!(x, y); + /// + /// // And no allocation occurred + /// assert_eq!(yp, &*y); /// ``` #[inline] fn clone_from(&mut self, source: &Box) { From de00ae726626bd9a5061306600e03209afb893bd Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sun, 30 Jun 2019 23:23:11 +0200 Subject: [PATCH 17/21] Switch tracking issue for 'slice_patterns'. --- .../src/language-features/slice-patterns.md | 4 ++-- src/librustc_typeck/check/_match.rs | 2 +- src/libsyntax/feature_gate.rs | 4 ++-- .../feature-gates/feature-gate-slice-patterns.stderr | 12 ++++++------ 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/doc/unstable-book/src/language-features/slice-patterns.md b/src/doc/unstable-book/src/language-features/slice-patterns.md index 133174268ef93..00c81f03ba173 100644 --- a/src/doc/unstable-book/src/language-features/slice-patterns.md +++ b/src/doc/unstable-book/src/language-features/slice-patterns.md @@ -1,8 +1,8 @@ # `slice_patterns` -The tracking issue for this feature is: [#23121] +The tracking issue for this feature is: [#62254] -[#23121]: https://github.com/rust-lang/rust/issues/23121 +[#62254]: https://github.com/rust-lang/rust/issues/62254 ------------------------ diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index b435c99ad01f5..bcb66f1715942 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -458,7 +458,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { match ty.sty { ty::Array(..) | ty::Slice(..) => { err.help("the semantics of slice patterns changed \ - recently; see issue #23121"); + recently; see issue #62254"); } _ => {} } diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index a6e8441a915e0..00b8cf67b2ffb 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -323,7 +323,7 @@ declare_features! ( (active, nll, "1.0.0", Some(43234), None), // Allows using slice patterns. - (active, slice_patterns, "1.0.0", Some(23121), None), + (active, slice_patterns, "1.0.0", Some(62254), None), // Allows the definition of `const` functions with some advanced features. (active, const_fn, "1.2.0", Some(57563), None), @@ -610,7 +610,7 @@ declare_features! ( (removed, allocator, "1.0.0", None, None, None), (removed, simd, "1.0.0", Some(27731), None, Some("removed in favor of `#[repr(simd)]`")), - (removed, advanced_slice_patterns, "1.0.0", Some(23121), None, + (removed, advanced_slice_patterns, "1.0.0", Some(62254), None, Some("merged into `#![feature(slice_patterns)]`")), (removed, macro_reexport, "1.0.0", Some(29638), None, Some("subsumed by `pub use`")), diff --git a/src/test/ui/feature-gates/feature-gate-slice-patterns.stderr b/src/test/ui/feature-gates/feature-gate-slice-patterns.stderr index fe3c1e0afdd6b..03bf933cd084d 100644 --- a/src/test/ui/feature-gates/feature-gate-slice-patterns.stderr +++ b/src/test/ui/feature-gates/feature-gate-slice-patterns.stderr @@ -4,7 +4,7 @@ error[E0658]: syntax for subslices in slice patterns is not yet stabilized LL | [1, 2, ..] => {} | ^^ | - = note: for more information, see https://github.com/rust-lang/rust/issues/23121 + = note: for more information, see https://github.com/rust-lang/rust/issues/62254 = help: add #![feature(slice_patterns)] to the crate attributes to enable error[E0658]: syntax for subslices in slice patterns is not yet stabilized @@ -13,7 +13,7 @@ error[E0658]: syntax for subslices in slice patterns is not yet stabilized LL | [1, .., 5] => {} | ^^ | - = note: for more information, see https://github.com/rust-lang/rust/issues/23121 + = note: for more information, see https://github.com/rust-lang/rust/issues/62254 = help: add #![feature(slice_patterns)] to the crate attributes to enable error[E0658]: syntax for subslices in slice patterns is not yet stabilized @@ -22,7 +22,7 @@ error[E0658]: syntax for subslices in slice patterns is not yet stabilized LL | [.., 4, 5] => {} | ^^ | - = note: for more information, see https://github.com/rust-lang/rust/issues/23121 + = note: for more information, see https://github.com/rust-lang/rust/issues/62254 = help: add #![feature(slice_patterns)] to the crate attributes to enable error[E0658]: syntax for subslices in slice patterns is not yet stabilized @@ -31,7 +31,7 @@ error[E0658]: syntax for subslices in slice patterns is not yet stabilized LL | [ xs.., 4, 5 ] => {} | ^^ | - = note: for more information, see https://github.com/rust-lang/rust/issues/23121 + = note: for more information, see https://github.com/rust-lang/rust/issues/62254 = help: add #![feature(slice_patterns)] to the crate attributes to enable error[E0658]: syntax for subslices in slice patterns is not yet stabilized @@ -40,7 +40,7 @@ error[E0658]: syntax for subslices in slice patterns is not yet stabilized LL | [ 1, xs.., 5 ] => {} | ^^ | - = note: for more information, see https://github.com/rust-lang/rust/issues/23121 + = note: for more information, see https://github.com/rust-lang/rust/issues/62254 = help: add #![feature(slice_patterns)] to the crate attributes to enable error[E0658]: syntax for subslices in slice patterns is not yet stabilized @@ -49,7 +49,7 @@ error[E0658]: syntax for subslices in slice patterns is not yet stabilized LL | [ 1, 2, xs.. ] => {} | ^^ | - = note: for more information, see https://github.com/rust-lang/rust/issues/23121 + = note: for more information, see https://github.com/rust-lang/rust/issues/62254 = help: add #![feature(slice_patterns)] to the crate attributes to enable error: aborting due to 6 previous errors From 353b5d413e6aba4d89ca7609f9953a2d6770d2ed Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Mon, 1 Jul 2019 20:23:35 -0400 Subject: [PATCH 18/21] Fix michaelwoerister's mailmap --- .mailmap | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.mailmap b/.mailmap index 5673cc5cfbc9d..c5ecfb54fca52 100644 --- a/.mailmap +++ b/.mailmap @@ -167,6 +167,8 @@ Matthijs Hofstra Melody Horn Michael Williams Michael Woerister +Michael Woerister +Michael Woerister Mickaƫl Raybaud-Roig m-r-r Ms2ger Mukilan Thiagarajan From 7454b29efc76c9d029359e6900262206722f65dc Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Tue, 2 Jul 2019 15:19:19 +0200 Subject: [PATCH 19/21] HashMap is UnwindSafe Fixes https://github.com/rust-lang/rust/issues/62301, a regression in 1.36.0 which was caused by hashbrown using `NonZero` where the older hashmap used `Unique`. --- src/libstd/collections/hash/map.rs | 6 ++++++ src/libstd/panic.rs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 5a2fe2b244f55..2925d8362c8d9 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -2608,6 +2608,12 @@ mod test_map { use realstd::collections::CollectionAllocErr::*; use realstd::usize; + // https://github.com/rust-lang/rust/issues/62301 + fn _assert_hashmap_is_unwind_safe() { + fn assert_unwind_safe() {} + assert_unwind_safe::>>(); + } + #[test] fn test_zero_capacities() { type HM = HashMap; diff --git a/src/libstd/panic.rs b/src/libstd/panic.rs index 7a3b5d30500a9..1d4fd98dd754f 100644 --- a/src/libstd/panic.rs +++ b/src/libstd/panic.rs @@ -4,6 +4,7 @@ use crate::any::Any; use crate::cell::UnsafeCell; +use crate::collections; use crate::fmt; use crate::future::Future; use crate::pin::Pin; @@ -285,6 +286,11 @@ impl RefUnwindSafe for atomic::AtomicBool {} #[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")] impl RefUnwindSafe for atomic::AtomicPtr {} +// https://github.com/rust-lang/rust/issues/62301 +#[stable(feature = "hashbrown", since = "1.36.0")] +impl UnwindSafe for collections::HashMap + where K: UnwindSafe, V: UnwindSafe, S: UnwindSafe {} + #[stable(feature = "catch_unwind", since = "1.9.0")] impl Deref for AssertUnwindSafe { type Target = T; From dd702cc65330281f7cfed746fa02ead92ae8c646 Mon Sep 17 00:00:00 2001 From: Julien Cretin Date: Wed, 3 Jul 2019 00:37:25 +0200 Subject: [PATCH 20/21] Fix mismatching Kleene operators --- src/libcore/tests/ascii.rs | 2 +- src/libcore/tests/pattern.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/tests/ascii.rs b/src/libcore/tests/ascii.rs index ec98e0464c9e6..439ed0c81c8b6 100644 --- a/src/libcore/tests/ascii.rs +++ b/src/libcore/tests/ascii.rs @@ -151,7 +151,7 @@ macro_rules! assert_none { stringify!($what), b); } } - )* + )+ }}; ($what:ident, $($str:tt),+,) => (assert_none!($what,$($str),+)) } diff --git a/src/libcore/tests/pattern.rs b/src/libcore/tests/pattern.rs index b78ed0210770f..06c3a78c1698a 100644 --- a/src/libcore/tests/pattern.rs +++ b/src/libcore/tests/pattern.rs @@ -5,7 +5,7 @@ use std::str::pattern::*; macro_rules! search_asserts { ($haystack:expr, $needle:expr, $testname:expr, [$($func:ident),*], $result:expr) => { let mut searcher = $needle.into_searcher($haystack); - let arr = [$( Step::from(searcher.$func()) ),+]; + let arr = [$( Step::from(searcher.$func()) ),*]; assert_eq!(&arr[..], &$result, $testname); } } From e5ede80a9a0ee29344c88ef1a74689b816926644 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Wed, 3 Jul 2019 15:59:40 +0900 Subject: [PATCH 21/21] Fixed document bug, those replaced each other Introduced by #58005 --- src/libcore/str/mod.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 34f2d8917ea47..f7b4e4ea7824f 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -3716,10 +3716,10 @@ impl str { /// /// # Text directionality /// - /// A string is a sequence of bytes. 'Left' in this context means the first - /// position of that byte string; for a language like Arabic or Hebrew - /// which are 'right to left' rather than 'left to right', this will be - /// the _right_ side, not the left. + /// A string is a sequence of bytes. `start` in this context means the first + /// position of that byte string; for a left-to-right language like English or + /// Russian, this will be left side, and for right-to-left languages like + /// like Arabic or Hebrew, this will be the right side. /// /// # Examples /// @@ -3755,10 +3755,10 @@ impl str { /// /// # Text directionality /// - /// A string is a sequence of bytes. 'Right' in this context means the last - /// position of that byte string; for a language like Arabic or Hebrew - /// which are 'right to left' rather than 'left to right', this will be - /// the _left_ side, not the right. + /// A string is a sequence of bytes. `end` in this context means the last + /// position of that byte string; for a left-to-right language like English or + /// Russian, this will be right side, and for right-to-left languages like + /// like Arabic or Hebrew, this will be the left side. /// /// # Examples /// @@ -3804,10 +3804,10 @@ impl str { /// /// # Text directionality /// - /// A string is a sequence of bytes. `start` in this context means the first - /// position of that byte string; for a left-to-right language like English or - /// Russian, this will be left side, and for right-to-left languages like - /// like Arabic or Hebrew, this will be the right side. + /// A string is a sequence of bytes. 'Left' in this context means the first + /// position of that byte string; for a language like Arabic or Hebrew + /// which are 'right to left' rather than 'left to right', this will be + /// the _right_ side, not the left. /// /// # Examples /// @@ -3840,10 +3840,10 @@ impl str { /// /// # Text directionality /// - /// A string is a sequence of bytes. `end` in this context means the last - /// position of that byte string; for a left-to-right language like English or - /// Russian, this will be right side, and for right-to-left languages like - /// like Arabic or Hebrew, this will be the left side. + /// A string is a sequence of bytes. 'Right' in this context means the last + /// position of that byte string; for a language like Arabic or Hebrew + /// which are 'right to left' rather than 'left to right', this will be + /// the _left_ side, not the right. /// /// # Examples ///