Skip to content

Commit e72ddbd

Browse files
committed
Fix all code examples
1 parent 6667f90 commit e72ddbd

File tree

18 files changed

+103
-67
lines changed

18 files changed

+103
-67
lines changed

src/libextra/json.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ An object is a series of string keys mapping to values, in `"key": value` format
3030
Arrays are enclosed in square brackets ([ ... ]) and objects in curly brackets ({ ... }).
3131
A simple JSON document encoding a person, his/her age, address and phone numbers could look like:
3232
33-
```
33+
```ignore
3434
{
3535
"FirstName": "John",
3636
"LastName": "Doe",

src/libextra/stats.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ pub fn write_5_number_summary(w: &mut io::Writer,
341341
/// As an example, the summary with 5-number-summary `(min=15, q1=17, med=20, q3=24, max=31)` might
342342
/// display as:
343343
///
344-
/// ~~~~
344+
/// ~~~~ignore
345345
/// 10 | [--****#******----------] | 40
346346
/// ~~~~
347347

src/libglob/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub struct Paths {
6767
///
6868
/// The above code will print:
6969
///
70-
/// ```
70+
/// ```ignore
7171
/// /media/pictures/kittens.jpg
7272
/// /media/pictures/puppies.jpg
7373
/// ```

src/libstd/comm/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
//! let (port, chan) = Chan::new();
6262
//! spawn(proc() {
6363
//! chan.send(10);
64-
//! })
64+
//! });
6565
//! assert_eq!(port.recv(), 10);
6666
//!
6767
//! // Create a shared channel which can be sent along from many tasks

src/libstd/fmt/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function, but the `format!` macro is a syntax extension which allows it to
8282
leverage named parameters. Named parameters are listed at the end of the
8383
argument list and have the syntax:
8484
85-
```
85+
```ignore
8686
identifier '=' expression
8787
```
8888
@@ -107,7 +107,7 @@ and if all references to one argument do not provide a type, then the format `?`
107107
is used (the type's rust-representation is printed). For example, this is an
108108
invalid format string:
109109
110-
```
110+
```ignore
111111
{0:d} {0:s}
112112
```
113113
@@ -123,7 +123,7 @@ must have the type `uint`. Although a `uint` can be printed with `{:u}`, it is
123123
illegal to reference an argument as such. For example, this is another invalid
124124
format string:
125125
126-
```
126+
```ignore
127127
{:.*s} {0:u}
128128
```
129129
@@ -334,7 +334,7 @@ This example is the equivalent of `{0:s}` essentially.
334334
The select method is a switch over a `&str` parameter, and the parameter *must*
335335
be of the type `&str`. An example of the syntax is:
336336
337-
```
337+
```ignore
338338
{0, select, male{...} female{...} other{...}}
339339
```
340340
@@ -353,7 +353,7 @@ The plural method is a switch statement over a `uint` parameter, and the
353353
parameter *must* be a `uint`. A plural method in its full glory can be specified
354354
as:
355355
356-
```
356+
```ignore
357357
{0, plural, offset=1 =1{...} two{...} many{...} other{...}}
358358
```
359359
@@ -381,7 +381,7 @@ should not be too alien. Arguments are formatted with python-like syntax,
381381
meaning that arguments are surrounded by `{}` instead of the C-like `%`. The
382382
actual grammar for the formatting syntax is:
383383
384-
```
384+
```ignore
385385
format_string := <text> [ format <text> ] *
386386
format := '{' [ argument ] [ ':' format_spec ] [ ',' function_spec ] '}'
387387
argument := integer | identifier

src/libstd/io/comm_adapters.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ use vec::{bytes, CloneableVector, MutableVector, ImmutableVector};
2222
/// # Example
2323
///
2424
/// ```
25-
/// let reader = PortReader::new(port);
25+
/// use std::io::PortReader;
26+
///
27+
/// let (port, chan) = Chan::new();
28+
/// # drop(chan);
29+
/// let mut reader = PortReader::new(port);
2630
///
2731
/// let mut buf = ~[0u8, ..100];
2832
/// match reader.read(buf) {
29-
/// Some(nread) => println!("Read {} bytes", nread),
30-
/// None => println!("At the end of the stream!")
33+
/// Ok(nread) => println!("Read {} bytes", nread),
34+
/// Err(e) => println!("read error: {}", e),
3135
/// }
3236
/// ```
3337
pub struct PortReader {
@@ -83,7 +87,12 @@ impl Reader for PortReader {
8387
/// # Example
8488
///
8589
/// ```
86-
/// let writer = ChanWriter::new(chan);
90+
/// # #[allow(unused_must_use)];
91+
/// use std::io::ChanWriter;
92+
///
93+
/// let (port, chan) = Chan::new();
94+
/// # drop(port);
95+
/// let mut writer = ChanWriter::new(chan);
8796
/// writer.write("hello, world".as_bytes());
8897
/// ```
8998
pub struct ChanWriter {

src/libstd/io/net/unix.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,18 @@ impl UnixListener {
9191
/// # Example
9292
///
9393
/// ```
94+
/// # fn main() {}
95+
/// # fn foo() {
96+
/// # #[allow(unused_must_use)];
9497
/// use std::io::net::unix::UnixListener;
95-
/// use std::io::Listener;
98+
/// use std::io::{Listener, Acceptor};
9699
///
97-
/// let server = Path::new("path/to/my/socket");
98-
/// let mut stream = UnixListener::bind(&server);
99-
/// for client in stream.incoming() {
100-
/// let mut client = client;
100+
/// let server = Path::new("/path/to/my/socket");
101+
/// let stream = UnixListener::bind(&server);
102+
/// for mut client in stream.listen().incoming() {
101103
/// client.write([1, 2, 3, 4]);
102104
/// }
105+
/// # }
103106
/// ```
104107
pub fn bind<P: ToCStr>(path: &P) -> IoResult<UnixListener> {
105108
LocalIo::maybe_raise(|io| {

src/libstd/kinds.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ pub mod marker {
6969
/// Given a struct `S` that includes a type parameter `T`
7070
/// but does not actually *reference* that type parameter:
7171
///
72-
/// ```
72+
/// ```ignore
73+
/// use std::cast;
74+
///
7375
/// struct S<T> { x: *() }
7476
/// fn get<T>(s: &S<T>) -> T {
7577
/// unsafe {
@@ -109,6 +111,8 @@ pub mod marker {
109111
/// but does not actually *reference* that type parameter:
110112
///
111113
/// ```
114+
/// use std::cast;
115+
///
112116
/// struct S<T> { x: *() }
113117
/// fn get<T>(s: &S<T>, v: T) {
114118
/// unsafe {
@@ -147,7 +151,8 @@ pub mod marker {
147151
/// "interior" mutability:
148152
///
149153
/// ```
150-
/// struct Cell<T> { priv value: T }
154+
/// pub struct Cell<T> { priv value: T }
155+
/// # fn main() {}
151156
/// ```
152157
///
153158
/// The type system would infer that `value` is only read here and

src/libstd/logging.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ disabled except for `error!` (a log level of 1). Logging is controlled via the
4242
`RUST_LOG` environment variable. The value of this environment variable is a
4343
comma-separated list of logging directives. A logging directive is of the form:
4444
45-
```
45+
```ignore
4646
path::to::module=log_level
4747
```
4848
@@ -65,7 +65,7 @@ all modules is set to this value.
6565
6666
Some examples of valid values of `RUST_LOG` are:
6767
68-
```
68+
```ignore
6969
hello // turns on all logging for the 'hello' module
7070
info // turns on all info logging
7171
hello=debug // turns on debug logging for 'hello'

src/libstd/num/int_macros.rs

+22-19
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ impl Rem<$T,$T> for $T {
119119
/// Returns the integer remainder after division, satisfying:
120120
///
121121
/// ```
122+
/// # let n = 1;
123+
/// # let d = 2;
122124
/// assert!((n / d) * d + (n % d) == n)
123125
/// ```
124126
///
@@ -194,15 +196,15 @@ impl Integer for $T {
194196
/// # Examples
195197
///
196198
/// ```
197-
/// assert!(( 8).div_floor( 3) == 2);
198-
/// assert!(( 8).div_floor(-3) == -3);
199-
/// assert!((-8).div_floor( 3) == -3);
200-
/// assert!((-8).div_floor(-3) == 2);
201-
///
202-
/// assert!(( 1).div_floor( 2) == 0);
203-
/// assert!(( 1).div_floor(-2) == -1);
204-
/// assert!((-1).div_floor( 2) == -1);
205-
/// assert!((-1).div_floor(-2) == 0);
199+
/// assert!(( 8i).div_floor(& 3) == 2);
200+
/// assert!(( 8i).div_floor(&-3) == -3);
201+
/// assert!((-8i).div_floor(& 3) == -3);
202+
/// assert!((-8i).div_floor(&-3) == 2);
203+
///
204+
/// assert!(( 1i).div_floor(& 2) == 0);
205+
/// assert!(( 1i).div_floor(&-2) == -1);
206+
/// assert!((-1i).div_floor(& 2) == -1);
207+
/// assert!((-1i).div_floor(&-2) == 0);
206208
/// ```
207209
///
208210
#[inline]
@@ -220,21 +222,22 @@ impl Integer for $T {
220222
/// Integer modulo, satisfying:
221223
///
222224
/// ```
223-
/// assert!(n.div_floor(d) * d + n.mod_floor(d) == n)
225+
/// # let n = 1i; let d = 1i;
226+
/// assert!(n.div_floor(&d) * d + n.mod_floor(&d) == n)
224227
/// ```
225228
///
226229
/// # Examples
227230
///
228231
/// ```
229-
/// assert!(( 8).mod_floor( 3) == 2);
230-
/// assert!(( 8).mod_floor(-3) == -1);
231-
/// assert!((-8).mod_floor( 3) == 1);
232-
/// assert!((-8).mod_floor(-3) == -2);
233-
///
234-
/// assert!(( 1).mod_floor( 2) == 1);
235-
/// assert!(( 1).mod_floor(-2) == -1);
236-
/// assert!((-1).mod_floor( 2) == 1);
237-
/// assert!((-1).mod_floor(-2) == -1);
232+
/// assert!(( 8i).mod_floor(& 3) == 2);
233+
/// assert!(( 8i).mod_floor(&-3) == -1);
234+
/// assert!((-8i).mod_floor(& 3) == 1);
235+
/// assert!((-8i).mod_floor(&-3) == -2);
236+
///
237+
/// assert!(( 1i).mod_floor(& 2) == 1);
238+
/// assert!(( 1i).mod_floor(&-2) == -1);
239+
/// assert!((-1i).mod_floor(& 2) == 1);
240+
/// assert!((-1i).mod_floor(&-2) == -1);
238241
/// ```
239242
///
240243
#[inline]

src/libstd/num/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub trait Zero: Add<Self, Self> {
4545
///
4646
/// # Laws
4747
///
48-
/// ~~~
48+
/// ~~~ignore
4949
/// a + 0 = a ∀ a ∈ Self
5050
/// 0 + a = a ∀ a ∈ Self
5151
/// ~~~
@@ -71,7 +71,7 @@ pub trait One: Mul<Self, Self> {
7171
///
7272
/// # Laws
7373
///
74-
/// ~~~
74+
/// ~~~ignore
7575
/// a * 1 = a ∀ a ∈ Self
7676
/// 1 * a = a ∀ a ∈ Self
7777
/// ~~~
@@ -964,6 +964,8 @@ impl_from_primitive!(f64, n.to_f64())
964964
/// # Example
965965
///
966966
/// ```
967+
/// use std::num;
968+
///
967969
/// let twenty: f32 = num::cast(0x14).unwrap();
968970
/// assert_eq!(twenty, 20f32);
969971
/// ```

src/libstd/rand/distributions/gamma.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use super::{IndependentSample, Sample, Exp};
2020
///
2121
/// The density function of this distribution is
2222
///
23-
/// ```
23+
/// ```ignore
2424
/// f(x) = x^(k - 1) * exp(-x / θ) / (Γ(k) * θ^k)
2525
/// ```
2626
///

src/libstd/str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2011,7 +2011,7 @@ pub trait StrSlice<'a> {
20112011
///
20122012
/// ## Output
20132013
///
2014-
/// ```
2014+
/// ```ignore
20152015
/// 0: 中
20162016
/// 3: 华
20172017
/// 6: V

src/libstd/task.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
*
4747
* ```
4848
* spawn(proc() {
49-
* log(error, "Hello, World!");
49+
* println!("Hello, World!");
5050
* })
5151
* ```
5252
*/

src/libstd/unstable/finally.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ also be used. See that function for more details.
1919
2020
# Example
2121
22-
```
22+
```
23+
use std::unstable::finally::Finally;
24+
# fn always_run_this() {}
25+
2326
(|| {
24-
...
27+
// ...
2528
}).finally(|| {
2629
always_run_this();
2730
})
28-
```
31+
```
2932
*/
3033

3134
use ops::Drop;
@@ -69,13 +72,16 @@ impl<T> Finally<T> for fn() -> T {
6972
* # Example
7073
*
7174
* ```
75+
* use std::unstable::finally::try_finally;
76+
*
7277
* struct State<'a> { buffer: &'a mut [u8], len: uint }
78+
* # let mut buf = [];
7379
* let mut state = State { buffer: buf, len: 0 };
7480
* try_finally(
7581
* &mut state, (),
7682
* |state, ()| {
7783
* // use state.buffer, state.len
78-
* }
84+
* },
7985
* |state| {
8086
* // use state.buffer, state.len to cleanup
8187
* })

src/libstd/vec.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ pub trait ImmutableVector<'a, T> {
955955
*
956956
* Equivalent to:
957957
*
958-
* ```
958+
* ```ignore
959959
* if self.len() == 0 { return None }
960960
* let head = &self[0];
961961
* *self = self.slice_from(1);
@@ -973,7 +973,7 @@ pub trait ImmutableVector<'a, T> {
973973
*
974974
* Equivalent to:
975975
*
976-
* ```
976+
* ```ignore
977977
* if self.len() == 0 { return None; }
978978
* let tail = &self[self.len() - 1];
979979
* *self = self.slice_to(self.len() - 1);
@@ -2075,7 +2075,7 @@ pub trait MutableVector<'a, T> {
20752075
*
20762076
* Equivalent to:
20772077
*
2078-
* ```
2078+
* ```ignore
20792079
* if self.len() == 0 { return None; }
20802080
* let head = &mut self[0];
20812081
* *self = self.mut_slice_from(1);
@@ -2093,7 +2093,7 @@ pub trait MutableVector<'a, T> {
20932093
*
20942094
* Equivalent to:
20952095
*
2096-
* ```
2096+
* ```ignore
20972097
* if self.len() == 0 { return None; }
20982098
* let tail = &mut self[self.len() - 1];
20992099
* *self = self.mut_slice_to(self.len() - 1);

0 commit comments

Comments
 (0)