Skip to content

Commit 8db4cae

Browse files
committed
Add #![feature] attributes to doctests
1 parent 3a21c4b commit 8db4cae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+649
-22
lines changed

src/doc/reference.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,8 +816,7 @@ may optionally begin with any number of `attributes` that apply to the
816816
containing module. Attributes on the anonymous crate module define important
817817
metadata that influences the behavior of the compiler.
818818

819-
```{.rust}
820-
# #![allow(unused_attribute)]
819+
```no_run
821820
// Crate name
822821
#![crate_name = "projx"]
823822
@@ -1020,6 +1019,7 @@ Use declarations support a number of convenient shortcuts:
10201019
An example of `use` declarations:
10211020

10221021
```
1022+
# #![feature(core)]
10231023
use std::iter::range_step;
10241024
use std::option::Option::{Some, None};
10251025
use std::collections::hash_map::{self, HashMap};
@@ -1080,6 +1080,7 @@ declarations.
10801080
An example of what will and will not work for `use` items:
10811081

10821082
```
1083+
# #![feature(core)]
10831084
# #![allow(unused_imports)]
10841085
use foo::core::iter; // good: foo is at the root of the crate
10851086
use foo::baz::foobaz; // good: foo is at the root of the crate
@@ -1781,6 +1782,7 @@ functions, with the exception that they may not have a body and are instead
17811782
terminated by a semicolon.
17821783

17831784
```
1785+
# #![feature(libc)]
17841786
extern crate libc;
17851787
use libc::{c_char, FILE};
17861788

src/doc/trpl/concurrency.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ When `guard` goes out of scope, it will block execution until the thread is
8888
finished. If we didn't want this behaviour, we could use `thread::spawn()`:
8989

9090
```
91+
# #![feature(old_io, std_misc)]
9192
use std::thread;
9293
use std::old_io::timer;
9394
use std::time::Duration;
@@ -146,6 +147,7 @@ As an example, here is a Rust program that would have a data race in many
146147
languages. It will not compile:
147148

148149
```ignore
150+
# #![feature(old_io, std_misc)]
149151
use std::thread;
150152
use std::old_io::timer;
151153
use std::time::Duration;
@@ -185,6 +187,7 @@ only one person at a time can mutate what's inside. For that, we can use the
185187
but for a different reason:
186188

187189
```ignore
190+
# #![feature(old_io, std_misc)]
188191
use std::thread;
189192
use std::old_io::timer;
190193
use std::time::Duration;
@@ -229,6 +232,7 @@ guard across thread boundaries, which gives us our error.
229232
We can use `Arc<T>` to fix this. Here's the working version:
230233

231234
```
235+
# #![feature(old_io, std_misc)]
232236
use std::sync::{Arc, Mutex};
233237
use std::thread;
234238
use std::old_io::timer;
@@ -254,6 +258,7 @@ handle is then moved into the new thread. Let's examine the body of the
254258
thread more closely:
255259

256260
```
261+
# #![feature(old_io, std_misc)]
257262
# use std::sync::{Arc, Mutex};
258263
# use std::thread;
259264
# use std::old_io::timer;

src/doc/trpl/ffi.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The following is a minimal example of calling a foreign function which will
1212
compile if snappy is installed:
1313

1414
```no_run
15+
# #![feature(libc)]
1516
extern crate libc;
1617
use libc::size_t;
1718
@@ -45,6 +46,7 @@ keeping the binding correct at runtime.
4546
The `extern` block can be extended to cover the entire snappy API:
4647

4748
```no_run
49+
# #![feature(libc)]
4850
extern crate libc;
4951
use libc::{c_int, size_t};
5052
@@ -80,6 +82,7 @@ length is number of elements currently contained, and the capacity is the total
8082
the allocated memory. The length is less than or equal to the capacity.
8183

8284
```
85+
# #![feature(libc)]
8386
# extern crate libc;
8487
# use libc::{c_int, size_t};
8588
# unsafe fn snappy_validate_compressed_buffer(_: *const u8, _: size_t) -> c_int { 0 }
@@ -104,6 +107,7 @@ required capacity to hold the compressed output. The vector can then be passed t
104107
the true length after compression for setting the length.
105108

106109
```
110+
# #![feature(libc)]
107111
# extern crate libc;
108112
# use libc::{size_t, c_int};
109113
# unsafe fn snappy_compress(a: *const u8, b: size_t, c: *mut u8,
@@ -130,6 +134,7 @@ Decompression is similar, because snappy stores the uncompressed size as part of
130134
format and `snappy_uncompressed_length` will retrieve the exact buffer size required.
131135

132136
```
137+
# #![feature(libc)]
133138
# extern crate libc;
134139
# use libc::{size_t, c_int};
135140
# unsafe fn snappy_uncompress(compressed: *const u8,
@@ -408,6 +413,7 @@ global state. In order to access these variables, you declare them in `extern`
408413
blocks with the `static` keyword:
409414

410415
```no_run
416+
# #![feature(libc)]
411417
extern crate libc;
412418
413419
#[link(name = "readline")]
@@ -426,6 +432,7 @@ interface. To do this, statics can be declared with `mut` so we can mutate
426432
them.
427433

