@@ -5,7 +5,7 @@ that your tests are up to date and working.
55
66The basic idea is this:
77
8- ``` rust, ignore
8+ ``` ignore
99/// # Examples
1010///
1111/// ```
@@ -106,23 +106,23 @@ our source code:
106106```text
107107 First , we set `x ` to five :
108108
109- ```rust
109+ ```
110110 let x = 5 ;
111111 # let y = 6 ;
112112 # println! (" {}" , x + y );
113113 ```
114114
115115 Next , we set `y ` to six :
116116
117- ```rust
117+ ```
118118 # let x = 5 ;
119119 let y = 6 ;
120120 # println! (" {}" , x + y );
121121 ```
122122
123123 Finally , we print the sum of `x ` and `y `:
124124
125- ```rust
125+ ```
126126 # let x = 5 ;
127127 # let y = 6 ;
128128 println! (" {}" , x + y );
@@ -136,7 +136,7 @@ explanation.
136136Another case where the use of ` # ` is handy is when you want to ignore
137137error handling. Lets say you want the following,
138138
139- ``` rust, ignore
139+ ``` ignore
140140/// use std::io;
141141/// let mut input = String::new();
142142/// io::stdin().read_line(&mut input)?;
@@ -145,7 +145,7 @@ error handling. Lets say you want the following,
145145The problem is that ` ? ` returns a ` Result<T, E> ` and test functions
146146don't return anything so this will give a mismatched types error.
147147
148- ``` rust, ignore
148+ ``` ignore
149149/// A doc test using ?
150150///
151151/// ```
@@ -179,7 +179,7 @@ Here’s an example of documenting a macro:
179179/// # }
180180/// ```
181181///
182- /// ```rust, should_panic
182+ /// ```should_panic
183183/// # #[macro_use] extern crate foo;
184184/// # fn main() {
185185/// panic_unless!(true == false, “I’m broken.”);
@@ -224,7 +224,7 @@ only shows the part you care about.
224224` should_panic ` tells ` rustdoc ` that the code should compile correctly, but
225225not actually pass as a test.
226226
227- ``` rust
227+ ``` text
228228/// ```no_run
229229/// loop {
230230/// println!("Hello, world");
@@ -233,6 +233,18 @@ not actually pass as a test.
233233# fn foo() {}
234234```
235235
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+
236248The ` no_run ` attribute will compile your code, but not run it. This is
237249important for examples such as "Here's how to retrieve a web page,"
238250which you would want to ensure compiles, but might be run in a test
0 commit comments