Skip to content

Commit 8ed03c8

Browse files
committed
Auto merge of #30049 - Manishearth:rollup, r=Manishearth
- Successful merges: #30013, #30038, #30040 - Failed merges: #30030
2 parents 7fa2c6c + 529689f commit 8ed03c8

File tree

4 files changed

+96
-16
lines changed

4 files changed

+96
-16
lines changed

src/doc/book/dining-philosophers.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,17 @@ Now, let’s imagine this sequence of events:
4545
6. ... ? All the forks are taken, but nobody can eat!
4646

4747
There are different ways to solve this problem. We’ll get to our solution in
48-
the tutorial itself. For now, let’s get started modeling the problem itself.
49-
We’ll start with the philosophers:
48+
the tutorial itself. For now, let’s get started and create a new project with
49+
`cargo`:
50+
51+
```bash
52+
$ cd ~/projects
53+
$ cargo new dining_philosophers --bin
54+
$ cd dining_philosophers
55+
```
56+
57+
Now we can start modeling the problem itself. We’ll start with the philosophers
58+
in `src/main.rs`:
5059

5160
```rust
5261
struct Philosopher {

src/liballoc/arc.rs

+5
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,11 @@ impl<T: ?Sized> Weak<T> {
637637
return None
638638
}
639639

640+
// See comments in `Arc::clone` for why we do this (for `mem::forget`).
641+
if n > MAX_REFCOUNT {
642+
unsafe { abort(); }
643+
}
644+
640645
// Relaxed is valid for the same reason it is on Arc's Clone impl
641646
let old = inner.strong.compare_and_swap(n, n + 1, Relaxed);
642647
if old == n {

src/librustc_unicode/char.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! A Unicode scalar value
11+
//! Unicode scalar values
1212
//!
1313
//! This module provides the `CharExt` trait, as well as its
1414
//! implementation for the primitive `char` type, in order to allow
@@ -244,11 +244,12 @@ impl char {
244244
/// character, as `char`s.
245245
///
246246
/// All characters are escaped with Rust syntax of the form `\\u{NNNN}`
247-
/// where `NNNN` is the shortest hexadecimal representation of the code
248-
/// point.
247+
/// where `NNNN` is the shortest hexadecimal representation.
249248
///
250249
/// # Examples
251250
///
251+
/// Basic usage:
252+
///
252253
/// ```
253254
/// for c in '❤'.escape_unicode() {
254255
/// print!("{}", c);
@@ -384,6 +385,8 @@ impl char {
384385
///
385386
/// # Examples
386387
///
388+
/// Basic usage:
389+
///
387390
/// ```
388391
/// let n = 'ß'.len_utf16();
389392
/// assert_eq!(n, 1);
@@ -858,6 +861,8 @@ pub struct DecodeUtf16<I>
858861
///
859862
/// # Examples
860863
///
864+
/// Basic usage:
865+
///
861866
/// ```
862867
/// #![feature(decode_utf16)]
863868
///

src/libstd/primitive_docs.rs

+72-11
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,82 @@ mod prim_bool { }
1616

1717
#[doc(primitive = "char")]
1818
//
19-
/// A Unicode scalar value.
19+
/// A character type.
2020
///
21-
/// A `char` represents a
22-
/// *[Unicode scalar
23-
/// value](http://www.unicode.org/glossary/#unicode_scalar_value)*, as it can
24-
/// contain any Unicode code point except high-surrogate and low-surrogate code
25-
/// points.
21+
/// The `char` type represents a single character. More specifically, since
22+
/// 'character' isn't a well-defined concept in Unicode, `char` is a '[Unicode
23+
/// scalar value]', which is similar to, but not the same as, a '[Unicode code
24+
/// point]'.
2625
///
27-
/// As such, only values in the ranges \[0x0,0xD7FF\] and \[0xE000,0x10FFFF\]
28-
/// (inclusive) are allowed. A `char` can always be safely cast to a `u32`;
29-
/// however the converse is not always true due to the above range limits
30-
/// and, as such, should be performed via the `from_u32` function.
26+
/// [Unicode scalar value]: http://www.unicode.org/glossary/#unicode_scalar_value
27+
/// [Unicode code point]: http://www.unicode.org/glossary/#code_point
3128
///
32-
/// *[See also the `std::char` module](char/index.html).*
29+
/// This documentation describes a number of methods and trait implementations on the
30+
/// `char` type. For technical reasons, there is additional, separate
31+
/// documentation in [the `std::char` module](char/index.html) as well.
3332
///
33+
/// # Representation
34+
///
35+
/// `char` is always four bytes in size. This is a different representation than
36+
/// a given character would have as part of a [`String`], for example:
37+
///
38+
/// ```
39+
/// let v = vec!['h', 'e', 'l', 'l', 'o'];
40+
///
41+
/// // five elements times four bytes for each element
42+
/// assert_eq!(20, v.len() * std::mem::size_of::<char>());
43+
///
44+
/// let s = String::from("hello");
45+
///
46+
/// // five elements times one byte per element
47+
/// assert_eq!(5, s.len() * std::mem::size_of::<u8>());
48+
/// ```
49+
///
50+
/// [`String`]: string/struct.String.html
51+
///
52+
/// As always, remember that a human intuition for 'character' may not map to
53+
/// Unicode's definitions. For example, emoji symbols such as '❤️' are more than
54+
/// one byte; ❤️ in particular is six:
55+
///
56+
/// ```
57+
/// let s = String::from("❤️");
58+
///
59+
/// // six bytes times one byte for each element
60+
/// assert_eq!(6, s.len() * std::mem::size_of::<u8>());
61+
/// ```
62+
///
63+
/// This also means it won't fit into a `char`, and so trying to create a
64+
/// literal with `let heart = '❤️';` gives an error:
65+
///
66+
/// ```text
67+
/// error: character literal may only contain one codepoint: '❤
68+
/// let heart = '❤️';
69+
/// ^~
70+
/// ```
71+
///
72+
/// Another implication of this is that if you want to do per-`char`acter
73+
/// processing, it can end up using a lot more memory:
74+
///
75+
/// ```
76+
/// let s = String::from("love: ❤️");
77+
/// let v: Vec<char> = s.chars().collect();
78+
///
79+
/// assert_eq!(12, s.len() * std::mem::size_of::<u8>());
80+
/// assert_eq!(32, v.len() * std::mem::size_of::<char>());
81+
/// ```
82+
///
83+
/// Or may give you results you may not expect:
84+
///
85+
/// ```
86+
/// let s = String::from("❤️");
87+
///
88+
/// let mut iter = s.chars();
89+
///
90+
/// // we get two chars out of a single ❤️
91+
/// assert_eq!(Some('\u{2764}'), iter.next());
92+
/// assert_eq!(Some('\u{fe0f}'), iter.next());
93+
/// assert_eq!(None, iter.next());
94+
/// ```
3495
mod prim_char { }
3596

3697
#[doc(primitive = "unit")]

0 commit comments

Comments
 (0)