doc: Turn off special features for rustdoc tests
These were only used for the markdown tests, and there's no reason they should be distinct from the other tests.
This commit is contained in:
parent
5915763106
commit
cc63d4c61b
6 changed files with 39 additions and 28 deletions
|
@ -11,7 +11,7 @@ which both pattern-match on their input and both return early in one case,
|
||||||
doing nothing otherwise:
|
doing nothing otherwise:
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
# enum T { SpecialA(uint), SpecialB(uint) };
|
# enum T { SpecialA(uint), SpecialB(uint) }
|
||||||
# fn f() -> uint {
|
# fn f() -> uint {
|
||||||
# let input_1 = SpecialA(0);
|
# let input_1 = SpecialA(0);
|
||||||
# let input_2 = SpecialA(0);
|
# let input_2 = SpecialA(0);
|
||||||
|
@ -37,7 +37,8 @@ lightweight custom syntax extensions, themselves defined using the
|
||||||
the pattern in the above code:
|
the pattern in the above code:
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
# enum T { SpecialA(uint), SpecialB(uint) };
|
# #![feature(macro_rules)]
|
||||||
|
# enum T { SpecialA(uint), SpecialB(uint) }
|
||||||
# fn f() -> uint {
|
# fn f() -> uint {
|
||||||
# let input_1 = SpecialA(0);
|
# let input_1 = SpecialA(0);
|
||||||
# let input_2 = SpecialA(0);
|
# let input_2 = SpecialA(0);
|
||||||
|
@ -55,6 +56,7 @@ early_return!(input_1 SpecialA);
|
||||||
early_return!(input_2 SpecialB);
|
early_return!(input_2 SpecialB);
|
||||||
# return 0;
|
# return 0;
|
||||||
# }
|
# }
|
||||||
|
# fn main() {}
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
Macros are defined in pattern-matching style: in the above example, the text
|
Macros are defined in pattern-matching style: in the above example, the text
|
||||||
|
@ -155,7 +157,8 @@ separator token (a comma-separated list could be written `$(...),*`), and `+`
|
||||||
instead of `*` to mean "at least one".
|
instead of `*` to mean "at least one".
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
# enum T { SpecialA(uint),SpecialB(uint),SpecialC(uint),SpecialD(uint)};
|
# #![feature(macro_rules)]
|
||||||
|
# enum T { SpecialA(uint),SpecialB(uint),SpecialC(uint),SpecialD(uint)}
|
||||||
# fn f() -> uint {
|
# fn f() -> uint {
|
||||||
# let input_1 = SpecialA(0);
|
# let input_1 = SpecialA(0);
|
||||||
# let input_2 = SpecialA(0);
|
# let input_2 = SpecialA(0);
|
||||||
|
@ -175,6 +178,7 @@ early_return!(input_1, [SpecialA|SpecialC|SpecialD]);
|
||||||
early_return!(input_2, [SpecialB]);
|
early_return!(input_2, [SpecialB]);
|
||||||
# return 0;
|
# return 0;
|
||||||
# }
|
# }
|
||||||
|
# fn main() {}
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
### Transcription
|
### Transcription
|
||||||
|
@ -215,9 +219,10 @@ solves the problem.
|
||||||
Now consider code like the following:
|
Now consider code like the following:
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
# enum T1 { Good1(T2, uint), Bad1};
|
# #![feature(macro_rules)]
|
||||||
|
# enum T1 { Good1(T2, uint), Bad1}
|
||||||
# struct T2 { body: T3 }
|
# struct T2 { body: T3 }
|
||||||
# enum T3 { Good2(uint), Bad2};
|
# enum T3 { Good2(uint), Bad2}
|
||||||
# fn f(x: T1) -> uint {
|
# fn f(x: T1) -> uint {
|
||||||
match x {
|
match x {
|
||||||
Good1(g1, val) => {
|
Good1(g1, val) => {
|
||||||
|
@ -232,6 +237,7 @@ match x {
|
||||||
_ => return 0 // default value
|
_ => return 0 // default value
|
||||||
}
|
}
|
||||||
# }
|
# }
|
||||||
|
# fn main() {}
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
All the complicated stuff is deeply indented, and the error-handling code is
|
All the complicated stuff is deeply indented, and the error-handling code is
|
||||||
|
@ -240,6 +246,7 @@ a match, but with a syntax that suits the problem better. The following macro
|
||||||
can solve the problem:
|
can solve the problem:
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
|
# #![feature(macro_rules)]
|
||||||
macro_rules! biased_match (
|
macro_rules! biased_match (
|
||||||
// special case: `let (x) = ...` is illegal, so use `let x = ...` instead
|
// special case: `let (x) = ...` is illegal, so use `let x = ...` instead
|
||||||
( ($e:expr) ~ ($p:pat) else $err:stmt ;
|
( ($e:expr) ~ ($p:pat) else $err:stmt ;
|
||||||
|
@ -261,9 +268,9 @@ macro_rules! biased_match (
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# enum T1 { Good1(T2, uint), Bad1};
|
# enum T1 { Good1(T2, uint), Bad1}
|
||||||
# struct T2 { body: T3 }
|
# struct T2 { body: T3 }
|
||||||
# enum T3 { Good2(uint), Bad2};
|
# enum T3 { Good2(uint), Bad2}
|
||||||
# fn f(x: T1) -> uint {
|
# fn f(x: T1) -> uint {
|
||||||
biased_match!((x) ~ (Good1(g1, val)) else { return 0 };
|
biased_match!((x) ~ (Good1(g1, val)) else { return 0 };
|
||||||
binds g1, val )
|
binds g1, val )
|
||||||
|
@ -273,6 +280,7 @@ biased_match!((g1.body) ~ (Good2(result) )
|
||||||
// complicated stuff goes here
|
// complicated stuff goes here
|
||||||
return result + val;
|
return result + val;
|
||||||
# }
|
# }
|
||||||
|
# fn main() {}
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
This solves the indentation problem. But if we have a lot of chained matches
|
This solves the indentation problem. But if we have a lot of chained matches
|
||||||
|
@ -280,6 +288,8 @@ like this, we might prefer to write a single macro invocation. The input
|
||||||
pattern we want is clear:
|
pattern we want is clear:
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
|
# #![feature(macro_rules)]
|
||||||
|
# fn main() {}
|
||||||
# macro_rules! b(
|
# macro_rules! b(
|
||||||
( $( ($e:expr) ~ ($p:pat) else $err:stmt ; )*
|
( $( ($e:expr) ~ ($p:pat) else $err:stmt ; )*
|
||||||
binds $( $bind_res:ident ),*
|
binds $( $bind_res:ident ),*
|
||||||
|
@ -301,14 +311,18 @@ process the semicolon-terminated lines, one-by-one. So, we want the following
|
||||||
input patterns:
|
input patterns:
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
|
# #![feature(macro_rules)]
|
||||||
# macro_rules! b(
|
# macro_rules! b(
|
||||||
( binds $( $bind_res:ident ),* )
|
( binds $( $bind_res:ident ),* )
|
||||||
# => (0))
|
# => (0))
|
||||||
|
# fn main() {}
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
...and:
|
...and:
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
|
# #![feature(macro_rules)]
|
||||||
|
# fn main() {}
|
||||||
# macro_rules! b(
|
# macro_rules! b(
|
||||||
( ($e :expr) ~ ($p :pat) else $err :stmt ;
|
( ($e :expr) ~ ($p :pat) else $err :stmt ;
|
||||||
$( ($e_rest:expr) ~ ($p_rest:pat) else $err_rest:stmt ; )*
|
$( ($e_rest:expr) ~ ($p_rest:pat) else $err_rest:stmt ; )*
|
||||||
|
@ -322,6 +336,8 @@ The resulting macro looks like this. Note that the separation into
|
||||||
piece of syntax (the `let`) which we only want to transcribe once.
|
piece of syntax (the `let`) which we only want to transcribe once.
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
|
# #![feature(macro_rules)]
|
||||||
|
# fn main() {
|
||||||
|
|
||||||
macro_rules! biased_match_rec (
|
macro_rules! biased_match_rec (
|
||||||
// Handle the first layer
|
// Handle the first layer
|
||||||
|
@ -365,9 +381,9 @@ macro_rules! biased_match (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# enum T1 { Good1(T2, uint), Bad1};
|
# enum T1 { Good1(T2, uint), Bad1}
|
||||||
# struct T2 { body: T3 }
|
# struct T2 { body: T3 }
|
||||||
# enum T3 { Good2(uint), Bad2};
|
# enum T3 { Good2(uint), Bad2}
|
||||||
# fn f(x: T1) -> uint {
|
# fn f(x: T1) -> uint {
|
||||||
biased_match!(
|
biased_match!(
|
||||||
(x) ~ (Good1(g1, val)) else { return 0 };
|
(x) ~ (Good1(g1, val)) else { return 0 };
|
||||||
|
@ -376,6 +392,7 @@ biased_match!(
|
||||||
// complicated stuff goes here
|
// complicated stuff goes here
|
||||||
return result + val;
|
return result + val;
|
||||||
# }
|
# }
|
||||||
|
# }
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
This technique applies to many cases where transcribing a result all at once is not possible.
|
This technique applies to many cases where transcribing a result all at once is not possible.
|
||||||
|
|
|
@ -523,6 +523,7 @@ vectors provided from C, using idiomatic Rust practices.
|
||||||
|
|
||||||
```
|
```
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
#![feature(globs)]
|
||||||
|
|
||||||
# extern crate libc;
|
# extern crate libc;
|
||||||
extern crate core;
|
extern crate core;
|
||||||
|
|
|
@ -1260,6 +1260,8 @@ a = Cat;
|
||||||
Enumeration constructors can have either named or unnamed fields:
|
Enumeration constructors can have either named or unnamed fields:
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
|
# #![feature(struct_variant)]
|
||||||
|
# fn main() {
|
||||||
enum Animal {
|
enum Animal {
|
||||||
Dog (String, f64),
|
Dog (String, f64),
|
||||||
Cat { name: String, weight: f64 }
|
Cat { name: String, weight: f64 }
|
||||||
|
@ -1267,6 +1269,7 @@ enum Animal {
|
||||||
|
|
||||||
let mut a: Animal = Dog("Cocoa".to_string(), 37.2);
|
let mut a: Animal = Dog("Cocoa".to_string(), 37.2);
|
||||||
a = Cat { name: "Spotty".to_string(), weight: 2.7 };
|
a = Cat { name: "Spotty".to_string(), weight: 2.7 };
|
||||||
|
# }
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
In this example, `Cat` is a _struct-like enum variant_,
|
In this example, `Cat` is a _struct-like enum variant_,
|
||||||
|
|
|
@ -774,6 +774,7 @@ fn point_from_direction(dir: Direction) -> Point {
|
||||||
Enum variants may also be structs. For example:
|
Enum variants may also be structs. For example:
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
|
# #![feature(struct_variant)]
|
||||||
use std::f64;
|
use std::f64;
|
||||||
# struct Point { x: f64, y: f64 }
|
# struct Point { x: f64, y: f64 }
|
||||||
# fn square(x: f64) -> f64 { x * x }
|
# fn square(x: f64) -> f64 { x * x }
|
||||||
|
@ -789,6 +790,7 @@ fn area(sh: Shape) -> f64 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
# fn main() {}
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
> *Note:* This feature of the compiler is currently gated behind the
|
> *Note:* This feature of the compiler is currently gated behind the
|
||||||
|
@ -3046,6 +3048,7 @@ use farm::{chicken, cow};
|
||||||
2. Import everything in a module with a wildcard:
|
2. Import everything in a module with a wildcard:
|
||||||
|
|
||||||
~~~
|
~~~
|
||||||
|
# #![feature(globs)]
|
||||||
use farm::*;
|
use farm::*;
|
||||||
# mod farm {
|
# mod farm {
|
||||||
# pub fn cow() { println!("Bat-chicken? What a stupid name!") }
|
# pub fn cow() { println!("Bat-chicken? What a stupid name!") }
|
||||||
|
|
|
@ -173,7 +173,7 @@ pub fn render(input: &str, mut output: Path, matches: &getopts::Matches) -> int
|
||||||
pub fn test(input: &str, libs: HashSet<Path>, mut test_args: Vec<String>) -> int {
|
pub fn test(input: &str, libs: HashSet<Path>, mut test_args: Vec<String>) -> int {
|
||||||
let input_str = load_or_return!(input, 1, 2);
|
let input_str = load_or_return!(input, 1, 2);
|
||||||
|
|
||||||
let mut collector = Collector::new(input.to_string(), libs, true, true);
|
let mut collector = Collector::new(input.to_string(), libs, true);
|
||||||
find_testable_code(input_str.as_slice(), &mut collector);
|
find_testable_code(input_str.as_slice(), &mut collector);
|
||||||
test_args.unshift("rustdoctest".to_string());
|
test_args.unshift("rustdoctest".to_string());
|
||||||
testing::test_main(test_args.as_slice(), collector.tests);
|
testing::test_main(test_args.as_slice(), collector.tests);
|
||||||
|
|
|
@ -91,7 +91,6 @@ pub fn run(input: &str,
|
||||||
|
|
||||||
let mut collector = Collector::new(krate.name.to_string(),
|
let mut collector = Collector::new(krate.name.to_string(),
|
||||||
libs,
|
libs,
|
||||||
false,
|
|
||||||
false);
|
false);
|
||||||
collector.fold_crate(krate);
|
collector.fold_crate(krate);
|
||||||
|
|
||||||
|
@ -103,8 +102,8 @@ pub fn run(input: &str,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool,
|
fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool,
|
||||||
no_run: bool, loose_feature_gating: bool) {
|
no_run: bool) {
|
||||||
let test = maketest(test, cratename, loose_feature_gating);
|
let test = maketest(test, cratename);
|
||||||
let input = driver::StrInput(test.to_string());
|
let input = driver::StrInput(test.to_string());
|
||||||
|
|
||||||
let sessopts = config::Options {
|
let sessopts = config::Options {
|
||||||
|
@ -201,18 +200,12 @@ fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn maketest(s: &str, cratename: &str, loose_feature_gating: bool) -> String {
|
pub fn maketest(s: &str, cratename: &str) -> String {
|
||||||
let mut prog = String::from_str(r"
|
let mut prog = String::from_str(r"
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
#![allow(unused_variable, dead_assignment, unused_mut, attribute_usage, dead_code)]
|
#![allow(unused_variable, dead_assignment, unused_mut, attribute_usage, dead_code)]
|
||||||
");
|
");
|
||||||
|
|
||||||
if loose_feature_gating {
|
|
||||||
// FIXME #12773: avoid inserting these when the tutorial & manual
|
|
||||||
// etc. have been updated to not use them so prolifically.
|
|
||||||
prog.push_str("#![feature(macro_rules, globs, struct_variant, managed_boxes) ]\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if !s.contains("extern crate") {
|
if !s.contains("extern crate") {
|
||||||
if s.contains(cratename) {
|
if s.contains(cratename) {
|
||||||
prog.push_str(format!("extern crate {};\n",
|
prog.push_str(format!("extern crate {};\n",
|
||||||
|
@ -238,13 +231,11 @@ pub struct Collector {
|
||||||
use_headers: bool,
|
use_headers: bool,
|
||||||
current_header: Option<String>,
|
current_header: Option<String>,
|
||||||
cratename: String,
|
cratename: String,
|
||||||
|
|
||||||
loose_feature_gating: bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Collector {
|
impl Collector {
|
||||||
pub fn new(cratename: String, libs: HashSet<Path>,
|
pub fn new(cratename: String, libs: HashSet<Path>,
|
||||||
use_headers: bool, loose_feature_gating: bool) -> Collector {
|
use_headers: bool) -> Collector {
|
||||||
Collector {
|
Collector {
|
||||||
tests: Vec::new(),
|
tests: Vec::new(),
|
||||||
names: Vec::new(),
|
names: Vec::new(),
|
||||||
|
@ -253,8 +244,6 @@ impl Collector {
|
||||||
use_headers: use_headers,
|
use_headers: use_headers,
|
||||||
current_header: None,
|
current_header: None,
|
||||||
cratename: cratename,
|
cratename: cratename,
|
||||||
|
|
||||||
loose_feature_gating: loose_feature_gating
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,7 +257,6 @@ impl Collector {
|
||||||
self.cnt += 1;
|
self.cnt += 1;
|
||||||
let libs = self.libs.clone();
|
let libs = self.libs.clone();
|
||||||
let cratename = self.cratename.to_string();
|
let cratename = self.cratename.to_string();
|
||||||
let loose_feature_gating = self.loose_feature_gating;
|
|
||||||
debug!("Creating test {}: {}", name, test);
|
debug!("Creating test {}: {}", name, test);
|
||||||
self.tests.push(testing::TestDescAndFn {
|
self.tests.push(testing::TestDescAndFn {
|
||||||
desc: testing::TestDesc {
|
desc: testing::TestDesc {
|
||||||
|
@ -281,8 +269,7 @@ impl Collector {
|
||||||
cratename.as_slice(),
|
cratename.as_slice(),
|
||||||
libs,
|
libs,
|
||||||
should_fail,
|
should_fail,
|
||||||
no_run,
|
no_run);
|
||||||
loose_feature_gating);
|
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue