Skip to content

Commit

Permalink
Auto merge of #42038 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
Rollup of 8 pull requests

- Successful merges: #41489, #41982, #41994, #41995, #42001, #42005, #42011, #42028
- Failed merges:
  • Loading branch information
bors committed May 16, 2017
2 parents b28cf75 + 9678ad2 commit 0f68728
Show file tree
Hide file tree
Showing 15 changed files with 158 additions and 45 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ python x.py test src/test/rustdoc
python x.py build src/libcore --stage 0
```

You can explore the build system throught the various `--help` pages for each
You can explore the build system through the various `--help` pages for each
subcommand. For example to learn more about a command you can run:

```
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let bound_list = unsatisfied_predicates.iter()
.map(|p| format!("`{} : {}`", p.self_ty(), p))
.collect::<Vec<_>>()
.join(", ");
.join("\n");
err.note(&format!("the method `{}` exists but the following trait bounds \
were not satisfied: {}",
were not satisfied:\n{}",
item_name,
bound_list));
}
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,6 @@ impl fmt::Display for AbiSpace {
let quot = if f.alternate() { "\"" } else { "&quot;" };
match self.0 {
Abi::Rust => Ok(()),
Abi::C => write!(f, "extern "),
abi => write!(f, "extern {0}{1}{0} ", quot, abi.name()),
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,11 @@ a.test-arrow:hover{
top: 0;
}

h3 > .collapse-toggle, h4 > .collapse-toggle {
font-size: 0.8em;
top: 5px;
}

.toggle-wrapper > .collapse-toggle {
left: -24px;
margin-top: 0px;
Expand Down
45 changes: 30 additions & 15 deletions src/libstd/thread/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ use mem;
/// A thread local storage key which owns its contents.
///
/// This key uses the fastest possible implementation available to it for the
/// target platform. It is instantiated with the `thread_local!` macro and the
/// primary method is the `with` method.
/// target platform. It is instantiated with the [`thread_local!`] macro and the
/// primary method is the [`with`] method.
///
/// The `with` method yields a reference to the contained value which cannot be
/// The [`with`] method yields a reference to the contained value which cannot be
/// sent across threads or escape the given closure.
///
/// # Initialization and Destruction
///
/// Initialization is dynamically performed on the first call to `with()`
/// within a thread, and values that implement `Drop` get destructed when a
/// Initialization is dynamically performed on the first call to [`with`]
/// within a thread, and values that implement [`Drop`] get destructed when a
/// thread exits. Some caveats apply, which are explained below.
///
/// # Examples
Expand Down Expand Up @@ -77,6 +77,10 @@ use mem;
/// 3. On macOS, initializing TLS during destruction of other TLS slots can
/// sometimes cancel *all* destructors for the current thread, whether or not
/// the slots have already had their destructors run or not.
///
/// [`with`]: ../../std/thread/struct.LocalKey.html#method.with
/// [`thread_local!`]: ../../std/macro.thread_local.html
/// [`Drop`]: ../../std/ops/trait.Drop.html
#[stable(feature = "rust1", since = "1.0.0")]
pub struct LocalKey<T: 'static> {
// This outer `LocalKey<T>` type is what's going to be stored in statics,
Expand Down Expand Up @@ -106,7 +110,7 @@ impl<T: 'static> fmt::Debug for LocalKey<T> {
}
}

/// Declare a new thread local storage key of type `std::thread::LocalKey`.
/// Declare a new thread local storage key of type [`std::thread::LocalKey`].
///
/// # Syntax
///
Expand All @@ -124,8 +128,10 @@ impl<T: 'static> fmt::Debug for LocalKey<T> {
/// # fn main() {}
/// ```
///
/// See [LocalKey documentation](thread/struct.LocalKey.html) for more
/// See [LocalKey documentation][`std::thread::LocalKey`] for more
/// information.
///
/// [`std::thread::LocalKey`]: ../std/thread/struct.LocalKey.html
#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
#[allow_internal_unstable]
Expand Down Expand Up @@ -195,11 +201,13 @@ macro_rules! __thread_local_inner {
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub enum LocalKeyState {
/// All keys are in this state whenever a thread starts. Keys will
/// transition to the `Valid` state once the first call to `with` happens
/// transition to the `Valid` state once the first call to [`with`] happens
/// and the initialization expression succeeds.
///
/// Keys in the `Uninitialized` state will yield a reference to the closure
/// passed to `with` so long as the initialization routine does not panic.
/// passed to [`with`] so long as the initialization routine does not panic.
///
/// [`with`]: ../../std/thread/struct.LocalKey.html#method.with
Uninitialized,

/// Once a key has been accessed successfully, it will enter the `Valid`
Expand All @@ -208,15 +216,19 @@ pub enum LocalKeyState {
/// `Destroyed` state.
///
/// Keys in the `Valid` state will be guaranteed to yield a reference to the
/// closure passed to `with`.
/// closure passed to [`with`].
///
/// [`with`]: ../../std/thread/struct.LocalKey.html#method.with
Valid,

/// When a thread exits, the destructors for keys will be run (if
/// necessary). While a destructor is running, and possibly after a
/// destructor has run, a key is in the `Destroyed` state.
///
/// Keys in the `Destroyed` states will trigger a panic when accessed via
/// `with`.
/// [`with`].
///
/// [`with`]: ../../std/thread/struct.LocalKey.html#method.with
Destroyed,
}

Expand Down Expand Up @@ -283,23 +295,26 @@ impl<T: 'static> LocalKey<T> {
/// Query the current state of this key.
///
/// A key is initially in the `Uninitialized` state whenever a thread
/// starts. It will remain in this state up until the first call to `with`
/// starts. It will remain in this state up until the first call to [`with`]
/// within a thread has run the initialization expression successfully.
///
/// Once the initialization expression succeeds, the key transitions to the
/// `Valid` state which will guarantee that future calls to `with` will
/// `Valid` state which will guarantee that future calls to [`with`] will
/// succeed within the thread.
///
/// When a thread exits, each key will be destroyed in turn, and as keys are
/// destroyed they will enter the `Destroyed` state just before the
/// destructor starts to run. Keys may remain in the `Destroyed` state after
/// destruction has completed. Keys without destructors (e.g. with types
/// that are `Copy`), may never enter the `Destroyed` state.
/// that are [`Copy`]), may never enter the `Destroyed` state.
///
/// Keys in the `Uninitialized` state can be accessed so long as the
/// initialization does not panic. Keys in the `Valid` state are guaranteed
/// to be able to be accessed. Keys in the `Destroyed` state will panic on
/// any call to `with`.
/// any call to [`with`].
///
/// [`with`]: ../../std/thread/struct.LocalKey.html#method.with
/// [`Copy`]: ../../std/marker/trait.Copy.html
#[unstable(feature = "thread_local_state",
reason = "state querying was recently added",
issue = "27716")]
Expand Down
72 changes: 61 additions & 11 deletions src/libstd/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,33 @@ pub use self::local::{LocalKey, LocalKeyState};
// Builder
////////////////////////////////////////////////////////////////////////////////

/// Thread configuration. Provides detailed control over the properties
/// and behavior of new threads.
/// Thread factory, which can be used in order to configure the properties of
/// a new thread.
///
/// Methods can be chained on it in order to configure it.
///
/// The two configurations available are:
///
/// - [`name`]: allows to give a name to the thread which is currently
/// only used in `panic` messages.
/// - [`stack_size`]: specifies the desired stack size. Note that this can
/// be overriden by the OS.
///
/// If the [`stack_size`] field is not specified, the stack size
/// will be the `RUST_MIN_STACK` environment variable. If it is
/// not specified either, a sensible default will be set.
///
/// If the [`name`] field is not specified, the thread will not be named.
///
/// The [`spawn`] method will take ownership of the builder and create an
/// [`io::Result`] to the thread handle with the given configuration.
///
/// The [`thread::spawn`] free function uses a `Builder` with default
/// configuration and [`unwrap`]s its return value.
///
/// You may want to use [`spawn`] instead of [`thread::spawn`], when you want
/// to recover from a failure to launch a thread, indeed the free function will
/// panick where the `Builder` method will return a [`io::Result`].
///
/// # Examples
///
Expand All @@ -196,6 +221,13 @@ pub use self::local::{LocalKey, LocalKeyState};
///
/// handler.join().unwrap();
/// ```
///
/// [`thread::spawn`]: ../../std/thread/fn.spawn.html
/// [`stack_size`]: ../../std/thread/struct.Builder.html#method.stack_size
/// [`name`]: ../../std/thread/struct.Builder.html#method.name
/// [`spawn`]: ../../std/thread/struct.Builder.html#method.spawn
/// [`io::Result`]: ../../std/io/type.Result.html
/// [`unwrap`]: ../../std/result/enum.Result.html#method.unwrap
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Debug)]
pub struct Builder {
Expand All @@ -209,11 +241,6 @@ impl Builder {
/// Generates the base configuration for spawning a thread, from which
/// configuration methods can be chained.
///
/// If the [`stack_size`] field is not specified, the stack size
/// will be the `RUST_MIN_STACK` environment variable. If it is
/// not specified either, a sensible default will be set (2MB as
/// of the writting of this doc).
///
/// # Examples
///
/// ```
Expand All @@ -229,8 +256,6 @@ impl Builder {
///
/// handler.join().unwrap();
/// ```
///
/// [`stack_size`]: ../../std/thread/struct.Builder.html#method.stack_size
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new() -> Builder {
Builder {
Expand Down Expand Up @@ -280,9 +305,10 @@ impl Builder {
self
}

/// Spawns a new thread, and returns a join handle for it.
/// Spawns a new thread by taking ownership of the `Builder`, and returns an
/// [`io::Result`] to its [`JoinHandle`].
///
/// The child thread may outlive the parent (unless the parent thread
/// The spawned thread may outlive the caller (unless the caller thread
/// is the main thread; the whole process is terminated when the main
/// thread finishes). The join handle can be used to block on
/// termination of the child thread, including recovering its panics.
Expand All @@ -297,6 +323,7 @@ impl Builder {
///
/// [`spawn`]: ../../std/thread/fn.spawn.html
/// [`io::Result`]: ../../std/io/type.Result.html
/// [`JoinHandle`]: ../../std/thread/struct.JoinHandle.html
///
/// # Examples
///
Expand Down Expand Up @@ -468,13 +495,36 @@ pub fn current() -> Thread {

/// Cooperatively gives up a timeslice to the OS scheduler.
///
/// This is used when the programmer knows that the thread will have nothing
/// to do for some time, and thus avoid wasting computing time.
///
/// For example when polling on a resource, it is common to check that it is
/// available, and if not to yield in order to avoid busy waiting.
///
/// Thus the pattern of `yield`ing after a failed poll is rather common when
/// implementing low-level shared resources or synchronization primitives.
///
/// However programmers will usualy prefer to use, [`channel`]s, [`Condvar`]s,
/// [`Mutex`]es or [`join`] for their synchronisation routines, as they avoid
/// thinking about thread schedulling.
///
/// Note that [`channel`]s for example are implemented using this primitive.
/// Indeed when you call `send` or `recv`, which are blocking, they will yield
/// if the channel is not available.
///
/// # Examples
///
/// ```
/// use std::thread;
///
/// thread::yield_now();
/// ```
///
/// [`channel`]: ../../std/sync/mpsc/index.html
/// [`spawn`]: ../../std/thread/fn.spawn.html
/// [`join`]: ../../std/thread/struct.JoinHandle.html#method.join
/// [`Mutex`]: ../../std/sync/struct.Mutex.html
/// [`Condvar`]: ../../std/sync/struct.Condvar.html
#[stable(feature = "rust1", since = "1.0.0")]
pub fn yield_now() {
imp::Thread::yield_now()
Expand Down
11 changes: 6 additions & 5 deletions src/libsyntax/ext/tt/macro_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,12 @@ pub fn parse_failure_msg(tok: Token) -> String {

/// Perform a token equality check, ignoring syntax context (that is, an unhygienic comparison)
fn token_name_eq(t1 : &Token, t2 : &Token) -> bool {
match (t1,t2) {
(&token::Ident(id1),&token::Ident(id2))
| (&token::Lifetime(id1),&token::Lifetime(id2)) =>
id1.name == id2.name,
_ => *t1 == *t2
if let (Some(id1), Some(id2)) = (t1.ident(), t2.ident()) {
id1.name == id2.name
} else if let (&token::Lifetime(id1), &token::Lifetime(id2)) = (t1, t2) {
id1.name == id2.name
} else {
*t1 == *t2
}
}

Expand Down
30 changes: 30 additions & 0 deletions src/test/run-pass/issue-41803.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2017 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

/// A compile-time map from identifiers to arbitrary (heterogeneous) expressions
macro_rules! ident_map {
( $name:ident = { $($key:ident => $e:expr,)* } ) => {
macro_rules! $name {
$(
( $key ) => { $e };
)*
// Empty invocation expands to nothing. Needed when the map is empty.
() => {};
}
};
}

ident_map!(my_map = {
main => 0,
});

fn main() {
my_map!(main);
}
6 changes: 3 additions & 3 deletions src/test/rustdoc/extern-impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ impl Foo {
pub fn rust0() {}
// @has - '//code' 'fn rust1()'
pub extern "Rust" fn rust1() {}
// @has - '//code' 'extern fn c0()'
// @has - '//code' 'extern "C" fn c0()'
pub extern fn c0() {}
// @has - '//code' 'extern fn c1()'
// @has - '//code' 'extern "C" fn c1()'
pub extern "C" fn c1() {}
// @has - '//code' 'extern "system" fn system0()'
pub extern "system" fn system0() {}
Expand All @@ -31,7 +31,7 @@ pub trait Bar {}

// @has - '//code' 'impl Bar for fn()'
impl Bar for fn() {}
// @has - '//code' 'impl Bar for extern fn()'
// @has - '//code' 'impl Bar for extern "C" fn()'
impl Bar for extern fn() {}
// @has - '//code' 'impl Bar for extern "system" fn()'
impl Bar for extern "system" fn() {}
4 changes: 2 additions & 2 deletions src/test/rustdoc/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

extern crate rustdoc_ffi as lib;

// @has ffi/fn.foreigner.html //pre 'pub unsafe extern fn foreigner(cold_as_ice: u32)'
// @has ffi/fn.foreigner.html //pre 'pub unsafe extern "C" fn foreigner(cold_as_ice: u32)'
pub use lib::foreigner;

extern "C" {
// @has ffi/fn.another.html //pre 'pub unsafe extern fn another(cold_as_ice: u32)'
// @has ffi/fn.another.html //pre 'pub unsafe extern "C" fn another(cold_as_ice: u32)'
pub fn another(cold_as_ice: u32);
}
4 changes: 2 additions & 2 deletions src/test/rustdoc/issue-22038.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

extern {
// @has issue_22038/fn.foo1.html \
// '//*[@class="rust fn"]' 'pub unsafe extern fn foo1()'
// '//*[@class="rust fn"]' 'pub unsafe extern "C" fn foo1()'
pub fn foo1();
}

Expand All @@ -21,7 +21,7 @@ extern "system" {
}

// @has issue_22038/fn.bar.html \
// '//*[@class="rust fn"]' 'pub extern fn bar()'
// '//*[@class="rust fn"]' 'pub extern "C" fn bar()'
pub extern fn bar() {}

// @has issue_22038/fn.baz.html \
Expand Down
Loading

0 comments on commit 0f68728

Please sign in to comment.