Skip to content

Commit 0f68728

Browse files
committed
Auto merge of #42038 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 8 pull requests - Successful merges: #41489, #41982, #41994, #41995, #42001, #42005, #42011, #42028 - Failed merges:
2 parents b28cf75 + 9678ad2 commit 0f68728

File tree

15 files changed

+158
-45
lines changed

15 files changed

+158
-45
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ python x.py test src/test/rustdoc
177177
python x.py build src/libcore --stage 0
178178
```
179179

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

183183
```

src/librustc_typeck/check/method/suggest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
251251
let bound_list = unsatisfied_predicates.iter()
252252
.map(|p| format!("`{} : {}`", p.self_ty(), p))
253253
.collect::<Vec<_>>()
254-
.join(", ");
254+
.join("\n");
255255
err.note(&format!("the method `{}` exists but the following trait bounds \
256-
were not satisfied: {}",
256+
were not satisfied:\n{}",
257257
item_name,
258258
bound_list));
259259
}

src/librustdoc/html/format.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,6 @@ impl fmt::Display for AbiSpace {
11771177
let quot = if f.alternate() { "\"" } else { "&quot;" };
11781178
match self.0 {
11791179
Abi::Rust => Ok(()),
1180-
Abi::C => write!(f, "extern "),
11811180
abi => write!(f, "extern {0}{1}{0} ", quot, abi.name()),
11821181
}
11831182
}

src/librustdoc/html/static/rustdoc.css

+5
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,11 @@ a.test-arrow:hover{
617617
top: 0;
618618
}
619619

620+
h3 > .collapse-toggle, h4 > .collapse-toggle {
621+
font-size: 0.8em;
622+
top: 5px;
623+
}
624+
620625
.toggle-wrapper > .collapse-toggle {
621626
left: -24px;
622627
margin-top: 0px;

src/libstd/thread/local.rs

+30-15
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ use mem;
1919
/// A thread local storage key which owns its contents.
2020
///
2121
/// This key uses the fastest possible implementation available to it for the
22-
/// target platform. It is instantiated with the `thread_local!` macro and the
23-
/// primary method is the `with` method.
22+
/// target platform. It is instantiated with the [`thread_local!`] macro and the
23+
/// primary method is the [`with`] method.
2424
///
25-
/// The `with` method yields a reference to the contained value which cannot be
25+
/// The [`with`] method yields a reference to the contained value which cannot be
2626
/// sent across threads or escape the given closure.
2727
///
2828
/// # Initialization and Destruction
2929
///
30-
/// Initialization is dynamically performed on the first call to `with()`
31-
/// within a thread, and values that implement `Drop` get destructed when a
30+
/// Initialization is dynamically performed on the first call to [`with`]
31+
/// within a thread, and values that implement [`Drop`] get destructed when a
3232
/// thread exits. Some caveats apply, which are explained below.
3333
///
3434
/// # Examples
@@ -77,6 +77,10 @@ use mem;
7777
/// 3. On macOS, initializing TLS during destruction of other TLS slots can
7878
/// sometimes cancel *all* destructors for the current thread, whether or not
7979
/// the slots have already had their destructors run or not.
80+
///
81+
/// [`with`]: ../../std/thread/struct.LocalKey.html#method.with
82+
/// [`thread_local!`]: ../../std/macro.thread_local.html
83+
/// [`Drop`]: ../../std/ops/trait.Drop.html
8084
#[stable(feature = "rust1", since = "1.0.0")]
8185
pub struct LocalKey<T: 'static> {
8286
// This outer `LocalKey<T>` type is what's going to be stored in statics,
@@ -106,7 +110,7 @@ impl<T: 'static> fmt::Debug for LocalKey<T> {
106110
}
107111
}
108112

