@@ -5,7 +5,7 @@ that your tests are up to date and working.
5
5
6
6
The basic idea is this:
7
7
8
- ``` rust, ignore
8
+ ``` ignore
9
9
/// # Examples
10
10
///
11
11
/// ```
@@ -106,23 +106,23 @@ our source code:
106
106
```text
107
107
First , we set `x ` to five :
108
108
109
- ```rust
109
+ ```
110
110
let x = 5 ;
111
111
# let y = 6 ;
112
112
# println! (" {}" , x + y );
113
113
```
114
114
115
115
Next , we set `y ` to six :
116
116
117
- ```rust
117
+ ```
118
118
# let x = 5 ;
119
119
let y = 6 ;
120
120
# println! (" {}" , x + y );
121
121
```
122
122
123
123
Finally , we print the sum of `x ` and `y `:
124
124
125
- ```rust
125
+ ```
126
126
# let x = 5 ;
127
127
# let y = 6 ;
128
128
println! (" {}" , x + y );
@@ -136,7 +136,7 @@ explanation.
136
136
Another case where the use of ` # ` is handy is when you want to ignore
137
137
error handling. Lets say you want the following,
138
138
139
- ``` rust, ignore
139
+ ``` ignore
140
140
/// use std::io;
141
141
/// let mut input = String::new();
142
142
/// io::stdin().read_line(&mut input)?;
@@ -145,7 +145,7 @@ error handling. Lets say you want the following,
145
145
The problem is that ` ? ` returns a ` Result<T, E> ` and test functions
146
146
don't return anything so this will give a mismatched types error.
147
147
148
- ``` rust, ignore
148
+ ``` ignore
149
149
/// A doc test using ?
150
150
///
151
151
/// ```
@@ -179,7 +179,7 @@ Here’s an example of documenting a macro:
179
179
/// # }
180
180
/// ```
181
181
///
182
- /// ```rust, should_panic
182
+ /// ```should_panic
183
183
/// # #[macro_use] extern crate foo;
184
184
/// # fn main() {
185
185
/// panic_unless!(true == false, “I’m broken.”);
@@ -224,7 +224,7 @@ only shows the part you care about.
224
224
` should_panic ` tells ` rustdoc ` that the code should compile correctly, but
225
225
not actually pass as a test.
226
226
227
- ``` rust
227
+ ``` text
228
228
/// ```no_run
229
229
/// loop {
230
230
/// println!("Hello, world");
@@ -233,6 +233,18 @@ not actually pass as a test.
233
233
# fn foo() {}
234
234
```
235
235
236
+ ` compile_fail ` tells ` rustdoc ` that the compilation should fail. If it
237
+ compiles, then the test will fail. However please note that code failing
238
+ with the current Rust release may work in a future release, as new features
239
+ are added.
240
+
241
+ ``` text
242
+ /// ```compile_fail
243
+ /// let x = 5;
244
+ /// x += 2; // shouldn't compile!
245
+ /// ```
246
+ ```
247
+
236
248
The ` no_run ` attribute will compile your code, but not run it. This is
237
249
important for examples such as "Here's how to retrieve a web page,"
238
250
which you would want to ensure compiles, but might be run in a test
0 commit comments