From eba93c3a0f7cf8a0b7447ab22081ccd20824d9e6 Mon Sep 17 00:00:00 2001 From: arthurprs Date: Sat, 29 Oct 2016 23:12:12 +0200 Subject: Don't reuse RandomState seeds --- src/libstd/collections/hash/map.rs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index fb8a0c3c265..ece51d6d826 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -11,6 +11,7 @@ use self::Entry::*; use self::VacantEntryState::*; +use cell::Cell; use borrow::Borrow; use cmp::max; use fmt::{self, Debug}; @@ -2049,24 +2050,21 @@ impl RandomState { // many hash maps are created on a thread. To solve this performance // trap we cache the first set of randomly generated keys per-thread. // - // In doing this, however, we lose the property that all hash maps have - // nondeterministic iteration order as all of those created on the same - // thread would have the same hash keys. This property has been nice in - // the past as it allows for maximal flexibility in the implementation - // of `HashMap` itself. - // - // The constraint here (if there even is one) is just that maps created - // on the same thread have the same iteration order, and that *may* be - // relied upon even though it is not a documented guarantee at all of - // the `HashMap` type. In any case we've decided that this is reasonable - // for now, so caching keys thread-locally seems fine. - thread_local!(static KEYS: (u64, u64) = { + // Later in #36481 it was discovered that exposing a deterministic + // iteration order allows a form of DOS attack. To counter that we + // increment one of the seeds on every RandomState creation, giving + // every corresponding HashMap a different iteration order. + thread_local!(static KEYS: Cell<(u64, u64)> = { let r = rand::OsRng::new(); let mut r = r.expect("failed to create an OS RNG"); - (r.gen(), r.gen()) + Cell::new((r.gen(), r.gen())) }); - KEYS.with(|&(k0, k1)| RandomState { k0: k0, k1: k1 }) + KEYS.with(|keys| { + let (k0, k1) = keys.get(); + keys.set((k0.wrapping_add(1), k1)); + RandomState { k0: k0, k1: k1 } + }) } } -- cgit 1.4.1-3-g733a5 From 99234bbe9e9f89dcfdf28b9ee53fbcece5f19abb Mon Sep 17 00:00:00 2001 From: Mark-Simulacrum Date: Tue, 1 Nov 2016 19:19:33 -0600 Subject: Add a new non-heap allocated variant to io::Error's representation. Implement From for io::Error, intended for use with errors that should never be exposed to the user. --- src/libstd/io/error.rs | 69 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 21 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/io/error.rs b/src/libstd/io/error.rs index ddf0030858e..659c8aa5aea 100644 --- a/src/libstd/io/error.rs +++ b/src/libstd/io/error.rs @@ -12,6 +12,7 @@ use error; use fmt; use result; use sys; +use convert::From; /// A specialized [`Result`](../result/enum.Result.html) type for I/O /// operations. @@ -62,6 +63,7 @@ pub struct Error { enum Repr { Os(i32), + Simple(ErrorKind), Custom(Box), } @@ -171,6 +173,43 @@ pub enum ErrorKind { __Nonexhaustive, } +impl ErrorKind { + fn as_str(&self) -> &'static str { + match *self { + ErrorKind::NotFound => "entity not found", + ErrorKind::PermissionDenied => "permission denied", + ErrorKind::ConnectionRefused => "connection refused", + ErrorKind::ConnectionReset => "connection reset", + ErrorKind::ConnectionAborted => "connection aborted", + ErrorKind::NotConnected => "not connected", + ErrorKind::AddrInUse => "address in use", + ErrorKind::AddrNotAvailable => "address not available", + ErrorKind::BrokenPipe => "broken pipe", + ErrorKind::AlreadyExists => "entity already exists", + ErrorKind::WouldBlock => "operation would block", + ErrorKind::InvalidInput => "invalid input parameter", + ErrorKind::InvalidData => "invalid data", + ErrorKind::TimedOut => "timed out", + ErrorKind::WriteZero => "write zero", + ErrorKind::Interrupted => "operation interrupted", + ErrorKind::Other => "other os error", + ErrorKind::UnexpectedEof => "unexpected end of file", + ErrorKind::__Nonexhaustive => unreachable!() + } + } +} + +/// Intended for use for errors not exposed to the user, where allocating onto +/// the heap (for normal construction via Error::new) is too costly. +#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] +impl From for Error { + fn from(kind: ErrorKind) -> Error { + Error { + repr: Repr::Simple(kind) + } + } +} + impl Error { /// Creates a new I/O error from a known kind of error as well as an /// arbitrary error payload. @@ -285,6 +324,7 @@ impl Error { match self.repr { Repr::Os(i) => Some(i), Repr::Custom(..) => None, + Repr::Simple(..) => None, } } @@ -317,6 +357,7 @@ impl Error { pub fn get_ref(&self) -> Option<&(error::Error+Send+Sync+'static)> { match self.repr { Repr::Os(..) => None, + Repr::Simple(..) => None, Repr::Custom(ref c) => Some(&*c.error), } } @@ -387,6 +428,7 @@ impl Error { pub fn get_mut(&mut self) -> Option<&mut (error::Error+Send+Sync+'static)> { match self.repr { Repr::Os(..) => None, + Repr::Simple(..) => None, Repr::Custom(ref mut c) => Some(&mut *c.error), } } @@ -420,6 +462,7 @@ impl Error { pub fn into_inner(self) -> Option> { match self.repr { Repr::Os(..) => None, + Repr::Simple(..) => None, Repr::Custom(c) => Some(c.error) } } @@ -447,6 +490,7 @@ impl Error { match self.repr { Repr::Os(code) => sys::decode_error_kind(code), Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, } } } @@ -458,6 +502,7 @@ impl fmt::Debug for Repr { fmt.debug_struct("Os").field("code", code) .field("message", &sys::os::error_string(*code)).finish(), Repr::Custom(ref c) => fmt.debug_tuple("Custom").field(c).finish(), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), } } } @@ -471,6 +516,7 @@ impl fmt::Display for Error { write!(fmt, "{} (os error {})", detail, code) } Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), } } } @@ -479,27 +525,7 @@ impl fmt::Display for Error { impl error::Error for Error { fn description(&self) -> &str { match self.repr { - Repr::Os(..) => match self.kind() { - ErrorKind::NotFound => "entity not found", - ErrorKind::PermissionDenied => "permission denied", - ErrorKind::ConnectionRefused => "connection refused", - ErrorKind::ConnectionReset => "connection reset", - ErrorKind::ConnectionAborted => "connection aborted", - ErrorKind::NotConnected => "not connected", - ErrorKind::AddrInUse => "address in use", - ErrorKind::AddrNotAvailable => "address not available", - ErrorKind::BrokenPipe => "broken pipe", - ErrorKind::AlreadyExists => "entity already exists", - ErrorKind::WouldBlock => "operation would block", - ErrorKind::InvalidInput => "invalid input parameter", - ErrorKind::InvalidData => "invalid data", - ErrorKind::TimedOut => "timed out", - ErrorKind::WriteZero => "write zero", - ErrorKind::Interrupted => "operation interrupted", - ErrorKind::Other => "other os error", - ErrorKind::UnexpectedEof => "unexpected end of file", - ErrorKind::__Nonexhaustive => unreachable!() - }, + Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), Repr::Custom(ref c) => c.error.description(), } } @@ -507,6 +533,7 @@ impl error::Error for Error { fn cause(&self) -> Option<&error::Error> { match self.repr { Repr::Os(..) => None, + Repr::Simple(..) => None, Repr::Custom(ref c) => c.error.cause(), } } -- cgit 1.4.1-3-g733a5 From 942f909c1f6d2d203661831366e828ef030588c6 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 2 Nov 2016 19:08:10 +0100 Subject: Add missing urls for ErrorKind's variants --- src/libstd/io/error.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/io/error.rs b/src/libstd/io/error.rs index ddf0030858e..54372d91c89 100644 --- a/src/libstd/io/error.rs +++ b/src/libstd/io/error.rs @@ -124,23 +124,28 @@ pub enum ErrorKind { InvalidInput, /// Data not valid for the operation were encountered. /// - /// Unlike `InvalidInput`, this typically means that the operation + /// Unlike [`InvalidInput`], this typically means that the operation /// parameters were valid, however the error was caused by malformed /// input data. /// /// For example, a function that reads a file into a string will error with /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput #[stable(feature = "io_invalid_data", since = "1.2.0")] InvalidData, /// The I/O operation's timeout expired, causing it to be canceled. #[stable(feature = "rust1", since = "1.0.0")] TimedOut, /// An error returned when an operation could not be completed because a - /// call to `write` returned `Ok(0)`. + /// call to [`write()`] returned [`Ok(0)`]. /// /// This typically means that an operation could only succeed if it wrote a /// particular number of bytes but only a smaller number of bytes could be /// written. + /// + /// [`write()`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html #[stable(feature = "rust1", since = "1.0.0")] WriteZero, /// This operation was interrupted. -- cgit 1.4.1-3-g733a5 From 74bb5945635b5aaacd238632932baaa294694ce3 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 15 Sep 2016 00:51:46 +0300 Subject: Stabilize `..` in tuple (struct) patterns --- src/doc/reference.md | 2 -- src/librustc/lib.rs | 2 +- src/librustc_borrowck/lib.rs | 2 +- src/librustc_const_eval/lib.rs | 2 +- src/librustc_driver/lib.rs | 2 +- src/librustc_incremental/lib.rs | 2 +- src/librustc_lint/lib.rs | 3 +-- src/librustc_metadata/lib.rs | 2 +- src/librustc_mir/lib.rs | 2 +- src/librustc_passes/lib.rs | 2 +- src/librustc_privacy/lib.rs | 2 +- src/librustc_resolve/lib.rs | 2 +- src/librustc_save_analysis/lib.rs | 2 +- src/librustc_trans/lib.rs | 2 +- src/librustc_typeck/lib.rs | 2 +- src/librustdoc/lib.rs | 2 +- src/libstd/lib.rs | 2 +- src/libsyntax/feature_gate.rs | 17 ++--------------- src/libsyntax/lib.rs | 2 +- src/libsyntax_ext/lib.rs | 2 +- .../compile-fail-fulldeps/auxiliary/macro_crate_test.rs | 1 - src/test/compile-fail/pat-tuple-bad-type.rs | 2 -- src/test/compile-fail/pat-tuple-feature-gate.rs | 17 ----------------- src/test/compile-fail/pat-tuple-overfield.rs | 2 -- src/test/run-make/save-analysis/foo.rs | 1 - .../auxiliary/custom_derive_plugin_attr.rs | 1 - .../run-pass-fulldeps/auxiliary/macro_crate_test.rs | 1 - src/test/run-pass/pat-tuple-1.rs | 2 -- src/test/run-pass/pat-tuple-2.rs | 2 -- src/test/run-pass/pat-tuple-3.rs | 2 -- src/test/run-pass/pat-tuple-4.rs | 2 -- src/test/run-pass/pat-tuple-5.rs | 2 -- src/test/run-pass/pat-tuple-6.rs | 2 -- 33 files changed, 20 insertions(+), 73 deletions(-) delete mode 100644 src/test/compile-fail/pat-tuple-feature-gate.rs (limited to 'src/libstd') diff --git a/src/doc/reference.md b/src/doc/reference.md index 4838ecd2d42..563d0f5d957 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -2479,8 +2479,6 @@ The currently implemented features of the reference compiler are: * - `abi_vectorcall` - Allows the usage of the vectorcall calling convention (e.g. `extern "vectorcall" func fn_();`) -* - `dotdot_in_tuple_patterns` - Allows `..` in tuple (struct) patterns. - * - `abi_sysv64` - Allows the usage of the system V AMD64 calling convention (e.g. `extern "sysv64" func fn_();`) diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index d17402d2134..fa49e5c7289 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -31,7 +31,7 @@ #![feature(conservative_impl_trait)] #![feature(const_fn)] #![feature(core_intrinsics)] -#![feature(dotdot_in_tuple_patterns)] +#![cfg_attr(stage0, feature(dotdot_in_tuple_patterns))] #![feature(enumset)] #![feature(libc)] #![feature(nonzero)] diff --git a/src/librustc_borrowck/lib.rs b/src/librustc_borrowck/lib.rs index da899714e93..2cd709dbd36 100644 --- a/src/librustc_borrowck/lib.rs +++ b/src/librustc_borrowck/lib.rs @@ -19,7 +19,7 @@ #![allow(non_camel_case_types)] -#![feature(dotdot_in_tuple_patterns)] +#![cfg_attr(stage0, feature(dotdot_in_tuple_patterns))] #![feature(quote)] #![feature(rustc_diagnostic_macros)] #![feature(rustc_private)] diff --git a/src/librustc_const_eval/lib.rs b/src/librustc_const_eval/lib.rs index 1a07ece044f..3fa60f86c98 100644 --- a/src/librustc_const_eval/lib.rs +++ b/src/librustc_const_eval/lib.rs @@ -22,7 +22,7 @@ html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/")] -#![feature(dotdot_in_tuple_patterns)] +#![cfg_attr(stage0, feature(dotdot_in_tuple_patterns))] #![feature(rustc_private)] #![feature(staged_api)] #![feature(rustc_diagnostic_macros)] diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index cb78baa12a6..6ddbce7dc72 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -24,7 +24,7 @@ #![cfg_attr(not(stage0), deny(warnings))] #![feature(box_syntax)] -#![feature(dotdot_in_tuple_patterns)] +#![cfg_attr(stage0, feature(dotdot_in_tuple_patterns))] #![feature(libc)] #![feature(quote)] #![feature(rustc_diagnostic_macros)] diff --git a/src/librustc_incremental/lib.rs b/src/librustc_incremental/lib.rs index 577e50699bf..4a5a6b9bea9 100644 --- a/src/librustc_incremental/lib.rs +++ b/src/librustc_incremental/lib.rs @@ -19,7 +19,7 @@ html_root_url = "https://doc.rust-lang.org/nightly/")] #![cfg_attr(not(stage0), deny(warnings))] -#![feature(dotdot_in_tuple_patterns)] +#![cfg_attr(stage0, feature(dotdot_in_tuple_patterns))] #![cfg_attr(stage0, feature(question_mark))] #![feature(rustc_private)] #![feature(staged_api)] diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 6f114e09a6c..42a893913b6 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -31,13 +31,12 @@ #![cfg_attr(test, feature(test))] #![feature(box_patterns)] #![feature(box_syntax)] -#![feature(dotdot_in_tuple_patterns)] +#![cfg_attr(stage0, feature(dotdot_in_tuple_patterns))] #![feature(quote)] #![feature(rustc_diagnostic_macros)] #![feature(rustc_private)] #![feature(slice_patterns)] #![feature(staged_api)] -#![feature(dotdot_in_tuple_patterns)] #[macro_use] extern crate syntax; diff --git a/src/librustc_metadata/lib.rs b/src/librustc_metadata/lib.rs index ef81dbd7f29..2fd40181d7c 100644 --- a/src/librustc_metadata/lib.rs +++ b/src/librustc_metadata/lib.rs @@ -20,7 +20,7 @@ #![feature(box_patterns)] #![feature(conservative_impl_trait)] #![feature(core_intrinsics)] -#![feature(dotdot_in_tuple_patterns)] +#![cfg_attr(stage0, feature(dotdot_in_tuple_patterns))] #![feature(proc_macro_internals)] #![feature(proc_macro_lib)] #![cfg_attr(stage0, feature(question_mark))] diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index 02f15602d70..aa56daf8889 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -22,7 +22,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment! #![feature(associated_consts)] #![feature(box_patterns)] -#![feature(dotdot_in_tuple_patterns)] +#![cfg_attr(stage0, feature(dotdot_in_tuple_patterns))] #![feature(rustc_diagnostic_macros)] #![feature(rustc_private)] #![feature(staged_api)] diff --git a/src/librustc_passes/lib.rs b/src/librustc_passes/lib.rs index a4657251c9c..3cc7e32ed1f 100644 --- a/src/librustc_passes/lib.rs +++ b/src/librustc_passes/lib.rs @@ -23,7 +23,7 @@ html_root_url = "https://doc.rust-lang.org/nightly/")] #![cfg_attr(not(stage0), deny(warnings))] -#![feature(dotdot_in_tuple_patterns)] +#![cfg_attr(stage0, feature(dotdot_in_tuple_patterns))] #![feature(rustc_diagnostic_macros)] #![feature(staged_api)] #![feature(rustc_private)] diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 77b3e76fc54..2f77d29260b 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -17,7 +17,7 @@ html_root_url = "https://doc.rust-lang.org/nightly/")] #![cfg_attr(not(stage0), deny(warnings))] -#![feature(dotdot_in_tuple_patterns)] +#![cfg_attr(stage0, feature(dotdot_in_tuple_patterns))] #![feature(rustc_diagnostic_macros)] #![feature(rustc_private)] #![feature(staged_api)] diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 0b382fcbfdd..a52d59fce16 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -19,7 +19,7 @@ #![feature(associated_consts)] #![feature(borrow_state)] -#![feature(dotdot_in_tuple_patterns)] +#![cfg_attr(stage0, feature(dotdot_in_tuple_patterns))] #![feature(rustc_diagnostic_macros)] #![feature(rustc_private)] #![feature(staged_api)] diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 15c74f2ed6a..af266b3617c 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -18,7 +18,7 @@ #![cfg_attr(not(stage0), deny(warnings))] #![feature(custom_attribute)] -#![feature(dotdot_in_tuple_patterns)] +#![cfg_attr(stage0, feature(dotdot_in_tuple_patterns))] #![allow(unused_attributes)] #![feature(rustc_private)] #![feature(staged_api)] diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index 07acc54962b..1671e79daa4 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -28,7 +28,7 @@ #![feature(cell_extras)] #![feature(const_fn)] #![feature(custom_attribute)] -#![feature(dotdot_in_tuple_patterns)] +#![cfg_attr(stage0, feature(dotdot_in_tuple_patterns))] #![allow(unused_attributes)] #![feature(libc)] #![feature(quote)] diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index d636baca248..ddead08aeab 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -77,7 +77,7 @@ This API is completely unstable and subject to change. #![feature(box_patterns)] #![feature(box_syntax)] #![feature(conservative_impl_trait)] -#![feature(dotdot_in_tuple_patterns)] +#![cfg_attr(stage0, feature(dotdot_in_tuple_patterns))] #![feature(quote)] #![feature(rustc_diagnostic_macros)] #![feature(rustc_private)] diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index cf5e8e5e34a..ee395e0616b 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -20,7 +20,7 @@ #![feature(box_patterns)] #![feature(box_syntax)] -#![feature(dotdot_in_tuple_patterns)] +#![cfg_attr(stage0, feature(dotdot_in_tuple_patterns))] #![feature(libc)] #![feature(rustc_private)] #![feature(set_stdio)] diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 8d973fc1ade..12dbbe3c469 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -249,7 +249,7 @@ #![feature(const_fn)] #![feature(core_float)] #![feature(core_intrinsics)] -#![feature(dotdot_in_tuple_patterns)] +#![cfg_attr(stage0, feature(dotdot_in_tuple_patterns))] #![feature(dropck_parametricity)] #![feature(float_extras)] #![feature(float_from_str_radix)] diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 129e4a82338..316f287f1cb 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -268,9 +268,6 @@ declare_features! ( // Allows cfg(target_has_atomic = "..."). (active, cfg_target_has_atomic, "1.9.0", Some(32976)), - // Allows `..` in tuple (struct) patterns - (active, dotdot_in_tuple_patterns, "1.10.0", Some(33627)), - // Allows `impl Trait` in function return types. (active, conservative_impl_trait, "1.12.0", Some(34511)), @@ -353,6 +350,8 @@ declare_features! ( (accepted, deprecated, "1.9.0", Some(29935)), // `expr?` (accepted, question_mark, "1.14.0", Some(31436)), + // Allows `..` in tuple (struct) patterns + (accepted, dotdot_in_tuple_patterns, "1.14.0", Some(33627)), ); // (changing above list without updating src/doc/reference.md makes @cmr sad) @@ -1190,18 +1189,6 @@ impl<'a> Visitor for PostExpansionVisitor<'a> { pattern.span, "box pattern syntax is experimental"); } - PatKind::Tuple(_, ddpos) - if ddpos.is_some() => { - gate_feature_post!(&self, dotdot_in_tuple_patterns, - pattern.span, - "`..` in tuple patterns is experimental"); - } - PatKind::TupleStruct(_, ref fields, ddpos) - if ddpos.is_some() && !fields.is_empty() => { - gate_feature_post!(&self, dotdot_in_tuple_patterns, - pattern.span, - "`..` in tuple struct patterns is experimental"); - } PatKind::TupleStruct(_, ref fields, ddpos) if ddpos.is_none() && fields.is_empty() => { gate_feature_post!(&self, relaxed_adts, pattern.span, diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index b86e508d899..feed400897c 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -34,7 +34,7 @@ #![cfg_attr(stage0, feature(question_mark))] #![feature(rustc_diagnostic_macros)] #![feature(specialization)] -#![feature(dotdot_in_tuple_patterns)] +#![cfg_attr(stage0, feature(dotdot_in_tuple_patterns))] extern crate core; extern crate serialize; diff --git a/src/libsyntax_ext/lib.rs b/src/libsyntax_ext/lib.rs index f336b26ae41..e1542c9e466 100644 --- a/src/libsyntax_ext/lib.rs +++ b/src/libsyntax_ext/lib.rs @@ -19,7 +19,7 @@ html_root_url = "https://doc.rust-lang.org/nightly/")] #![cfg_attr(not(stage0), deny(warnings))] -#![feature(dotdot_in_tuple_patterns)] +#![cfg_attr(stage0, feature(dotdot_in_tuple_patterns))] #![feature(proc_macro_lib)] #![feature(proc_macro_internals)] #![feature(rustc_private)] diff --git a/src/test/compile-fail-fulldeps/auxiliary/macro_crate_test.rs b/src/test/compile-fail-fulldeps/auxiliary/macro_crate_test.rs index 60697cc8b6a..409f9dbf03c 100644 --- a/src/test/compile-fail-fulldeps/auxiliary/macro_crate_test.rs +++ b/src/test/compile-fail-fulldeps/auxiliary/macro_crate_test.rs @@ -10,7 +10,6 @@ // force-host -#![feature(dotdot_in_tuple_patterns)] #![feature(plugin_registrar, quote, rustc_private)] extern crate syntax; diff --git a/src/test/compile-fail/pat-tuple-bad-type.rs b/src/test/compile-fail/pat-tuple-bad-type.rs index 0d50a30dd05..fd4ab5d2531 100644 --- a/src/test/compile-fail/pat-tuple-bad-type.rs +++ b/src/test/compile-fail/pat-tuple-bad-type.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(dotdot_in_tuple_patterns)] - fn main() { let x; diff --git a/src/test/compile-fail/pat-tuple-feature-gate.rs b/src/test/compile-fail/pat-tuple-feature-gate.rs deleted file mode 100644 index 55ca05bdef3..00000000000 --- a/src/test/compile-fail/pat-tuple-feature-gate.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() { - match 0 { - (..) => {} //~ ERROR `..` in tuple patterns is experimental - (pat, ..) => {} //~ ERROR `..` in tuple patterns is experimental - S(pat, ..) => {} //~ ERROR `..` in tuple struct patterns is experimental - } -} diff --git a/src/test/compile-fail/pat-tuple-overfield.rs b/src/test/compile-fail/pat-tuple-overfield.rs index 069c1dc0aea..851fa5c5be6 100644 --- a/src/test/compile-fail/pat-tuple-overfield.rs +++ b/src/test/compile-fail/pat-tuple-overfield.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(dotdot_in_tuple_patterns)] - struct S(u8, u8, u8); fn main() { diff --git a/src/test/run-make/save-analysis/foo.rs b/src/test/run-make/save-analysis/foo.rs index 3f36ebe6492..e9ed897bf30 100644 --- a/src/test/run-make/save-analysis/foo.rs +++ b/src/test/run-make/save-analysis/foo.rs @@ -10,7 +10,6 @@ #![ crate_name = "test" ] #![feature(box_syntax)] -#![feature(dotdot_in_tuple_patterns)] #![feature(rustc_private)] extern crate graphviz; diff --git a/src/test/run-pass-fulldeps/auxiliary/custom_derive_plugin_attr.rs b/src/test/run-pass-fulldeps/auxiliary/custom_derive_plugin_attr.rs index 5df95ba5fac..6b58fee1575 100644 --- a/src/test/run-pass-fulldeps/auxiliary/custom_derive_plugin_attr.rs +++ b/src/test/run-pass-fulldeps/auxiliary/custom_derive_plugin_attr.rs @@ -12,7 +12,6 @@ #![feature(plugin_registrar)] #![feature(box_syntax)] -#![feature(dotdot_in_tuple_patterns)] #![feature(rustc_private)] extern crate syntax; diff --git a/src/test/run-pass-fulldeps/auxiliary/macro_crate_test.rs b/src/test/run-pass-fulldeps/auxiliary/macro_crate_test.rs index 15ec0ccae8f..7257444ee87 100644 --- a/src/test/run-pass-fulldeps/auxiliary/macro_crate_test.rs +++ b/src/test/run-pass-fulldeps/auxiliary/macro_crate_test.rs @@ -10,7 +10,6 @@ // force-host -#![feature(dotdot_in_tuple_patterns)] #![feature(plugin_registrar, quote, rustc_private)] extern crate syntax; diff --git a/src/test/run-pass/pat-tuple-1.rs b/src/test/run-pass/pat-tuple-1.rs index c3796210a8e..45a9a2b303c 100644 --- a/src/test/run-pass/pat-tuple-1.rs +++ b/src/test/run-pass/pat-tuple-1.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(dotdot_in_tuple_patterns)] - fn tuple() { let x = (1, 2, 3); match x { diff --git a/src/test/run-pass/pat-tuple-2.rs b/src/test/run-pass/pat-tuple-2.rs index 881e96a9d78..ee60d1c01cf 100644 --- a/src/test/run-pass/pat-tuple-2.rs +++ b/src/test/run-pass/pat-tuple-2.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(dotdot_in_tuple_patterns)] - fn tuple() { let x = (1,); match x { diff --git a/src/test/run-pass/pat-tuple-3.rs b/src/test/run-pass/pat-tuple-3.rs index 94d33d41899..7a46c1deb59 100644 --- a/src/test/run-pass/pat-tuple-3.rs +++ b/src/test/run-pass/pat-tuple-3.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(dotdot_in_tuple_patterns)] - fn tuple() { let x = (1, 2, 3); let branch = match x { diff --git a/src/test/run-pass/pat-tuple-4.rs b/src/test/run-pass/pat-tuple-4.rs index ffd82fea996..1d75e1e9d14 100644 --- a/src/test/run-pass/pat-tuple-4.rs +++ b/src/test/run-pass/pat-tuple-4.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(dotdot_in_tuple_patterns)] - fn tuple() { let x = (1, 2, 3); match x { diff --git a/src/test/run-pass/pat-tuple-5.rs b/src/test/run-pass/pat-tuple-5.rs index 41c4d02abcb..1192932f13d 100644 --- a/src/test/run-pass/pat-tuple-5.rs +++ b/src/test/run-pass/pat-tuple-5.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(dotdot_in_tuple_patterns)] - fn tuple() { struct S; struct Z; diff --git a/src/test/run-pass/pat-tuple-6.rs b/src/test/run-pass/pat-tuple-6.rs index 6f3f2b3aed5..9d3cd65b455 100644 --- a/src/test/run-pass/pat-tuple-6.rs +++ b/src/test/run-pass/pat-tuple-6.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(dotdot_in_tuple_patterns)] - fn tuple() { let x = (1, 2, 3, 4, 5); match x { -- cgit 1.4.1-3-g733a5 From 3e4bd8843829284a62af22687ee415a66c8207cc Mon Sep 17 00:00:00 2001 From: "leonardo.yvens" Date: Fri, 4 Nov 2016 15:54:08 -0200 Subject: Change Into> for String and Into for PathBuf to From impls --- src/libcollections/string.rs | 8 ++++---- src/libstd/path.rs | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src/libstd') diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 286f06b6fe3..348eb6fb5ff 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -1904,10 +1904,10 @@ impl<'a> FromIterator for Cow<'a, str> { } } -#[stable(feature = "rust1", since = "1.0.0")] -impl Into> for String { - fn into(self) -> Vec { - self.into_bytes() +#[stable(feature = "from_string_for_vec_u8", since = "1.14.0")] +impl From for Vec { + fn from(string : String) -> Vec { + string.into_bytes() } } diff --git a/src/libstd/path.rs b/src/libstd/path.rs index d6a5dfe5518..e8a7951d557 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1172,6 +1172,13 @@ impl From for PathBuf { } } +#[stable(feature = "from_path_buf_for_os_string", since = "1.14.0")] +impl From for OsString { + fn from(path_buf : PathBuf) -> OsString { + path_buf.inner + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl From for PathBuf { fn from(s: String) -> PathBuf { @@ -1282,13 +1289,6 @@ impl AsRef for PathBuf { } } -#[stable(feature = "rust1", since = "1.0.0")] -impl Into for PathBuf { - fn into(self) -> OsString { - self.inner - } -} - /// A slice of a path (akin to [`str`]). /// /// This type supports a number of operations for inspecting a path, including -- cgit 1.4.1-3-g733a5 From fe953dc16ee205ec27a946398f2d3350666962e3 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Fri, 4 Nov 2016 13:01:15 -0700 Subject: std: Track change to cprng syscall signature (Fuchsia) The mx_cprng_draw syscall has changed signature to separate the status and size return values, rather than multiplexing them into a single value with errors interpreted as a negative value. This patch tracks that change. --- src/libstd/sys/unix/rand.rs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/sys/unix/rand.rs b/src/libstd/sys/unix/rand.rs index 3aebb8c18ec..9b1cf6ffd0e 100644 --- a/src/libstd/sys/unix/rand.rs +++ b/src/libstd/sys/unix/rand.rs @@ -350,11 +350,19 @@ mod imp { #[link(name = "magenta")] extern { - fn mx_cprng_draw(buffer: *mut u8, len: usize) -> isize; + fn mx_cprng_draw(buffer: *mut u8, len: usize, actual: *mut usize) -> i32; } - fn getrandom(buf: &mut [u8]) -> isize { - unsafe { mx_cprng_draw(buf.as_mut_ptr(), buf.len()) } + fn getrandom(buf: &mut [u8]) -> Result { + unsafe { + let mut actual = 0; + let status = mx_cprng_draw(buf.as_mut_ptr(), buf.len(), &mut actual); + if status == 0 { + Ok(actual) + } else { + Err(status) + } + } } pub struct OsRng { @@ -381,12 +389,16 @@ mod imp { let mut buf = v; while !buf.is_empty() { let ret = getrandom(buf); - if ret < 0 { - panic!("kernel mx_cprng_draw call failed! (returned {}, buf.len() {})", - ret, buf.len()); + match ret { + Err(err) => { + panic!("kernel mx_cprng_draw call failed! (returned {}, buf.len() {})", + err, buf.len()) + } + Ok(actual) => { + let move_buf = buf; + buf = &mut move_buf[(actual as usize)..]; + } } - let move_buf = buf; - buf = &mut move_buf[(ret as usize)..]; } } } -- cgit 1.4.1-3-g733a5 From 36e6f4be31aff59540f0184dac2cabbd5daf0ac3 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 4 Nov 2016 20:51:57 +0100 Subject: add missing urls on io structs --- src/libstd/io/mod.rs | 27 +++++++++++++++++---------- src/libstd/io/stdio.rs | 3 ++- 2 files changed, 19 insertions(+), 11 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 193f396c0d4..ad9ae5638b6 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -21,7 +21,7 @@ //! of other types, and you can implement them for your types too. As such, //! you'll see a few different types of I/O throughout the documentation in //! this module: [`File`]s, [`TcpStream`]s, and sometimes even [`Vec`]s. For -//! example, `Read` adds a `read()` method, which we can use on `File`s: +//! example, [`Read`] adds a [`read()`] method, which we can use on `File`s: //! //! ``` //! use std::io; @@ -251,6 +251,7 @@ //! [`Lines`]: struct.Lines.html //! [`io::Result`]: type.Result.html //! [`try!`]: ../macro.try.html +//! [`read()`]: trait.Read.html#tymethod.read #![stable(feature = "rust1", since = "1.0.0")] @@ -814,19 +815,23 @@ pub trait Read { /// /// Implementors of the `Write` trait are sometimes called 'writers'. /// -/// Writers are defined by two required methods, `write()` and `flush()`: +/// Writers are defined by two required methods, [`write()`] and [`flush()`]: /// -/// * The `write()` method will attempt to write some data into the object, +/// * The [`write()`] method will attempt to write some data into the object, /// returning how many bytes were successfully written. /// -/// * The `flush()` method is useful for adaptors and explicit buffers +/// * The [`flush()`] method is useful for adaptors and explicit buffers /// themselves for ensuring that all buffered data has been pushed out to the /// 'true sink'. /// /// Writers are intended to be composable with one another. Many implementors -/// throughout `std::io` take and provide types which implement the `Write` +/// throughout [`std::io`] take and provide types which implement the `Write` /// trait. /// +/// [`write()`]: #tymethod.write +/// [`flush()`]: #tymethod.flush +/// [`std::io`]: index.html +/// /// # Examples /// /// ``` @@ -1475,10 +1480,10 @@ impl BufRead for Chain { /// Reader adaptor which limits the bytes read from an underlying reader. /// -/// This struct is generally created by calling [`take()`][take] on a reader. -/// Please see the documentation of `take()` for more details. +/// This struct is generally created by calling [`take()`] on a reader. +/// Please see the documentation of [`take()`] for more details. /// -/// [take]: trait.Read.html#method.take +/// [`take()`]: trait.Read.html#method.take #[stable(feature = "rust1", since = "1.0.0")] pub struct Take { inner: T, @@ -1491,8 +1496,10 @@ impl Take { /// /// # Note /// - /// This instance may reach EOF after reading fewer bytes than indicated by - /// this method if the underlying `Read` instance reaches EOF. + /// This instance may reach `EOF` after reading fewer bytes than indicated by + /// this method if the underlying [`Read`] instance reaches EOF. + /// + /// [`Read`]: ../../std/io/trait.Read.html /// /// # Examples /// diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 1777b79ea1b..e8b812daed8 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -318,10 +318,11 @@ impl<'a> BufRead for StdinLock<'a> { /// /// Each handle shares a global buffer of data to be written to the standard /// output stream. Access is also synchronized via a lock and explicit control -/// over locking is available via the `lock` method. +/// over locking is available via the [`lock()`] method. /// /// Created by the [`io::stdout`] method. /// +/// [`lock()`]: #method.lock /// [`io::stdout`]: fn.stdout.html #[stable(feature = "rust1", since = "1.0.0")] pub struct Stdout { -- cgit 1.4.1-3-g733a5 From 18f5f9960f8db867ce7f716fc0f40b9b65c12a73 Mon Sep 17 00:00:00 2001 From: Oliver Middleton Date: Tue, 8 Nov 2016 16:55:24 +0000 Subject: Slightly optimise CString Avoid a reallocation in CString::from and CStr::to_owned. --- src/libstd/ffi/c_str.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libstd') diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 3ad5b5627d3..d1b8fcd7440 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -686,7 +686,7 @@ impl ToOwned for CStr { type Owned = CString; fn to_owned(&self) -> CString { - unsafe { CString::from_vec_unchecked(self.to_bytes().to_vec()) } + CString { inner: self.to_bytes_with_nul().to_vec().into_boxed_slice() } } } -- cgit 1.4.1-3-g733a5 From 50bfc238169844fff8287efc48ee4da3076b2f78 Mon Sep 17 00:00:00 2001 From: Abhishek Chanda Date: Thu, 27 Oct 2016 15:23:19 +0100 Subject: Clarify that send_to might return an error in certain cases Closes #34202 --- src/libstd/net/udp.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/libstd') diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs index c03ac496adb..559250adac5 100644 --- a/src/libstd/net/udp.rs +++ b/src/libstd/net/udp.rs @@ -67,6 +67,9 @@ impl UdpSocket { /// /// Address type can be any implementor of `ToSocketAddrs` trait. See its /// documentation for concrete examples. + /// This will return an error when the IP version of the local socket + /// does not match that returned from `ToSocketAddrs` + /// See https://github.com/rust-lang/rust/issues/34202 for more details. #[stable(feature = "rust1", since = "1.0.0")] pub fn send_to(&self, buf: &[u8], addr: A) -> io::Result { -- cgit 1.4.1-3-g733a5 From a9349d723d012913de6fdd8624ccd0b0edd9a85c Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Thu, 10 Nov 2016 05:15:56 +0200 Subject: doc: fix typos --- src/libstd/sys/mod.rs | 2 +- src/libstd/sys_common/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/sys/mod.rs b/src/libstd/sys/mod.rs index 84f41a1c535..0c45ab8a887 100644 --- a/src/libstd/sys/mod.rs +++ b/src/libstd/sys/mod.rs @@ -23,7 +23,7 @@ //! integration code in `std::sys_common`. See that module's //! documentation for details. //! -//! In the future it would be desirable for the indepedent +//! In the future it would be desirable for the independent //! implementations of this module to be extracted to their own crates //! that `std` can link to, thus enabling their implementation //! out-of-tree via crate replacement. Though due to the complex diff --git a/src/libstd/sys_common/mod.rs b/src/libstd/sys_common/mod.rs index 1dd9b73e262..fe17d8cb5e5 100644 --- a/src/libstd/sys_common/mod.rs +++ b/src/libstd/sys_common/mod.rs @@ -10,7 +10,7 @@ //! Platform-independent platform abstraction //! -//! This is the platform-independent portion of the standard libraries +//! This is the platform-independent portion of the standard library's //! platform abstraction layer, whereas `std::sys` is the //! platform-specific portion. //! -- cgit 1.4.1-3-g733a5