428434
```no_run
435+
# #![feature(libc)]
429436
extern crate libc;
430437
431438
use std::ffi::CString;
@@ -458,6 +465,7 @@ calling foreign functions. Some foreign functions, most notably the Windows API,
458465
conventions. Rust provides a way to tell the compiler which convention to use:
459466

460467
```
468+
# #![feature(libc)]
461469
extern crate libc;
462470
463471
#[cfg(all(target_os = "win32", target_arch = "x86"))]

src/doc/trpl/iterators.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ These two basic iterators should serve you well. There are some more
246246
advanced iterators, including ones that are infinite. Like `count`:
247247

248248
```rust
249+
# #![feature(core)]
249250
std::iter::count(1, 5);
250251
```
251252

@@ -294,6 +295,7 @@ has no side effect on the original iterator. Let's try it out with our infinite
294295
iterator from before, `count()`:
295296

296297
```rust
298+
# #![feature(core)]
297299
for i in std::iter::count(1, 5).take(5) {
298300
println!("{}", i);
299301
}

src/doc/trpl/method-syntax.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ the ability to use this *method call syntax* via the `impl` keyword.
2323
Here's how it works:
2424

2525
```{rust}
26+
# #![feature(core)]
2627
struct Circle {
2728
x: f64,
2829
y: f64,
@@ -87,6 +88,7 @@ original example, `foo.bar().baz()`? This is called 'method chaining', and we
8788
can do it by returning `self`.
8889

8990
```
91+
# #![feature(core)]
9092
struct Circle {
9193
x: f64,
9294
y: f64,
@@ -164,6 +166,7 @@ have method overloading, named arguments, or variable arguments. We employ
164166
the builder pattern instead. It looks like this:
165167

166168
```
169+
# #![feature(core)]
167170
struct Circle {
168171
x: f64,
169172
y: f64,

src/doc/trpl/more-strings.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ Rust provides iterators for each of these situations:
148148
Usually, the `graphemes()` method on `&str` is what you want:
149149

150150
```
151+
# #![feature(unicode)]
151152
let s = "u͔n͈̰̎i̙̮͚̦c͚̉o̼̩̰͗d͔̆̓ͥé";
152153
153154
for l in s.graphemes(true) {

src/doc/trpl/standard-input.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ we haven't seen before. Here's a simple program that reads some input,
55
and then prints it back out:
66

77
```{rust,ignore}
8-
fn main() {
8+
corefn main() {
99
println!("Type something!");
1010
1111
let input = std::old_io::stdin().read_line().ok().expect("Failed to read line");
@@ -28,6 +28,7 @@ Since writing the fully qualified name all the time is annoying, we can use
2828
the `use` statement to import it in:
2929

3030
```{rust}
31+
# #![feature(old_io)]
3132
use std::old_io::stdin;
3233
3334
stdin();
@@ -37,6 +38,7 @@ However, it's considered better practice to not import individual functions, but
3738
to import the module, and only use one level of qualification:
3839

3940
```{rust}
41+
# #![feature(old_io)]
4042
use std::old_io;
4143
4244
old_io::stdin();

src/doc/trpl/testing.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,8 @@ is an opaque "black box" to the optimizer and so forces it to consider any
546546
argument as used.
547547

548548
```rust
549+
# #![feature(test)]
550+
549551
extern crate test;
550552

551553
# fn main() {

src/doc/trpl/traits.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Do you remember the `impl` keyword, used to call a function with method
44
syntax?
55

66
```{rust}
7+
# #![feature(core)]
78
struct Circle {
89
x: f64,
910
y: f64,
@@ -21,6 +22,7 @@ Traits are similar, except that we define a trait with just the method
2122
signature, then implement the trait for that struct. Like this:
2223

2324
```{rust}
25+
# #![feature(core)]
2426
struct Circle {
2527
x: f64,
2628
y: f64,
@@ -84,6 +86,7 @@ which implements `HasArea` will have an `.area()` method.
8486
Here's an extended example of how this works:
8587

8688
```{rust}
89+
# #![feature(core)]
8790
trait HasArea {
8891
fn area(&self) -> f64;
8992
}
@@ -225,6 +228,7 @@ If we add a `use` line right above `main` and make the right things public,
225228
everything is fine:
226229

227230
```{rust}
231+
# #![feature(core)]
228232
use shapes::HasArea;
229233
230234
mod shapes {
@@ -408,6 +412,7 @@ but instead, we found a floating-point variable. We need a different bound. `Flo
408412
to the rescue:
409413

410414
```
415+
# #![feature(std_misc)]
411416
use std::num::Float;
412417
413418
fn inverse<T: Float>(x: T) -> Result<T, String> {
@@ -423,6 +428,7 @@ from the `Float` trait. Both `f32` and `f64` implement `Float`, so our function
423428
works just fine:
424429

425430
```
431+
# #![feature(std_misc)]
426432
# use std::num::Float;
427433
# fn inverse<T: Float>(x: T) -> Result<T, String> {
428434
# if x == Float::zero() { return Err("x cannot be zero!".to_string()) }

src/doc/trpl/unsafe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ As an example, we give a reimplementation of owned boxes by wrapping
187187
reimplementation is as safe as the `Box` type.
188188

189189
```
190+
# #![feature(libc)]
190191
#![feature(unsafe_destructor)]
191192
192193
extern crate libc;
@@ -443,6 +444,7 @@ The function marked `#[start]` is passed the command line parameters
443444
in the same format as C:
444445

445446
```
447+
# #![feature(libc)]
446448
#![feature(lang_items, start, no_std)]
447449
#![no_std]
448450
@@ -470,6 +472,7 @@ correct ABI and the correct name, which requires overriding the
470472
compiler's name mangling too:
471473

472474
```ignore
475+
# #![feature(libc)]
473476
#![feature(no_std)]
474477
#![no_std]
475478
#![no_main]
@@ -526,6 +529,7 @@ As an example, here is a program that will calculate the dot product of two
526529
vectors provided from C, using idiomatic Rust practices.
527530

528531
```
532+
# #![feature(libc, core)]
529533
#![feature(lang_items, start, no_std)]
530534
#![no_std]
531535
@@ -650,6 +654,7 @@ and one for deallocation. A freestanding program that uses the `Box`
650654
sugar for dynamic allocations via `malloc` and `free`:
651655

652656
```
657+
# #![feature(libc)]
653658
#![feature(lang_items, box_syntax, start, no_std)]
654659
#![no_std]
655660

src/liballoc/arc.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ use heap::deallocate;
9595
/// task.
9696
///
9797
/// ```
98+
/// # #![feature(alloc, core)]
9899
/// use std::sync::Arc;
99100
/// use std::thread;
100101
///
@@ -185,6 +186,7 @@ impl<T> Arc<T> {
185186
/// # Examples
186187
///
187188
/// ```
189+
/// # #![feature(alloc)]
188190
/// use std::sync::Arc;
189191
///
190192
/// let five = Arc::new(5);
@@ -246,6 +248,7 @@ impl<T> Clone for Arc<T> {
246248
/// # Examples
247249
///
248250
/// ```
251+
/// # #![feature(alloc)]
249252
/// use std::sync::Arc;
250253
///
251254
/// let five = Arc::new(5);
@@ -289,6 +292,7 @@ impl<T: Send + Sync + Clone> Arc<T> {
289292
/// # Examples
290293
///
291294
/// ```
295+
/// # #![feature(alloc)]
292296
/// use std::sync::Arc;
293297
///
294298
/// let mut five = Arc::new(5);
@@ -324,6 +328,7 @@ impl<T: Sync + Send> Drop for Arc<T> {
324328
/// # Examples
325329
///
326330
/// ```
331+
/// # #![feature(alloc)]
327332
/// use std::sync::Arc;
328333
///
329334
/// {
@@ -387,6 +392,7 @@ impl<T: Sync + Send> Weak<T> {
387392
/// # Examples
388393
///
389394
/// ```
395+
/// # #![feature(alloc)]
390396
/// use std::sync::Arc;
391397
///
392398
/// let five = Arc::new(5);
@@ -424,6 +430,7 @@ impl<T: Sync + Send> Clone for Weak<T> {
424430
/// # Examples
425431
///
426432
/// ```
433+
/// # #![feature(alloc)]
427434
/// use std::sync::Arc;
428435
///
429436
/// let weak_five = Arc::new(5).downgrade();
@@ -448,6 +455,7 @@ impl<T: Sync + Send> Drop for Weak<T> {
448455
/// # Examples
449456
///
450457
/// ```
458+
/// # #![feature(alloc)]
451459
/// use std::sync::Arc;
452460
///
453461
/// {

src/liballoc/boxed.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ use core::raw::TraitObject;
6565
/// The following two examples are equivalent:
6666
///
6767
/// ```
68+
/// # #![feature(alloc)]
6869
/// #![feature(box_syntax)]
6970
/// use std::boxed::HEAP;
7071
///
@@ -135,6 +136,7 @@ impl<T : ?Sized> Box<T> {
135136
///
136137
/// # Examples
137138
/// ```
139+
/// # #![feature(alloc)]
138140
/// use std::boxed;
139141
///
140142
/// let seventeen = Box::new(17u32);
@@ -178,6 +180,7 @@ impl<T: Clone> Clone for Box<T> {
178180
/// # Examples
179181
///
180182
/// ```
183+
/// # #![feature(alloc, core)]
181184
/// let x = Box::new(5);
182185
/// let mut y = Box::new(10);
183186
///

0 commit comments

Comments
 (0)