Skip to content

Commit bd7d541

Browse files
committed
Fix doc tests
1 parent 3184520 commit bd7d541

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/libstd/primitive_docs.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,12 @@ mod prim_bool { }
7979
/// write
8080
///
8181
/// ```
82+
/// # #![feature(never_type)]
83+
/// # fn foo() -> u32 {
8284
/// let x: ! = {
83-
/// return 123;
85+
/// return 123
8486
/// };
87+
/// # }
8588
/// ```
8689
///
8790
/// Although the `let` is pointless here, it illustrates the meaning of `!`. Since `x` is never
@@ -92,10 +95,13 @@ mod prim_bool { }
9295
/// A more realistic usage of `!` is in this code:
9396
///
9497
/// ```
98+
/// # fn get_a_number() -> Option<u32> { None }
99+
/// # loop {
95100
/// let num: u32 = match get_a_number() {
96101
/// Some(num) => num,
97102
/// None => break,
98-
/// }
103+
/// };
104+
/// # }
99105
/// ```
100106
///
101107
/// Both match arms must produce values of type `u32`, but since `break` never produces a value at
@@ -110,18 +116,20 @@ mod prim_bool { }
110116
/// trait:
111117
///
112118
/// ```
113-
/// trait FromStr {
114-
/// type Error;
115-
/// fn from_str(s: &str) -> Result<Self, Self::Error>;
119+
/// trait FromStr: Sized {
120+
/// type Err;
121+
/// fn from_str(s: &str) -> Result<Self, Self::Err>;
116122
/// }
117123
/// ```
118124
///
119-
/// When implementing this trait for `String` we need to pick a type for `Error`. And since
125+
/// When implementing this trait for `String` we need to pick a type for `Err`. And since
120126
/// converting a string into a string will never result in an error, the appropriate type is `!`.
121-
/// If we have to call `String::from_str` for some reason, the result will be a
122-
/// `Result<String, !>`, which we can unpack like this:
127+
/// (Currently the type actually used is an enum with no variants, though this is only because `!`
128+
/// was added to Rust at a later date and it may change in the future). With an `Err` type of `!`,
129+
/// if we have to call `String::from_str` for some reason the result will be a `Result<String, !>`
130+
/// which we can unpack like this:
123131
///
124-
/// ```
132+
/// ```ignore (string-from-str-error-type-is-not-never-yet)
125133
/// let Ok(s) = String::from_str("hello");
126134
/// ```
127135
///
@@ -138,6 +146,11 @@ mod prim_bool { }
138146
/// for example:
139147
///
140148
/// ```
149+
/// # #![feature(never_type)]
150+
/// # use std::fmt;
151+
/// # trait Debug {
152+
/// # fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result;
153+
/// # }
141154
/// impl Debug for ! {
142155
/// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
143156
/// *self

0 commit comments

Comments
 (0)