@@ -79,9 +79,12 @@ mod prim_bool { }
79
79
/// write
80
80
///
81
81
/// ```
82
+ /// # #![feature(never_type)]
83
+ /// # fn foo() -> u32 {
82
84
/// let x: ! = {
83
- /// return 123;
85
+ /// return 123
84
86
/// };
87
+ /// # }
85
88
/// ```
86
89
///
87
90
/// Although the `let` is pointless here, it illustrates the meaning of `!`. Since `x` is never
@@ -92,10 +95,13 @@ mod prim_bool { }
92
95
/// A more realistic usage of `!` is in this code:
93
96
///
94
97
/// ```
98
+ /// # fn get_a_number() -> Option<u32> { None }
99
+ /// # loop {
95
100
/// let num: u32 = match get_a_number() {
96
101
/// Some(num) => num,
97
102
/// None => break,
98
- /// }
103
+ /// };
104
+ /// # }
99
105
/// ```
100
106
///
101
107
/// Both match arms must produce values of type `u32`, but since `break` never produces a value at
@@ -110,18 +116,20 @@ mod prim_bool { }
110
116
/// trait:
111
117
///
112
118
/// ```
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 >;
116
122
/// }
117
123
/// ```
118
124
///
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
120
126
/// 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:
123
131
///
124
- /// ```
132
+ /// ```ignore (string-from-str-error-type-is-not-never-yet)
125
133
/// let Ok(s) = String::from_str("hello");
126
134
/// ```
127
135
///
@@ -138,6 +146,11 @@ mod prim_bool { }
138
146
/// for example:
139
147
///
140
148
/// ```
149
+ /// # #![feature(never_type)]
150
+ /// # use std::fmt;
151
+ /// # trait Debug {
152
+ /// # fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result;
153
+ /// # }
141
154
/// impl Debug for ! {
142
155
/// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
143
156
/// *self
0 commit comments