Skip to content

Rolling up PRs in the queue #14712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mk/docs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion mk/tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}


Expand Down
2 changes: 2 additions & 0 deletions src/doc/footer.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ or the <a href="http://opensource.org/licenses/MIT">MIT license</a>, at your opt
</p><p>
This file may not be copied, modified, or distributed except according to those terms.
</p></footer>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="playpen.js"></script>
35 changes: 26 additions & 9 deletions src/doc/guide-macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -175,6 +178,7 @@ early_return!(input_1, [SpecialA|SpecialC|SpecialD]);
early_return!(input_2, [SpecialB]);
# return 0;
# }
# fn main() {}
~~~~

### Transcription
Expand Down Expand Up @@ -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) => {
Expand All @@ -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
Expand All @@ -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 ;
Expand All @@ -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 )
Expand All @@ -273,13 +280,16 @@ 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
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 ),*
Expand All @@ -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 ; )*
Expand All @@ -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
Expand Down Expand Up @@ -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 };
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/doc/guide-unsafe.md
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ vectors provided from C, using idiomatic Rust practices.

```
#![no_std]
#![feature(globs)]

# extern crate libc;
extern crate core;
Expand Down
13 changes: 13 additions & 0 deletions src/doc/rust.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -1260,13 +1260,16 @@ 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 }
}

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_,
Expand Down
3 changes: 3 additions & 0 deletions src/doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -789,6 +790,7 @@ fn area(sh: Shape) -> f64 {
}
}
}
# fn main() {}
~~~~

> *Note:* This feature of the compiler is currently gated behind the
Expand Down Expand Up @@ -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!") }
Expand Down
8 changes: 4 additions & 4 deletions src/libcollections/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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> {
Expand Down
8 changes: 4 additions & 4 deletions src/libcollections/dlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1131,31 +1131,31 @@ mod tests {
let v = &[0, ..128];
let m: DList<int> = v.iter().map(|&x|x).collect();
b.iter(|| {
assert!(m.iter().len() == 128);
assert!(m.iter().count() == 128);
})
}
#[bench]
fn bench_iter_mut(b: &mut test::Bencher) {
let v = &[0, ..128];
let mut m: DList<int> = v.iter().map(|&x|x).collect();
b.iter(|| {
assert!(m.mut_iter().len() == 128);
assert!(m.mut_iter().count() == 128);
})
}
#[bench]
fn bench_iter_rev(b: &mut test::Bencher) {
let v = &[0, ..128];
let m: DList<int> = v.iter().map(|&x|x).collect();
b.iter(|| {
assert!(m.iter().rev().len() == 128);
assert!(m.iter().rev().count() == 128);
})
}
#[bench]
fn bench_iter_mut_rev(b: &mut test::Bencher) {
let v = &[0, ..128];
let mut m: DList<int> = v.iter().map(|&x|x).collect();
b.iter(|| {
assert!(m.mut_iter().rev().len() == 128);
assert!(m.mut_iter().rev().count() == 128);
})
}
}
3 changes: 2 additions & 1 deletion src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
#![license = "MIT/ASL2"]
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/")]
html_root_url = "http://doc.rust-lang.org/",
html_playground_url = "http://play.rust-lang.org/")]

#![feature(macro_rules, managed_boxes, default_type_params, phase, globs)]
#![no_std]
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2155,7 +2155,7 @@ mod tests {
#[test]
fn test_mut_splitator() {
let mut xs = [0,1,0,2,3,0,0,4,5,0];
assert_eq!(xs.mut_split(|x| *x == 0).len(), 6);
assert_eq!(xs.mut_split(|x| *x == 0).count(), 6);
for slice in xs.mut_split(|x| *x == 0) {
slice.reverse();
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/smallintmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct SmallIntMap<T> {
impl<V> Container for SmallIntMap<V> {
/// Return the number of elements in the map
fn len(&self) -> uint {
self.v.iter().count(|elt| elt.is_some())
self.v.iter().filter(|elt| elt.is_some()).count()
}

/// Return true if there are no elements in the map
Expand Down
Loading