From 517fce08c56186e060f2b67fc4d85484164f31b4 Mon Sep 17 00:00:00 2001 From: Wesley Moore Date: Sat, 26 Nov 2016 18:15:49 +1100 Subject: [PATCH 01/16] Simplify notes on testing and concurrency --- src/doc/book/testing.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/doc/book/testing.md b/src/doc/book/testing.md index ebeb9923197a9..96cec7295aa9d 100644 --- a/src/doc/book/testing.md +++ b/src/doc/book/testing.md @@ -589,11 +589,10 @@ please see the [Documentation chapter](documentation.html). # Testing and concurrency -One thing that is important to note when writing tests is that they may be run -concurrently using threads. For this reason you should take care that your tests -are written in such a way as to not depend on each-other, or on any shared -state. "Shared state" can also include the environment, such as the current -working directory, or environment variables. +It is important to note that tests are run concurrently using threads. For this +reason, care should be taken to ensure your tests do not depend on each-other, +or on any shared state. "Shared state" can also include the environment, such +as the current working directory, or environment variables. If this is an issue it is possible to control this concurrency, either by setting the environment variable `RUST_TEST_THREADS`, or by passing the argument From 71de148649bd9d2548b55e5d52bd0c8b38ffec44 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 11 Dec 2016 14:11:08 +0300 Subject: [PATCH 02/16] Advertise Vec in LinkedList docs --- src/libcollections/linked_list.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/libcollections/linked_list.rs b/src/libcollections/linked_list.rs index 67f3708a62b91..66a61355d7468 100644 --- a/src/libcollections/linked_list.rs +++ b/src/libcollections/linked_list.rs @@ -10,8 +10,15 @@ //! A doubly-linked list with owned nodes. //! -//! The `LinkedList` allows pushing and popping elements at either end and is thus -//! efficiently usable as a double-ended queue. +//! The `LinkedList` allows pushing and popping elements at either end +//! in constant time. +//! +//! Almost always it is better to use `Vec` or [`VecDeque`] instead of +//! [`LinkedList`]. In general, array-based containers are faster, +//! more memory efficient and make better use of CPU cache. +//! +//! [`LinkedList`]: ../linked_list/struct.LinkedList.html +//! [`VecDeque`]: ../vec_deque/struct.VecDeque.html #![stable(feature = "rust1", since = "1.0.0")] @@ -27,7 +34,14 @@ use core::ptr::{self, Shared}; use super::SpecExtend; -/// A doubly-linked list. +/// A doubly-linked list with owned nodes. +/// +/// The `LinkedList` allows pushing and popping elements at either end +/// in constant time. +/// +/// Almost always it is better to use `Vec` or `VecDeque` instead of +/// `LinkedList`. In general, array-based containers are faster, +/// more memory efficient and make better use of CPU cache. #[stable(feature = "rust1", since = "1.0.0")] pub struct LinkedList { head: Option>>, From 17dd0e5cd9debdaeec264f2574eaa609bce07b0c Mon Sep 17 00:00:00 2001 From: Clar Charr Date: Mon, 19 Dec 2016 18:00:29 -0500 Subject: [PATCH 03/16] Don't @import normalize.css. --- src/librustdoc/html/layout.rs | 1 + src/librustdoc/html/static/rustdoc.css | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index 5353642e29425..06a816412969b 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -46,6 +46,7 @@ r##" {title} + {css_extension} diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 15912b41d59c0..ce7c6acdf47f9 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -1,5 +1,3 @@ -@import "normalize.css"; - /** * Copyright 2013 The Rust Project Developers. See the COPYRIGHT * file at the top-level directory of this distribution and at From 941b6b0c0cfde5e253e799c7db9381263ca9cdb8 Mon Sep 17 00:00:00 2001 From: QuietMisdreavus Date: Tue, 20 Dec 2016 11:33:34 -0600 Subject: [PATCH 04/16] rustdoc: properly calculate line length for impl where clauses --- src/librustdoc/html/format.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 6dc6e80dae0b8..796a3a93068c8 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -207,7 +207,7 @@ impl<'a> fmt::Display for WhereClause<'a> { if !f.alternate() { clause.push_str(""); let plain = format!("{:#}", self); - if plain.len() > 80 { + if plain.len() + pad > 80 { //break it onto its own line regardless, but make sure method impls and trait //blocks keep their fixed padding (2 and 9, respectively) let padding = if pad > 10 { From 78f630f854781ab11d7f9620edf66c8ec68a7323 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Tue, 20 Dec 2016 16:54:22 -0500 Subject: [PATCH 05/16] ICH: Add test cases for inherent impls. --- src/test/incremental/hashes/inherent_impls.rs | 410 +++++++++++++++++- 1 file changed, 409 insertions(+), 1 deletion(-) diff --git a/src/test/incremental/hashes/inherent_impls.rs b/src/test/incremental/hashes/inherent_impls.rs index f7a390e874509..5c37bc133596d 100644 --- a/src/test/incremental/hashes/inherent_impls.rs +++ b/src/test/incremental/hashes/inherent_impls.rs @@ -107,7 +107,7 @@ impl Foo { pub fn method_selfness(&self) { } } -// Change Method Selfmutness ----------------------------------------------------------- +// Change Method Selfmutness --------------------------------------------------- #[cfg(cfail1)] impl Foo { pub fn method_selfmutness(&self) { } @@ -126,3 +126,411 @@ impl Foo { pub fn method_selfmutness(&mut self) { } } + + +// Add Method To Impl ---------------------------------------------------------- +#[cfg(cfail1)] +impl Foo { + pub fn add_method_to_impl1(&self) { } +} + +#[cfg(not(cfail1))] +#[rustc_dirty(label="Hir", cfg="cfail2")] +#[rustc_clean(label="Hir", cfg="cfail3")] +#[rustc_metadata_dirty(cfg="cfail2")] +#[rustc_metadata_clean(cfg="cfail3")] +impl Foo { + #[rustc_clean(label="Hir", cfg="cfail2")] + #[rustc_clean(label="Hir", cfg="cfail3")] + #[rustc_metadata_clean(cfg="cfail2")] + #[rustc_metadata_clean(cfg="cfail3")] + pub fn add_method_to_impl1(&self) { } + + #[rustc_dirty(label="Hir", cfg="cfail2")] + #[rustc_clean(label="Hir", cfg="cfail3")] + #[rustc_metadata_dirty(cfg="cfail2")] + #[rustc_metadata_clean(cfg="cfail3")] + pub fn add_method_to_impl2(&self) { } +} + + + +// Add Method Parameter -------------------------------------------------------- +#[cfg(cfail1)] +impl Foo { + pub fn add_method_parameter(&self) { } +} + +#[cfg(not(cfail1))] +#[rustc_clean(label="Hir", cfg="cfail2")] +#[rustc_clean(label="Hir", cfg="cfail3")] +#[rustc_metadata_clean(cfg="cfail2")] +#[rustc_metadata_clean(cfg="cfail3")] +impl Foo { + #[rustc_dirty(label="Hir", cfg="cfail2")] + #[rustc_clean(label="Hir", cfg="cfail3")] + #[rustc_metadata_dirty(cfg="cfail2")] + #[rustc_metadata_clean(cfg="cfail3")] + pub fn add_method_parameter(&self, _: i32) { } +} + + + +// Change Method Parameter Name ------------------------------------------------ +#[cfg(cfail1)] +impl Foo { + pub fn change_method_parameter_name(&self, a: i64) { } +} + +#[cfg(not(cfail1))] +#[rustc_clean(label="Hir", cfg="cfail2")] +#[rustc_clean(label="Hir", cfg="cfail3")] +#[rustc_metadata_clean(cfg="cfail2")] +#[rustc_metadata_clean(cfg="cfail3")] +impl Foo { + #[rustc_dirty(label="Hir", cfg="cfail2")] + #[rustc_clean(label="Hir", cfg="cfail3")] + #[rustc_metadata_dirty(cfg="cfail2")] + #[rustc_metadata_clean(cfg="cfail3")] + pub fn change_method_parameter_name(&self, b: i64) { } +} + + + +// Change Method Return Type --------------------------------------------------- +#[cfg(cfail1)] +impl Foo { + pub fn change_method_return_type(&self) -> u16 { 0 } +} + +#[cfg(not(cfail1))] +#[rustc_clean(label="Hir", cfg="cfail2")] +#[rustc_clean(label="Hir", cfg="cfail3")] +#[rustc_metadata_clean(cfg="cfail2")] +#[rustc_metadata_clean(cfg="cfail3")] +impl Foo { + #[rustc_dirty(label="Hir", cfg="cfail2")] + #[rustc_clean(label="Hir", cfg="cfail3")] + #[rustc_metadata_dirty(cfg="cfail2")] + #[rustc_metadata_clean(cfg="cfail3")] + pub fn change_method_return_type(&self) -> u8 { 0 } +} + + + +// Make Method #[inline] ------------------------------------------------------- +#[cfg(cfail1)] +impl Foo { + pub fn make_method_inline(&self) -> u8 { 0 } +} + +#[cfg(not(cfail1))] +#[rustc_clean(label="Hir", cfg="cfail2")] +#[rustc_clean(label="Hir", cfg="cfail3")] +#[rustc_metadata_clean(cfg="cfail2")] +#[rustc_metadata_clean(cfg="cfail3")] +impl Foo { + #[rustc_dirty(label="Hir", cfg="cfail2")] + #[rustc_clean(label="Hir", cfg="cfail3")] + #[rustc_metadata_dirty(cfg="cfail2")] + #[rustc_metadata_clean(cfg="cfail3")] + #[inline] + pub fn make_method_inline(&self) -> u8 { 0 } +} + + + +// Change order of parameters ------------------------------------------------- +#[cfg(cfail1)] +impl Foo { + pub fn change_method_parameter_order(&self, a: i64, b: i64) { } +} + +#[cfg(not(cfail1))] +#[rustc_clean(label="Hir", cfg="cfail2")] +#[rustc_clean(label="Hir", cfg="cfail3")] +#[rustc_metadata_clean(cfg="cfail2")] +#[rustc_metadata_clean(cfg="cfail3")] +impl Foo { + #[rustc_dirty(label="Hir", cfg="cfail2")] + #[rustc_clean(label="Hir", cfg="cfail3")] + #[rustc_metadata_dirty(cfg="cfail2")] + #[rustc_metadata_clean(cfg="cfail3")] + pub fn change_method_parameter_order(&self, b: i64, a: i64) { } +} + + + +// Make method unsafe ---------------------------------------------------------- +#[cfg(cfail1)] +impl Foo { + pub fn make_method_unsafe(&self) { } +} + +#[cfg(not(cfail1))] +#[rustc_clean(label="Hir", cfg="cfail2")] +#[rustc_clean(label="Hir", cfg="cfail3")] +#[rustc_metadata_clean(cfg="cfail2")] +#[rustc_metadata_clean(cfg="cfail3")] +impl Foo { + #[rustc_dirty(label="Hir", cfg="cfail2")] + #[rustc_clean(label="Hir", cfg="cfail3")] + #[rustc_metadata_dirty(cfg="cfail2")] + #[rustc_metadata_clean(cfg="cfail3")] + pub unsafe fn make_method_unsafe(&self) { } +} + + + +// Make method extern ---------------------------------------------------------- +#[cfg(cfail1)] +impl Foo { + pub fn make_method_extern(&self) { } +} + +#[cfg(not(cfail1))] +#[rustc_clean(label="Hir", cfg="cfail2")] +#[rustc_clean(label="Hir", cfg="cfail3")] +#[rustc_metadata_clean(cfg="cfail2")] +#[rustc_metadata_clean(cfg="cfail3")] +impl Foo { + #[rustc_dirty(label="Hir", cfg="cfail2")] + #[rustc_clean(label="Hir", cfg="cfail3")] + #[rustc_metadata_dirty(cfg="cfail2")] + #[rustc_metadata_clean(cfg="cfail3")] + pub extern fn make_method_extern(&self) { } +} + + + +// Change method calling convention -------------------------------------------- +#[cfg(cfail1)] +impl Foo { + pub extern "C" fn change_method_calling_convention(&self) { } +} + +#[cfg(not(cfail1))] +#[rustc_clean(label="Hir", cfg="cfail2")] +#[rustc_clean(label="Hir", cfg="cfail3")] +#[rustc_metadata_clean(cfg="cfail2")] +#[rustc_metadata_clean(cfg="cfail3")] +impl Foo { + #[rustc_dirty(label="Hir", cfg="cfail2")] + #[rustc_clean(label="Hir", cfg="cfail3")] + #[rustc_metadata_dirty(cfg="cfail2")] + #[rustc_metadata_clean(cfg="cfail3")] + pub extern "system" fn change_method_calling_convention(&self) { } +} + + + +// Add Lifetime Parameter to Method -------------------------------------------- +#[cfg(cfail1)] +impl Foo { + pub fn add_lifetime_parameter_to_method(&self) { } +} + +#[cfg(not(cfail1))] +#[rustc_clean(label="Hir", cfg="cfail2")] +#[rustc_clean(label="Hir", cfg="cfail3")] +#[rustc_metadata_clean(cfg="cfail2")] +#[rustc_metadata_clean(cfg="cfail3")] +impl Foo { + #[rustc_dirty(label="Hir", cfg="cfail2")] + #[rustc_clean(label="Hir", cfg="cfail3")] + #[rustc_metadata_dirty(cfg="cfail2")] + #[rustc_metadata_clean(cfg="cfail3")] + pub fn add_lifetime_parameter_to_method<'a>(&self) { } +} + + + +// Add Type Parameter To Method ------------------------------------------------ +#[cfg(cfail1)] +impl Foo { + pub fn add_type_parameter_to_method(&self) { } +} + +#[cfg(not(cfail1))] +#[rustc_clean(label="Hir", cfg="cfail2")] +#[rustc_clean(label="Hir", cfg="cfail3")] +#[rustc_metadata_clean(cfg="cfail2")] +#[rustc_metadata_clean(cfg="cfail3")] +impl Foo { + #[rustc_dirty(label="Hir", cfg="cfail2")] + #[rustc_clean(label="Hir", cfg="cfail3")] + #[rustc_metadata_dirty(cfg="cfail2")] + #[rustc_metadata_clean(cfg="cfail3")] + pub fn add_type_parameter_to_method(&self) { } +} + + + +// Add Lifetime Bound to Lifetime Parameter of Method -------------------------- +#[cfg(cfail1)] +impl Foo { + pub fn add_lifetime_bound_to_lifetime_param_of_method<'a, 'b>(&self) { } +} + +#[cfg(not(cfail1))] +#[rustc_clean(label="Hir", cfg="cfail2")] +#[rustc_clean(label="Hir", cfg="cfail3")] +#[rustc_metadata_clean(cfg="cfail2")] +#[rustc_metadata_clean(cfg="cfail3")] +impl Foo { + #[rustc_dirty(label="Hir", cfg="cfail2")] + #[rustc_clean(label="Hir", cfg="cfail3")] + #[rustc_metadata_dirty(cfg="cfail2")] + #[rustc_metadata_clean(cfg="cfail3")] + pub fn add_lifetime_bound_to_lifetime_param_of_method<'a, 'b: 'a>(&self) { } +} + + + +// Add Lifetime Bound to Type Parameter of Method ------------------------------ +#[cfg(cfail1)] +impl Foo { + pub fn add_lifetime_bound_to_type_param_of_method<'a, T>(&self) { } +} + +#[cfg(not(cfail1))] +#[rustc_clean(label="Hir", cfg="cfail2")] +#[rustc_clean(label="Hir", cfg="cfail3")] +#[rustc_metadata_clean(cfg="cfail2")] +#[rustc_metadata_clean(cfg="cfail3")] +impl Foo { + #[rustc_dirty(label="Hir", cfg="cfail2")] + #[rustc_clean(label="Hir", cfg="cfail3")] + #[rustc_metadata_dirty(cfg="cfail2")] + #[rustc_metadata_clean(cfg="cfail3")] + pub fn add_lifetime_bound_to_type_param_of_method<'a, T: 'a>(&self) { } +} + + + +// Add Trait Bound to Type Parameter of Method ------------------------------ +#[cfg(cfail1)] +impl Foo { + pub fn add_trait_bound_to_type_param_of_method(&self) { } +} + +#[cfg(not(cfail1))] +#[rustc_clean(label="Hir", cfg="cfail2")] +#[rustc_clean(label="Hir", cfg="cfail3")] +#[rustc_metadata_clean(cfg="cfail2")] +#[rustc_metadata_clean(cfg="cfail3")] +impl Foo { + #[rustc_dirty(label="Hir", cfg="cfail2")] + #[rustc_clean(label="Hir", cfg="cfail3")] + #[rustc_metadata_dirty(cfg="cfail2")] + #[rustc_metadata_clean(cfg="cfail3")] + pub fn add_trait_bound_to_type_param_of_method(&self) { } +} + + + +// Add #[no_mangle] to Method -------------------------------------------------- +#[cfg(cfail1)] +impl Foo { + pub fn add_no_mangle_to_method(&self) { } +} + +#[cfg(not(cfail1))] +#[rustc_clean(label="Hir", cfg="cfail2")] +#[rustc_clean(label="Hir", cfg="cfail3")] +#[rustc_metadata_clean(cfg="cfail2")] +#[rustc_metadata_clean(cfg="cfail3")] +impl Foo { + #[rustc_dirty(label="Hir", cfg="cfail2")] + #[rustc_clean(label="Hir", cfg="cfail3")] + #[rustc_metadata_dirty(cfg="cfail2")] + #[rustc_metadata_clean(cfg="cfail3")] + #[no_mangle] + pub fn add_no_mangle_to_method(&self) { } +} + + + +struct Bar(T); + +// Add Type Parameter To Impl -------------------------------------------------- +#[cfg(cfail1)] +impl Bar { + pub fn add_type_parameter_to_impl(&self) { } +} + +#[cfg(not(cfail1))] +#[rustc_dirty(label="Hir", cfg="cfail2")] +#[rustc_clean(label="Hir", cfg="cfail3")] +#[rustc_metadata_dirty(cfg="cfail2")] +#[rustc_metadata_clean(cfg="cfail3")] +impl Bar { + #[rustc_dirty(label="Hir", cfg="cfail2")] + #[rustc_clean(label="Hir", cfg="cfail3")] + #[rustc_metadata_dirty(cfg="cfail2")] + #[rustc_metadata_clean(cfg="cfail3")] + pub fn add_type_parameter_to_impl(&self) { } +} + + + +// Change Self Type of Impl ---------------------------------------------------- +#[cfg(cfail1)] +impl Bar { + pub fn change_impl_self_type(&self) { } +} + +#[cfg(not(cfail1))] +#[rustc_dirty(label="Hir", cfg="cfail2")] +#[rustc_clean(label="Hir", cfg="cfail3")] +#[rustc_metadata_dirty(cfg="cfail2")] +#[rustc_metadata_clean(cfg="cfail3")] +impl Bar { + #[rustc_dirty(label="Hir", cfg="cfail2")] + #[rustc_clean(label="Hir", cfg="cfail3")] + #[rustc_metadata_dirty(cfg="cfail2")] + #[rustc_metadata_clean(cfg="cfail3")] + pub fn change_impl_self_type(&self) { } +} + + + +// Add Lifetime Bound to Impl -------------------------------------------------- +#[cfg(cfail1)] +impl Bar { + pub fn add_lifetime_bound_to_impl_parameter(&self) { } +} + +#[cfg(not(cfail1))] +#[rustc_dirty(label="Hir", cfg="cfail2")] +#[rustc_clean(label="Hir", cfg="cfail3")] +#[rustc_metadata_dirty(cfg="cfail2")] +#[rustc_metadata_clean(cfg="cfail3")] +impl Bar { + #[rustc_dirty(label="Hir", cfg="cfail2")] + #[rustc_clean(label="Hir", cfg="cfail3")] + #[rustc_metadata_dirty(cfg="cfail2")] + #[rustc_metadata_clean(cfg="cfail3")] + pub fn add_lifetime_bound_to_impl_parameter(&self) { } +} + + + +// Add Trait Bound to Impl Parameter ------------------------------------------- +#[cfg(cfail1)] +impl Bar { + pub fn add_trait_bound_to_impl_parameter(&self) { } +} + +#[cfg(not(cfail1))] +#[rustc_dirty(label="Hir", cfg="cfail2")] +#[rustc_clean(label="Hir", cfg="cfail3")] +#[rustc_metadata_dirty(cfg="cfail2")] +#[rustc_metadata_clean(cfg="cfail3")] +impl Bar { + #[rustc_dirty(label="Hir", cfg="cfail2")] + #[rustc_clean(label="Hir", cfg="cfail3")] + #[rustc_metadata_dirty(cfg="cfail2")] + #[rustc_metadata_clean(cfg="cfail3")] + pub fn add_trait_bound_to_impl_parameter(&self) { } +} From 24334a03a3e3e6137b0810ebc14ac37e37a53349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 20 Dec 2016 17:09:36 -0800 Subject: [PATCH 06/16] Docs: Explain why/when `.lines()` returns an error --- src/libstd/io/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index b07da0dc268c4..6ba614fa2e3a3 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -1425,6 +1425,12 @@ pub trait BufRead: Read { /// println!("{}", line.unwrap()); /// } /// ``` + /// + /// # Errors + /// + /// Each line of the iterator has the same error semantics as [`BufRead::read_line()`]. + /// + /// [`BufRead::read_line()`]: trait.BufRead.html#method.read_line #[stable(feature = "rust1", since = "1.0.0")] fn lines(self) -> Lines where Self: Sized { Lines { buf: self } From 99529825e8765a1241c569495bca83218fc5e498 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 21 Dec 2016 18:05:11 +0100 Subject: [PATCH 07/16] Add missing examples in some thread functions --- src/libstd/thread/mod.rs | 51 +++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 2a3fb5ec43f2a..d3949743bcadb 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -318,20 +318,38 @@ impl Builder { // Free functions //////////////////////////////////////////////////////////////////////////////// -/// Spawns a new thread, returning a `JoinHandle` for it. +/// Spawns a new thread, returning a [`JoinHandle`] for it. /// /// The join handle will implicitly *detach* the child thread upon being /// dropped. In this case, the child thread may outlive the parent (unless /// the parent thread is the main thread; the whole process is terminated when -/// the main thread finishes.) Additionally, the join handle provides a `join` +/// the main thread finishes). Additionally, the join handle provides a [`join`] /// method that can be used to join the child thread. If the child thread -/// panics, `join` will return an `Err` containing the argument given to -/// `panic`. +/// panics, [`join`] will return an [`Err`] containing the argument given to +/// [`panic`]. /// /// # Panics /// -/// Panics if the OS fails to create a thread; use `Builder::spawn` +/// Panics if the OS fails to create a thread; use [`Builder::spawn`] /// to recover from such errors. +/// +/// [`JoinHandle`]: ../../std/thread/struct.JoinHandle.html +/// [`join`]: ../../std/thread/struct.JoinHandle.html#method.join +/// [`Err`]: ../../std/result/enum.Result.html#variant.Err +/// [`panic!`]: ../../std/macro.panic.html +/// [`Builder::spawn`]: ../../std/thread/struct.Builder.html#method.spawn +/// +/// # Examples +/// +/// ``` +/// use std::thread; +/// +/// let handler = thread::spawn(|| { +/// // thread code +/// }); +/// +/// handler.join().unwrap(); +/// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn spawn(f: F) -> JoinHandle where F: FnOnce() -> T, F: Send + 'static, T: Send + 'static @@ -341,7 +359,7 @@ pub fn spawn(f: F) -> JoinHandle where /// Gets a handle to the thread that invokes it. /// -/// #Examples +/// # Examples /// /// Getting a handle to the current thread with `thread::current()`: /// @@ -366,6 +384,14 @@ pub fn current() -> Thread { } /// Cooperatively gives up a timeslice to the OS scheduler. +/// +/// # Examples +/// +/// ``` +/// use std::thread; +/// +/// thread::yield_now(); +/// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn yield_now() { imp::Thread::yield_now() @@ -375,7 +401,7 @@ pub fn yield_now() { /// /// # Examples /// -/// ```rust,should_panic +/// ```should_panic /// use std::thread; /// /// struct SomeStruct; @@ -413,6 +439,15 @@ pub fn panicking() -> bool { /// specifics or platform-dependent functionality. Note that on unix platforms /// this function will not return early due to a signal being received or a /// spurious wakeup. +/// +/// # Examples +/// +/// ```no_run +/// use std::thread; +/// +/// // Let's sleep for 2 seconds: +/// thread::sleep_ms(2000); +/// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_deprecated(since = "1.6.0", reason = "replaced by `std::thread::sleep`")] pub fn sleep_ms(ms: u32) { @@ -433,7 +468,7 @@ pub fn sleep_ms(ms: u32) { /// /// # Examples /// -/// ```rust,no_run +/// ```no_run /// use std::{thread, time}; /// /// let ten_millis = time::Duration::from_millis(10); From 88af5bf5ecfebe1683ab449213d218de7871cc92 Mon Sep 17 00:00:00 2001 From: Jason Campbell Date: Wed, 21 Dec 2016 13:28:08 -0800 Subject: [PATCH 08/16] Removes magenta build warning. Small bug fix to remove an unused type in the magenta process code that causes build failures for magenta's rustc. --- src/libstd/sys/unix/process/magenta.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libstd/sys/unix/process/magenta.rs b/src/libstd/sys/unix/process/magenta.rs index 319fbce35cd7b..2bb005be4ec93 100644 --- a/src/libstd/sys/unix/process/magenta.rs +++ b/src/libstd/sys/unix/process/magenta.rs @@ -23,7 +23,6 @@ pub type mx_rights_t = u32; pub type mx_status_t = i32; pub type mx_size_t = usize; -pub type mx_ssize_t = isize; pub const MX_HANDLE_INVALID: mx_handle_t = 0; From 40b9352aa371d5984c7e84cad5e2f597dbecf177 Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Thu, 22 Dec 2016 17:35:53 +0530 Subject: [PATCH 09/16] Fix Markdown list formatting. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Markdown engine used by the book can cope with a single leading space on the list marker: Like this: * List item Rather than like this: * List item … but it’s not the typical convention employed in the book, and moreover the Markdown engine used for producing the error index *can’t* cope with it (its behaviour looks like a bug, as it appears to lose one of the two line breaks as well, but that’s immaterial here). So, we shift to a single convention which doesn’t trigger bugs in the Markdown renderer. --- src/doc/book/casting-between-types.md | 18 +++++++++--------- src/librustc_metadata/diagnostics.rs | 6 +++--- src/librustc_typeck/diagnostics.rs | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/doc/book/casting-between-types.md b/src/doc/book/casting-between-types.md index 296384ab6efd9..a8f8224c58b81 100644 --- a/src/doc/book/casting-between-types.md +++ b/src/doc/book/casting-between-types.md @@ -16,18 +16,18 @@ function result. The most common case of coercion is removing mutability from a reference: - * `&mut T` to `&T` +* `&mut T` to `&T` An analogous conversion is to remove mutability from a [raw pointer](raw-pointers.md): - * `*mut T` to `*const T` +* `*mut T` to `*const T` References can also be coerced to raw pointers: - * `&T` to `*const T` +* `&T` to `*const T` - * `&mut T` to `*mut T` +* `&mut T` to `*mut T` Custom coercions may be defined using [`Deref`](deref-coercions.md). @@ -59,11 +59,11 @@ A cast `e as U` is valid if `e` has type `T` and `T` *coerces* to `U`. A cast `e as U` is also valid in any of the following cases: - * `e` has type `T` and `T` and `U` are any numeric types; *numeric-cast* - * `e` is a C-like enum (with no data attached to the variants), - and `U` is an integer type; *enum-cast* - * `e` has type `bool` or `char` and `U` is an integer type; *prim-int-cast* - * `e` has type `u8` and `U` is `char`; *u8-char-cast* +* `e` has type `T` and `T` and `U` are any numeric types; *numeric-cast* +* `e` is a C-like enum (with no data attached to the variants), + and `U` is an integer type; *enum-cast* +* `e` has type `bool` or `char` and `U` is an integer type; *prim-int-cast* +* `e` has type `u8` and `U` is `char`; *u8-char-cast* For example diff --git a/src/librustc_metadata/diagnostics.rs b/src/librustc_metadata/diagnostics.rs index 6cf1a9e8a390d..d3a2b6f1683e2 100644 --- a/src/librustc_metadata/diagnostics.rs +++ b/src/librustc_metadata/diagnostics.rs @@ -57,9 +57,9 @@ An unknown "kind" was specified for a link attribute. Erroneous code example: Please specify a valid "kind" value, from one of the following: - * static - * dylib - * framework +* static +* dylib +* framework "##, diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 71507063ffc43..2b17ac94b2238 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1378,8 +1378,8 @@ let x = |_| {}; // error: cannot determine a type for this expression You have two possibilities to solve this situation: - * Give an explicit definition of the expression - * Infer the expression +* Give an explicit definition of the expression +* Infer the expression Examples: From 20b92db7eb9098901577a903ee6245f531e74749 Mon Sep 17 00:00:00 2001 From: Aidan Hobson Sayers Date: Thu, 22 Dec 2016 15:58:08 +0000 Subject: [PATCH 10/16] Correct path of incremental artifacts --- src/bootstrap/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/README.md b/src/bootstrap/README.md index ade5bde07d2da..ac84edb403847 100644 --- a/src/bootstrap/README.md +++ b/src/bootstrap/README.md @@ -142,7 +142,7 @@ incremental builds: ``` The `--incremental` flag will store incremental compilation artifacts -in `build/stage0-incremental`. Note that we only use incremental +in `build//stage0-incremental`. Note that we only use incremental compilation for the stage0 -> stage1 compilation -- this is because the stage1 compiler is changing, and we don't try to cache and reuse incremental artifacts across different versions of the compiler. For From 2432f69b351676f6f77369347a82810c821024b3 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Thu, 22 Dec 2016 12:01:59 -0500 Subject: [PATCH 11/16] ICH: Make InlineAsm hashes stable. --- .../calculate_svh/svh_visitor.rs | 46 +++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/src/librustc_incremental/calculate_svh/svh_visitor.rs b/src/librustc_incremental/calculate_svh/svh_visitor.rs index ec44e19df10c9..9d5277af3383e 100644 --- a/src/librustc_incremental/calculate_svh/svh_visitor.rs +++ b/src/librustc_incremental/calculate_svh/svh_visitor.rs @@ -28,7 +28,7 @@ use rustc::hir::def_id::DefId; use rustc::hir::intravisit as visit; use rustc::ty::TyCtxt; use rustc_data_structures::fnv; -use std::hash::Hash; +use std::hash::{Hash, Hasher}; use super::def_path_hash::DefPathHashes; use super::caching_codemap_view::CachingCodemapView; @@ -265,7 +265,7 @@ enum SawExprComponent<'a> { SawExprPath, SawExprAddrOf(hir::Mutability), SawExprRet, - SawExprInlineAsm(&'a hir::InlineAsm), + SawExprInlineAsm(StableInlineAsm<'a>), SawExprStruct, SawExprRepeat, } @@ -341,7 +341,7 @@ fn saw_expr<'a>(node: &'a Expr_, ExprBreak(label, _) => (SawExprBreak(label.map(|l| l.name.as_str())), false), ExprAgain(label) => (SawExprAgain(label.map(|l| l.name.as_str())), false), ExprRet(..) => (SawExprRet, false), - ExprInlineAsm(ref a,..) => (SawExprInlineAsm(a), false), + ExprInlineAsm(ref a,..) => (SawExprInlineAsm(StableInlineAsm(a)), false), ExprStruct(..) => (SawExprStruct, false), ExprRepeat(..) => (SawExprRepeat, false), } @@ -492,6 +492,46 @@ enum SawSpanExpnKind { SomeExpansion, } +/// A wrapper that provides a stable Hash implementation. +struct StableInlineAsm<'a>(&'a InlineAsm); + +impl<'a> Hash for StableInlineAsm<'a> { + fn hash(&self, state: &mut H) { + let InlineAsm { + asm, + asm_str_style, + ref outputs, + ref inputs, + ref clobbers, + volatile, + alignstack, + dialect, + expn_id: _, // This is used for error reporting + } = *self.0; + + asm.as_str().hash(state); + asm_str_style.hash(state); + outputs.len().hash(state); + for output in outputs { + let InlineAsmOutput { constraint, is_rw, is_indirect } = *output; + constraint.as_str().hash(state); + is_rw.hash(state); + is_indirect.hash(state); + } + inputs.len().hash(state); + for input in inputs { + input.as_str().hash(state); + } + clobbers.len().hash(state); + for clobber in clobbers { + clobber.as_str().hash(state); + } + volatile.hash(state); + alignstack.hash(state); + dialect.hash(state); + } +} + macro_rules! hash_attrs { ($visitor:expr, $attrs:expr) => ({ let attrs = $attrs; From 531ac797a8437152275411ae4c1bf589d40fc60c Mon Sep 17 00:00:00 2001 From: Geoff Yoerger Date: Thu, 22 Dec 2016 12:51:31 -0600 Subject: [PATCH 12/16] Add relative hyperlink --- src/librustc_trans/README.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_trans/README.txt b/src/librustc_trans/README.txt index 1f416d5404d27..cd43cbd705282 100644 --- a/src/librustc_trans/README.txt +++ b/src/librustc_trans/README.txt @@ -1 +1 @@ -See the README.md in ../librustc. +See [librustc/README.md](../librustc/README.md). From fc9719c4caf8fd76439e312b5d41a9a4fcea193d Mon Sep 17 00:00:00 2001 From: Geoff Yoerger Date: Thu, 22 Dec 2016 12:52:22 -0600 Subject: [PATCH 13/16] Rename README.txt to README.md --- src/librustc_trans/{README.txt => README.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/librustc_trans/{README.txt => README.md} (100%) diff --git a/src/librustc_trans/README.txt b/src/librustc_trans/README.md similarity index 100% rename from src/librustc_trans/README.txt rename to src/librustc_trans/README.md From 6a51d374904e0486b2f1de2a33027ea80c1049f0 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Thu, 22 Dec 2016 14:27:53 -0500 Subject: [PATCH 14/16] ICH: Add test case for InlineAsm hashes. --- src/test/incremental/hashes/inline_asm.rs | 265 ++++++++++++++++++++++ 1 file changed, 265 insertions(+) create mode 100644 src/test/incremental/hashes/inline_asm.rs diff --git a/src/test/incremental/hashes/inline_asm.rs b/src/test/incremental/hashes/inline_asm.rs new file mode 100644 index 0000000000000..a1057c036d6c4 --- /dev/null +++ b/src/test/incremental/hashes/inline_asm.rs @@ -0,0 +1,265 @@ +// 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. + + +// This test case tests the incremental compilation hash (ICH) implementation +// for inline asm. + +// The general pattern followed here is: Change one thing between rev1 and rev2 +// and make sure that the hash has changed, then change nothing between rev2 and +// rev3 and make sure that the hash has not changed. + +// must-compile-successfully +// revisions: cfail1 cfail2 cfail3 +// compile-flags: -Z query-dep-graph + +#![allow(warnings)] +#![feature(rustc_attrs)] +#![feature(asm)] +#![crate_type="rlib"] + + + +// Change template ------------------------------------------------------------- +#[cfg(cfail1)] +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +fn change_template(a: i32) -> i32 { + let c: i32; + unsafe { + asm!("add 1, $0" + : "=r"(c) + : "0"(a) + : + : + ); + } + c +} + +#[cfg(not(cfail1))] +#[rustc_clean(label="Hir", cfg="cfail2")] +#[rustc_clean(label="Hir", cfg="cfail3")] +#[rustc_dirty(label="HirBody", cfg="cfail2")] +#[rustc_clean(label="HirBody", cfg="cfail3")] +#[rustc_metadata_clean(cfg="cfail2")] +#[rustc_metadata_clean(cfg="cfail3")] +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +fn change_template(a: i32) -> i32 { + let c: i32; + unsafe { + asm!("add 2, $0" + : "=r"(c) + : "0"(a) + : + : + ); + } + c +} + + + +// Change output ------------------------------------------------------------- +#[cfg(cfail1)] +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +fn change_output(a: i32) -> i32 { + let mut _out1: i32 = 0; + let mut _out2: i32 = 0; + unsafe { + asm!("add 1, $0" + : "=r"(_out1) + : "0"(a) + : + : + ); + } + _out1 +} + +#[cfg(not(cfail1))] +#[rustc_clean(label="Hir", cfg="cfail2")] +#[rustc_clean(label="Hir", cfg="cfail3")] +#[rustc_dirty(label="HirBody", cfg="cfail2")] +#[rustc_clean(label="HirBody", cfg="cfail3")] +#[rustc_metadata_clean(cfg="cfail2")] +#[rustc_metadata_clean(cfg="cfail3")] +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +fn change_output(a: i32) -> i32 { + let mut _out1: i32 = 0; + let mut _out2: i32 = 0; + unsafe { + asm!("add 1, $0" + : "=r"(_out2) + : "0"(a) + : + : + ); + } + _out1 +} + + + +// Change input ------------------------------------------------------------- +#[cfg(cfail1)] +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +fn change_input(_a: i32, _b: i32) -> i32 { + let _out; + unsafe { + asm!("add 1, $0" + : "=r"(_out) + : "0"(_a) + : + : + ); + } + _out +} + +#[cfg(not(cfail1))] +#[rustc_clean(label="Hir", cfg="cfail2")] +#[rustc_clean(label="Hir", cfg="cfail3")] +#[rustc_dirty(label="HirBody", cfg="cfail2")] +#[rustc_clean(label="HirBody", cfg="cfail3")] +#[rustc_metadata_clean(cfg="cfail2")] +#[rustc_metadata_clean(cfg="cfail3")] +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +fn change_input(_a: i32, _b: i32) -> i32 { + let _out; + unsafe { + asm!("add 1, $0" + : "=r"(_out) + : "0"(_b) + : + : + ); + } + _out +} + + + +// Change input constraint ----------------------------------------------------- +#[cfg(cfail1)] +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +fn change_input_constraint(_a: i32, _b: i32) -> i32 { + let _out; + unsafe { + asm!("add 1, $0" + : "=r"(_out) + : "0"(_a), "r"(_b) + : + : + ); + } + _out +} + +#[cfg(not(cfail1))] +#[rustc_clean(label="Hir", cfg="cfail2")] +#[rustc_clean(label="Hir", cfg="cfail3")] +#[rustc_dirty(label="HirBody", cfg="cfail2")] +#[rustc_clean(label="HirBody", cfg="cfail3")] +#[rustc_metadata_clean(cfg="cfail2")] +#[rustc_metadata_clean(cfg="cfail3")] +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +fn change_input_constraint(_a: i32, _b: i32) -> i32 { + let _out; + unsafe { + asm!("add 1, $0" + : "=r"(_out) + : "r"(_a), "0"(_b) + : + : + ); + } + _out +} + + + +// Change clobber -------------------------------------------------------------- +#[cfg(cfail1)] +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +fn change_clobber(_a: i32) -> i32 { + let _out; + unsafe { + asm!("add 1, $0" + : "=r"(_out) + : "0"(_a) + : + : + ); + } + _out +} + +#[cfg(not(cfail1))] +#[rustc_clean(label="Hir", cfg="cfail2")] +#[rustc_clean(label="Hir", cfg="cfail3")] +#[rustc_dirty(label="HirBody", cfg="cfail2")] +#[rustc_clean(label="HirBody", cfg="cfail3")] +#[rustc_metadata_clean(cfg="cfail2")] +#[rustc_metadata_clean(cfg="cfail3")] +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +fn change_clobber(_a: i32) -> i32 { + let _out; + unsafe { + asm!("add 1, $0" + : "=r"(_out) + : "0"(_a) + : "eax" + : + ); + } + _out +} + + + +// Change options -------------------------------------------------------------- +#[cfg(cfail1)] +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +fn change_options(_a: i32) -> i32 { + let _out; + unsafe { + asm!("add 1, $0" + : "=r"(_out) + : "0"(_a) + : + : + ); + } + _out +} + +#[cfg(not(cfail1))] +#[rustc_clean(label="Hir", cfg="cfail2")] +#[rustc_clean(label="Hir", cfg="cfail3")] +#[rustc_dirty(label="HirBody", cfg="cfail2")] +#[rustc_clean(label="HirBody", cfg="cfail3")] +#[rustc_metadata_clean(cfg="cfail2")] +#[rustc_metadata_clean(cfg="cfail3")] +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +fn change_options(_a: i32) -> i32 { + let _out; + unsafe { + asm!("add 1, $0" + : "=r"(_out) + : "0"(_a) + : + : "volatile" + ); + } + _out +} + + + From d8ee0745f734231edb16441776a60c33dae317c2 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Fri, 23 Dec 2016 22:32:27 +0200 Subject: [PATCH 15/16] book: replace example I do not understand --- src/doc/book/documentation.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/doc/book/documentation.md b/src/doc/book/documentation.md index f30a95b4e7890..dafcffc39c802 100644 --- a/src/doc/book/documentation.md +++ b/src/doc/book/documentation.md @@ -460,8 +460,9 @@ not actually pass as a test. ``` The `no_run` attribute will compile your code, but not run it. This is -important for examples such as "Here's how to start up a network service," -which you would want to make sure compile, but might run in an infinite loop! +important for examples such as "Here's how to retrieve a web page," +which you would want to ensure compiles, but might be run in a test +environment that has no network access. ### Documenting modules From 00645e85043b9830118d4c9aecb59cc2c041b437 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 23 Dec 2016 11:25:11 +0100 Subject: [PATCH 16/16] Add JoinHandle missing examples --- src/libstd/thread/mod.rs | 46 ++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 2a3fb5ec43f2a..0ba009e5867df 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -749,7 +749,7 @@ impl JoinInner { /// /// A `JoinHandle` *detaches* the child thread when it is dropped. /// -/// Due to platform restrictions, it is not possible to `Clone` this +/// Due to platform restrictions, it is not possible to [`Clone`] this /// handle: the ability to join a child thread is a uniquely-owned /// permission. /// @@ -760,7 +760,7 @@ impl JoinInner { /// /// Creation from [`thread::spawn`]: /// -/// ```rust +/// ``` /// use std::thread; /// /// let join_handle: thread::JoinHandle<_> = thread::spawn(|| { @@ -770,7 +770,7 @@ impl JoinInner { /// /// Creation from [`thread::Builder::spawn`]: /// -/// ```rust +/// ``` /// use std::thread; /// /// let builder = thread::Builder::new(); @@ -780,13 +780,31 @@ impl JoinInner { /// }).unwrap(); /// ``` /// +/// [`Clone`]: ../../std/clone/trait.Clone.html /// [`thread::spawn`]: fn.spawn.html /// [`thread::Builder::spawn`]: struct.Builder.html#method.spawn #[stable(feature = "rust1", since = "1.0.0")] pub struct JoinHandle(JoinInner); impl JoinHandle { - /// Extracts a handle to the underlying thread + /// Extracts a handle to the underlying thread. + /// + /// # Examples + /// + /// ``` + /// #![feature(thread_id)] + /// + /// use std::thread; + /// + /// let builder = thread::Builder::new(); + /// + /// let join_handle: thread::JoinHandle<_> = builder.spawn(|| { + /// // some work here + /// }).unwrap(); + /// + /// let thread = join_handle.thread(); + /// println!("thread id: {:?}", thread.id()); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn thread(&self) -> &Thread { &self.0.thread @@ -794,8 +812,24 @@ impl JoinHandle { /// Waits for the associated thread to finish. /// - /// If the child thread panics, `Err` is returned with the parameter given - /// to `panic`. + /// If the child thread panics, [`Err`] is returned with the parameter given + /// to [`panic`]. + /// + /// [`Err`]: ../../std/result/enum.Result.html#variant.Err + /// [`panic!`]: ../../std/macro.panic.html + /// + /// # Examples + /// + /// ``` + /// use std::thread; + /// + /// let builder = thread::Builder::new(); + /// + /// let join_handle: thread::JoinHandle<_> = builder.spawn(|| { + /// // some work here + /// }).unwrap(); + /// join_handle.join().expect("Couldn't join on the associated thread"); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn join(mut self) -> Result { self.0.join()