diff --git a/mk/docs.mk b/mk/docs.mk index 90f85079464bb..dab40cb165431 100644 --- a/mk/docs.mk +++ b/mk/docs.mk @@ -43,7 +43,9 @@ L10N_LANGS := ja # The options are passed to the documentation generators. RUSTDOC_HTML_OPTS_NO_CSS = --markdown-before-content=doc/version_info.html \ - --markdown-in-header=doc/favicon.inc --markdown-after-content=doc/footer.inc + --markdown-in-header=doc/favicon.inc \ + --markdown-after-content=doc/footer.inc \ + --markdown-playground-url='http://play.rust-lang.org/' RUSTDOC_HTML_OPTS = $(RUSTDOC_HTML_OPTS_NO_CSS) --markdown-css rust.css diff --git a/mk/tests.mk b/mk/tests.mk index c67fa0042f814..dacea3a4bfc49 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -818,7 +818,7 @@ endif ifeq ($(2),$$(CFG_BUILD)) $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)): $$(CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4)) @$$(call E, run doc-crate-$(4) [$(2)]) - $$(Q)$$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --test \ + $$(Q)$$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --test --cfg dox \ $$(CRATEFILE_$(4)) --test-args "$$(TESTARGS)" && touch $$@ else $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)): diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 10428244b7115..8da984a414bda 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -1545,7 +1545,7 @@ fn disassemble_extract(config: &Config, _props: &TestProps, fn count_extracted_lines(p: &Path) -> uint { let x = File::open(&p.with_extension("ll")).read_to_end().unwrap(); let x = str::from_utf8(x.as_slice()).unwrap(); - x.lines().len() + x.lines().count() } diff --git a/src/doc/footer.inc b/src/doc/footer.inc index a103a4908f6bf..4e7d60586f23d 100644 --- a/src/doc/footer.inc +++ b/src/doc/footer.inc @@ -5,3 +5,5 @@ or the MIT license, at your opt
This file may not be copied, modified, or distributed except according to those terms.
+ + diff --git a/src/doc/guide-macros.md b/src/doc/guide-macros.md index b86a6aa1b619c..45745c7b7bc7a 100644 --- a/src/doc/guide-macros.md +++ b/src/doc/guide-macros.md @@ -11,7 +11,7 @@ which both pattern-match on their input and both return early in one case, doing nothing otherwise: ~~~~ -# enum T { SpecialA(uint), SpecialB(uint) }; +# enum T { SpecialA(uint), SpecialB(uint) } # fn f() -> uint { # let input_1 = 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: ~~~~ -# enum T { SpecialA(uint), SpecialB(uint) }; +# #![feature(macro_rules)] +# enum T { SpecialA(uint), SpecialB(uint) } # fn f() -> uint { # let input_1 = SpecialA(0); # let input_2 = SpecialA(0); @@ -55,6 +56,7 @@ early_return!(input_1 SpecialA); early_return!(input_2 SpecialB); # return 0; # } +# fn main() {} ~~~~ 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". ~~~~ -# 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 { # let input_1 = SpecialA(0); # let input_2 = SpecialA(0); @@ -175,6 +178,7 @@ early_return!(input_1, [SpecialA|SpecialC|SpecialD]); early_return!(input_2, [SpecialB]); # return 0; # } +# fn main() {} ~~~~ ### Transcription @@ -215,9 +219,10 @@ solves the problem. 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 } -# enum T3 { Good2(uint), Bad2}; +# enum T3 { Good2(uint), Bad2} # fn f(x: T1) -> uint { match x { Good1(g1, val) => { @@ -232,6 +237,7 @@ match x { _ => return 0 // default value } # } +# fn main() {} ~~~~ 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: ~~~~ +# #![feature(macro_rules)] macro_rules! biased_match ( // special case: `let (x) = ...` is illegal, so use `let x = ...` instead ( ($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 } -# enum T3 { Good2(uint), Bad2}; +# enum T3 { Good2(uint), Bad2} # fn f(x: T1) -> uint { biased_match!((x) ~ (Good1(g1, val)) else { return 0 }; binds g1, val ) @@ -273,6 +280,7 @@ biased_match!((g1.body) ~ (Good2(result) ) // complicated stuff goes here return result + val; # } +# fn main() {} ~~~~ 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: ~~~~ +# #![feature(macro_rules)] +# fn main() {} # macro_rules! b( ( $( ($e:expr) ~ ($p:pat) else $err:stmt ; )* binds $( $bind_res:ident ),* @@ -301,14 +311,18 @@ process the semicolon-terminated lines, one-by-one. So, we want the following input patterns: ~~~~ +# #![feature(macro_rules)] # macro_rules! b( ( binds $( $bind_res:ident ),* ) # => (0)) +# fn main() {} ~~~~ ...and: ~~~~ +# #![feature(macro_rules)] +# fn main() {} # macro_rules! b( ( ($e :expr) ~ ($p :pat) else $err :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. ~~~~ +# #![feature(macro_rules)] +# fn main() { macro_rules! biased_match_rec ( // 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 } -# enum T3 { Good2(uint), Bad2}; +# enum T3 { Good2(uint), Bad2} # fn f(x: T1) -> uint { biased_match!( (x) ~ (Good1(g1, val)) else { return 0 }; @@ -376,6 +392,7 @@ biased_match!( // complicated stuff goes here return result + val; # } +# } ~~~~ This technique applies to many cases where transcribing a result all at once is not possible. diff --git a/src/doc/guide-unsafe.md b/src/doc/guide-unsafe.md index e0a48682963b4..1431c8a5c9ae4 100644 --- a/src/doc/guide-unsafe.md +++ b/src/doc/guide-unsafe.md @@ -523,6 +523,7 @@ vectors provided from C, using idiomatic Rust practices. ``` #![no_std] +#![feature(globs)] # extern crate libc; extern crate core; diff --git a/src/doc/rust.css b/src/doc/rust.css index d60dd54a67d14..3957231a195a5 100644 --- a/src/doc/rust.css +++ b/src/doc/rust.css @@ -313,6 +313,19 @@ table th { padding: 5px; } +/* Code snippets */ + +.rusttest { display: none; } +pre.rust { position: relative; } +pre.rust a { transform: scaleX(-1); } +.test-arrow { + display: inline-block; + position: absolute; + top: 0; + right: 10px; + font-size: 150%; +} + @media (min-width: 1170px) { pre { font-size: 15px; diff --git a/src/doc/rust.md b/src/doc/rust.md index 06c9da2fe0e5a..619e24af36063 100644 --- a/src/doc/rust.md +++ b/src/doc/rust.md @@ -1260,6 +1260,8 @@ a = Cat; Enumeration constructors can have either named or unnamed fields: ~~~~ +# #![feature(struct_variant)] +# fn main() { enum Animal { Dog (String, f64), Cat { name: String, weight: f64 } @@ -1267,6 +1269,7 @@ enum Animal { let mut a: Animal = Dog("Cocoa".to_string(), 37.2); a = Cat { name: "Spotty".to_string(), weight: 2.7 }; +# } ~~~~ In this example, `Cat` is a _struct-like enum variant_, diff --git a/src/doc/tutorial.md b/src/doc/tutorial.md index 917704a2faacd..3b4164ffbc618 100644 --- a/src/doc/tutorial.md +++ b/src/doc/tutorial.md @@ -774,6 +774,7 @@ fn point_from_direction(dir: Direction) -> Point { Enum variants may also be structs. For example: ~~~~ +# #![feature(struct_variant)] use std::f64; # struct Point { x: f64, y: f64 } # 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 @@ -3046,6 +3048,7 @@ use farm::{chicken, cow}; 2. Import everything in a module with a wildcard: ~~~ +# #![feature(globs)] use farm::*; # mod farm { # pub fn cow() { println!("Bat-chicken? What a stupid name!") } diff --git a/src/libcollections/bitv.rs b/src/libcollections/bitv.rs index 11c777034fe6e..58f081b25e3e5 100644 --- a/src/libcollections/bitv.rs +++ b/src/libcollections/bitv.rs @@ -241,17 +241,17 @@ enum Op {Union, Intersect, Assign, Difference} /// bv.set(5, true); /// bv.set(7, true); /// println!("{}", bv.to_str()); -/// println!("total bits set to true: {}", bv.iter().count(|x| x)); +/// println!("total bits set to true: {}", bv.iter().filter(|x| *x).count()); /// /// // flip all values in bitvector, producing non-primes less than 10 /// bv.negate(); /// println!("{}", bv.to_str()); -/// println!("total bits set to true: {}", bv.iter().count(|x| x)); +/// println!("total bits set to true: {}", bv.iter().filter(|x| *x).count()); /// /// // reset bitvector to empty /// bv.clear(); /// println!("{}", bv.to_str()); -/// println!("total bits set to true: {}", bv.iter().count(|x| x)); +/// println!("total bits set to true: {}", bv.iter().filter(|x| *x).count()); /// ``` #[deriving(Clone)] pub struct Bitv { @@ -461,7 +461,7 @@ impl Bitv { /// bv.set(5, true); /// bv.set(8, true); /// // Count bits set to 1; result should be 5 - /// println!("{}", bv.iter().count(|x| x)); + /// println!("{}", bv.iter().filter(|x| *x).count()); /// ``` #[inline] pub fn iter<'a>(&'a self) -> Bits<'a> { diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index 8e3a49eecf339..94c617b58e8d2 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -1131,7 +1131,7 @@ mod tests { let v = &[0, ..128]; let m: DList\n", class.unwrap_or(""))); + try!(write!(out, "try!(write!(out, "id='{}' ", id)), + None => {} + } + try!(write!(out, "class='rust {}'>\n", class.unwrap_or(""))); let mut last = BytePos(0); let mut is_attribute = false; let mut is_macro = false; diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index 80653878247fa..e2fa57148c2c7 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -16,6 +16,7 @@ pub struct Layout { pub logo: String, pub favicon: String, pub krate: String, + pub playground_url: String, } pub struct Page<'a> { @@ -108,11 +109,13 @@ r##" + {play_js}