109-
/// Declare a new thread local storage key of type `std::thread::LocalKey`.
113+
/// Declare a new thread local storage key of type [`std::thread::LocalKey`].
110114
///
111115
/// # Syntax
112116
///
@@ -124,8 +128,10 @@ impl<T: 'static> fmt::Debug for LocalKey<T> {
124128
/// # fn main() {}
125129
/// ```
126130
///
127-
/// See [LocalKey documentation](thread/struct.LocalKey.html) for more
131+
/// See [LocalKey documentation][`std::thread::LocalKey`] for more
128132
/// information.
133+
///
134+
/// [`std::thread::LocalKey`]: ../std/thread/struct.LocalKey.html
129135
#[macro_export]
130136
#[stable(feature = "rust1", since = "1.0.0")]
131137
#[allow_internal_unstable]
@@ -195,11 +201,13 @@ macro_rules! __thread_local_inner {
195201
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
196202
pub enum LocalKeyState {
197203
/// All keys are in this state whenever a thread starts. Keys will
198-
/// transition to the `Valid` state once the first call to `with` happens
204+
/// transition to the `Valid` state once the first call to [`with`] happens
199205
/// and the initialization expression succeeds.
200206
///
201207
/// Keys in the `Uninitialized` state will yield a reference to the closure
202-
/// passed to `with` so long as the initialization routine does not panic.
208+
/// passed to [`with`] so long as the initialization routine does not panic.
209+
///
210+
/// [`with`]: ../../std/thread/struct.LocalKey.html#method.with
203211
Uninitialized,
204212

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

214224
/// When a thread exits, the destructors for keys will be run (if
215225
/// necessary). While a destructor is running, and possibly after a
216226
/// destructor has run, a key is in the `Destroyed` state.
217227
///
218228
/// Keys in the `Destroyed` states will trigger a panic when accessed via
219-
/// `with`.
229+
/// [`with`].
230+
///
231+
/// [`with`]: ../../std/thread/struct.LocalKey.html#method.with
220232
Destroyed,
221233
}
222234

@@ -283,23 +295,26 @@ impl<T: 'static> LocalKey<T> {
283295
/// Query the current state of this key.
284296
///
285297
/// A key is initially in the `Uninitialized` state whenever a thread
286-
/// starts. It will remain in this state up until the first call to `with`
298+
/// starts. It will remain in this state up until the first call to [`with`]
287299
/// within a thread has run the initialization expression successfully.
288300
///
289301
/// Once the initialization expression succeeds, the key transitions to the
290-
/// `Valid` state which will guarantee that future calls to `with` will
302+
/// `Valid` state which will guarantee that future calls to [`with`] will
291303
/// succeed within the thread.
292304
///
293305
/// When a thread exits, each key will be destroyed in turn, and as keys are
294306
/// destroyed they will enter the `Destroyed` state just before the
295307
/// destructor starts to run. Keys may remain in the `Destroyed` state after
296308
/// destruction has completed. Keys without destructors (e.g. with types
297-
/// that are `Copy`), may never enter the `Destroyed` state.
309+
/// that are [`Copy`]), may never enter the `Destroyed` state.
298310
///
299311
/// Keys in the `Uninitialized` state can be accessed so long as the
300312
/// initialization does not panic. Keys in the `Valid` state are guaranteed
301313
/// to be able to be accessed. Keys in the `Destroyed` state will panic on
302-
/// any call to `with`.
314+
/// any call to [`with`].
315+
///
316+
/// [`with`]: ../../std/thread/struct.LocalKey.html#method.with
317+
/// [`Copy`]: ../../std/marker/trait.Copy.html
303318
#[unstable(feature = "thread_local_state",
304319
reason = "state querying was recently added",
305320
issue = "27716")]

src/libstd/thread/mod.rs

+61-11
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,33 @@ pub use self::local::{LocalKey, LocalKeyState};
180180
// Builder
181181
////////////////////////////////////////////////////////////////////////////////
182182

183-
/// Thread configuration. Provides detailed control over the properties
184-
/// and behavior of new threads.
183+
/// Thread factory, which can be used in order to configure the properties of
184+
/// a new thread.
185+
///
186+
/// Methods can be chained on it in order to configure it.
187+
///
188+
/// The two configurations available are:
189+
///
190+
/// - [`name`]: allows to give a name to the thread which is currently
191+
/// only used in `panic` messages.
192+
/// - [`stack_size`]: specifies the desired stack size. Note that this can
193+
/// be overriden by the OS.
194+
///
195+
/// If the [`stack_size`] field is not specified, the stack size
196+
/// will be the `RUST_MIN_STACK` environment variable. If it is
197+
/// not specified either, a sensible default will be set.
198+
///
199+
/// If the [`name`] field is not specified, the thread will not be named.
200+
///
201+
/// The [`spawn`] method will take ownership of the builder and create an
202+
/// [`io::Result`] to the thread handle with the given configuration.
203+
///
204+
/// The [`thread::spawn`] free function uses a `Builder` with default
205+
/// configuration and [`unwrap`]s its return value.
206+
///
207+
/// You may want to use [`spawn`] instead of [`thread::spawn`], when you want
208+
/// to recover from a failure to launch a thread, indeed the free function will
209+
/// panick where the `Builder` method will return a [`io::Result`].
185210
///
186211
/// # Examples
187212
///
@@ -196,6 +221,13 @@ pub use self::local::{LocalKey, LocalKeyState};
196221
///
197222
/// handler.join().unwrap();
198223
/// ```
224+
///
225+
/// [`thread::spawn`]: ../../std/thread/fn.spawn.html
226+
/// [`stack_size`]: ../../std/thread/struct.Builder.html#method.stack_size
227+
/// [`name`]: ../../std/thread/struct.Builder.html#method.name
228+
/// [`spawn`]: ../../std/thread/struct.Builder.html#method.spawn
229+
/// [`io::Result`]: ../../std/io/type.Result.html
230+
/// [`unwrap`]: ../../std/result/enum.Result.html#method.unwrap
199231
#[stable(feature = "rust1", since = "1.0.0")]
200232
#[derive(Debug)]
201233
pub struct Builder {
@@ -209,11 +241,6 @@ impl Builder {
209241
/// Generates the base configuration for spawning a thread, from which
210242
/// configuration methods can be chained.
211243
///
212-
/// If the [`stack_size`] field is not specified, the stack size
213-
/// will be the `RUST_MIN_STACK` environment variable. If it is
214-
/// not specified either, a sensible default will be set (2MB as
215-
/// of the writting of this doc).
216-
///
217244
/// # Examples
218245
///
219246
/// ```
@@ -229,8 +256,6 @@ impl Builder {
229256
///
230257
/// handler.join().unwrap();
231258
/// ```
232-
///
233-
/// [`stack_size`]: ../../std/thread/struct.Builder.html#method.stack_size
234259
#[stable(feature = "rust1", since = "1.0.0")]
235260
pub fn new() -> Builder {
236261
Builder {
@@ -280,9 +305,10 @@ impl Builder {
280305
self
281306
}
282307

283-
/// Spawns a new thread, and returns a join handle for it.
308+
/// Spawns a new thread by taking ownership of the `Builder`, and returns an
309+
/// [`io::Result`] to its [`JoinHandle`].
284310
///
285-
/// The child thread may outlive the parent (unless the parent thread
311+
/// The spawned thread may outlive the caller (unless the caller thread
286312
/// is the main thread; the whole process is terminated when the main
287313
/// thread finishes). The join handle can be used to block on
288314
/// termination of the child thread, including recovering its panics.
@@ -297,6 +323,7 @@ impl Builder {
297323
///
298324
/// [`spawn`]: ../../std/thread/fn.spawn.html
299325
/// [`io::Result`]: ../../std/io/type.Result.html
326+
/// [`JoinHandle`]: ../../std/thread/struct.JoinHandle.html
300327
///
301328
/// # Examples
302329
///
@@ -468,13 +495,36 @@ pub fn current() -> Thread {
468495

469496
/// Cooperatively gives up a timeslice to the OS scheduler.
470497
///
498+
/// This is used when the programmer knows that the thread will have nothing
499+
/// to do for some time, and thus avoid wasting computing time.
500+
///
501+
/// For example when polling on a resource, it is common to check that it is
502+
/// available, and if not to yield in order to avoid busy waiting.
503+
///
504+
/// Thus the pattern of `yield`ing after a failed poll is rather common when
505+
/// implementing low-level shared resources or synchronization primitives.
506+
///
507+
/// However programmers will usualy prefer to use, [`channel`]s, [`Condvar`]s,
508+
/// [`Mutex`]es or [`join`] for their synchronisation routines, as they avoid
509+
/// thinking about thread schedulling.
510+
///
511+
/// Note that [`channel`]s for example are implemented using this primitive.
512+
/// Indeed when you call `send` or `recv`, which are blocking, they will yield
513+
/// if the channel is not available.
514+
///
471515
/// # Examples
472516
///
473517
/// ```
474518
/// use std::thread;
475519
///
476520
/// thread::yield_now();
477521
/// ```
522+
///
523+
/// [`channel`]: ../../std/sync/mpsc/index.html
524+
/// [`spawn`]: ../../std/thread/fn.spawn.html
525+
/// [`join`]: ../../std/thread/struct.JoinHandle.html#method.join
526+
/// [`Mutex`]: ../../std/sync/struct.Mutex.html
527+
/// [`Condvar`]: ../../std/sync/struct.Condvar.html
478528
#[stable(feature = "rust1", since = "1.0.0")]
479529
pub fn yield_now() {
480530
imp::Thread::yield_now()

src/libsyntax/ext/tt/macro_parser.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,12 @@ pub fn parse_failure_msg(tok: Token) -> String {
267267

268268
/// Perform a token equality check, ignoring syntax context (that is, an unhygienic comparison)
269269
fn token_name_eq(t1 : &Token, t2 : &Token) -> bool {
270-
match (t1,t2) {
271-
(&token::Ident(id1),&token::Ident(id2))
272-
| (&token::Lifetime(id1),&token::Lifetime(id2)) =>
273-
id1.name == id2.name,
274-
_ => *t1 == *t2
270+
if let (Some(id1), Some(id2)) = (t1.ident(), t2.ident()) {
271+
id1.name == id2.name
272+
} else if let (&token::Lifetime(id1), &token::Lifetime(id2)) = (t1, t2) {
273+
id1.name == id2.name
274+
} else {
275+
*t1 == *t2
275276
}
276277
}
277278

src/test/run-pass/issue-41803.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
/// A compile-time map from identifiers to arbitrary (heterogeneous) expressions
12+
macro_rules! ident_map {
13+
( $name:ident = { $($key:ident => $e:expr,)* } ) => {
14+
macro_rules! $name {
15+
$(
16+
( $key ) => { $e };
17+
)*
18+
// Empty invocation expands to nothing. Needed when the map is empty.
19+
() => {};
20+
}
21+
};
22+
}
23+
24+
ident_map!(my_map = {
25+
main => 0,
26+
});
27+
28+
fn main() {
29+
my_map!(main);
30+
}

src/test/rustdoc/extern-impl.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ impl Foo {
1818
pub fn rust0() {}
1919
// @has - '//code' 'fn rust1()'
2020
pub extern "Rust" fn rust1() {}
21-
// @has - '//code' 'extern fn c0()'
21+
// @has - '//code' 'extern "C" fn c0()'
2222
pub extern fn c0() {}
23-
// @has - '//code' 'extern fn c1()'
23+
// @has - '//code' 'extern "C" fn c1()'
2424
pub extern "C" fn c1() {}
2525
// @has - '//code' 'extern "system" fn system0()'
2626
pub extern "system" fn system0() {}
@@ -31,7 +31,7 @@ pub trait Bar {}
3131

3232
// @has - '//code' 'impl Bar for fn()'
3333
impl Bar for fn() {}
34-
// @has - '//code' 'impl Bar for extern fn()'
34+
// @has - '//code' 'impl Bar for extern "C" fn()'
3535
impl Bar for extern fn() {}
3636
// @has - '//code' 'impl Bar for extern "system" fn()'
3737
impl Bar for extern "system" fn() {}

src/test/rustdoc/ffi.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
extern crate rustdoc_ffi as lib;
1515

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

1919
extern "C" {
20-
// @has ffi/fn.another.html //pre 'pub unsafe extern fn another(cold_as_ice: u32)'
20+
// @has ffi/fn.another.html //pre 'pub unsafe extern "C" fn another(cold_as_ice: u32)'
2121
pub fn another(cold_as_ice: u32);
2222
}

src/test/rustdoc/issue-22038.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
extern {
1212
// @has issue_22038/fn.foo1.html \
13-
// '//*[@class="rust fn"]' 'pub unsafe extern fn foo1()'
13+
// '//*[@class="rust fn"]' 'pub unsafe extern "C" fn foo1()'
1414
pub fn foo1();
1515
}
1616

@@ -21,7 +21,7 @@ extern "system" {
2121
}
2222

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

2727
// @has issue_22038/fn.baz.html \

0 commit comments

Comments
 (0)