Skip to content

Commit f71208a

Browse files
committed
---
yaml --- r: 148443 b: refs/heads/try2 c: cf56624 h: refs/heads/master i: 148441: b2ac674 148439: bdae902 v: v3
1 parent da96f0f commit f71208a

File tree

22 files changed

+136
-223
lines changed

22 files changed

+136
-223
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: f8efde148c05d0603f1a4ef60764c1910db20181
8+
refs/heads/try2: cf56624a4ad7703c8f3fc327b8c385da0a803ea5
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/doc/guide-testing.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
3333
# Unit testing in Rust
3434

3535
Rust has built in support for simple unit testing. Functions can be
36-
marked as unit tests using the `test` attribute.
36+
marked as unit tests using the 'test' attribute.
3737

3838
~~~
3939
#[test]
@@ -44,13 +44,13 @@ fn return_none_if_empty() {
4444

4545
A test function's signature must have no arguments and no return
4646
value. To run the tests in a crate, it must be compiled with the
47-
`--test` flag: `rustc myprogram.rs --test -o myprogram-tests`. Running
47+
'--test' flag: `rustc myprogram.rs --test -o myprogram-tests`. Running
4848
the resulting executable will run all the tests in the crate. A test
4949
is considered successful if its function returns; if the task running
5050
the test fails, through a call to `fail!`, a failed `check` or
5151
`assert`, or some other (`assert_eq`, ...) means, then the test fails.
5252

53-
When compiling a crate with the `--test` flag `--cfg test` is also
53+
When compiling a crate with the '--test' flag '--cfg test' is also
5454
implied, so that tests can be conditionally compiled.
5555

5656
~~~
@@ -64,17 +64,17 @@ mod tests {
6464
~~~
6565

6666
Additionally `#[test]` items behave as if they also have the
67-
`#[cfg(test)]` attribute, and will not be compiled when the `--test` flag
67+
`#[cfg(test)]` attribute, and will not be compiled when the --test flag
6868
is not used.
6969

70-
Tests that should not be run can be annotated with the `ignore`
70+
Tests that should not be run can be annotated with the 'ignore'
7171
attribute. The existence of these tests will be noted in the test
7272
runner output, but the test will not be run. Tests can also be ignored
7373
by configuration so, for example, to ignore a test on windows you can
7474
write `#[ignore(cfg(target_os = "win32"))]`.
7575

7676
Tests that are intended to fail can be annotated with the
77-
`should_fail` attribute. The test will be run, and if it causes its
77+
'should_fail' attribute. The test will be run, and if it causes its
7878
task to fail then the test will be counted as successful; otherwise it
7979
will be counted as a failure. For example:
8080

@@ -87,11 +87,11 @@ fn test_out_of_bounds_failure() {
8787
}
8888
~~~
8989

90-
A test runner built with the `--test` flag supports a limited set of
90+
A test runner built with the '--test' flag supports a limited set of
9191
arguments to control which tests are run: the first free argument
9292
passed to a test runner specifies a filter used to narrow down the set
93-
of tests being run; the `--ignored` flag tells the test runner to run
94-
only tests with the `ignore` attribute.
93+
of tests being run; the '--ignored' flag tells the test runner to run
94+
only tests with the 'ignore' attribute.
9595

9696
## Parallelism
9797

branches/try2/src/compiletest/runtest.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,9 @@ actual:\n\
237237

238238
fn make_typecheck_args(config: &config, props: &TestProps, testfile: &Path) -> ProcArgs {
239239
let aux_dir = aux_output_dir_name(config, testfile);
240-
let target = if props.force_host {
241-
config.host.as_slice()
242-
} else {
243-
config.target.as_slice()
244-
};
245240
// FIXME (#9639): This needs to handle non-utf8 paths
246241
let mut args = ~[~"-",
247242
~"--no-trans", ~"--lib",
248-
~"--target=" + target,
249243
~"-L", config.build_base.as_str().unwrap().to_owned(),
250244
~"-L",
251245
aux_dir.as_str().unwrap().to_owned()];

branches/try2/src/libextra/base64.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,8 @@ impl<'a> FromBase64 for &'a str {
237237
}
238238

239239
for (idx, byte) in it {
240-
match byte as char {
241-
'='|'\r'|'\n' => continue,
242-
_ => return Err(InvalidBase64Character(self.char_at(idx), idx)),
240+
if (byte as char) != '=' {
241+
return Err(InvalidBase64Character(self.char_at(idx), idx));
243242
}
244243
}
245244

@@ -311,8 +310,6 @@ mod test {
311310
fn test_from_base64_newlines() {
312311
assert_eq!("Zm9v\r\nYmFy".from_base64().unwrap(),
313312
"foobar".as_bytes().to_owned());
314-
assert_eq!("Zm9vYg==\r\n".from_base64().unwrap(),
315-
"foob".as_bytes().to_owned());
316313
}
317314
318315
#[test]

branches/try2/src/libextra/uuid.rs

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Examples of string representations:
5757

5858
use std::str;
5959
use std::vec;
60-
use std::num::{FromStrRadix, Zero};
60+
use std::num::FromStrRadix;
6161
use std::char::Char;
6262
use std::container::Container;
6363
use std::to_str::ToStr;
@@ -158,9 +158,8 @@ static UuidGroupLens: [uint, ..5] = [8u, 4u, 4u, 4u, 12u];
158158

159159
/// UUID support
160160
impl Uuid {
161-
162161
/// Returns a nil or empty UUID (containing all zeroes)
163-
pub fn new_nil() -> Uuid {
162+
pub fn nil() -> Uuid {
164163
let uuid = Uuid{ bytes: [0, .. 16] };
165164
uuid
166165
}
@@ -423,24 +422,17 @@ impl Uuid {
423422

424423
Ok(Uuid::from_bytes(ub).unwrap())
425424
}
426-
}
427425

428-
impl Default for Uuid {
429-
/// Returns the nil UUID, which is all zeroes
430-
fn default() -> Uuid {
431-
Uuid::new_nil()
426+
/// Tests if the UUID is nil
427+
pub fn is_nil(&self) -> bool {
428+
return self.bytes.iter().all(|&b| b == 0);
432429
}
433430
}
434431

435-
impl Zero for Uuid {
432+
impl Default for Uuid {
436433
/// Returns the nil UUID, which is all zeroes
437-
fn zero() -> Uuid {
438-
Uuid::new_nil()
439-
}
440-
441-
/// Tests if the UUID is nil or all zeroes
442-
fn is_zero(&self) -> bool {
443-
return self.bytes.iter().all(|&b| b == 0);
434+
fn default() -> Uuid {
435+
Uuid::nil()
444436
}
445437
}
446438

@@ -521,24 +513,15 @@ mod test {
521513
use super::*;
522514
use std::str;
523515
use std::rand;
524-
use std::num::Zero;
525516
use std::io::MemWriter;
526517

527518
#[test]
528-
fn test_new_nil() {
529-
let nil = Uuid::new_nil();
530-
let nb = nil.to_bytes();
531-
532-
assert!(nb.iter().all(|&b| b == 0));
533-
}
534-
535-
#[test]
536-
fn test_zero() {
537-
let uz: Uuid = Zero::zero();
538-
let nz = Uuid::new_v4();
519+
fn test_nil() {
520+
let nil = Uuid::nil();
521+
let not_nil = Uuid::new_v4();
539522

540-
assert!(uz.is_zero());
541-
assert!(! nz.is_zero());
523+
assert!(nil.is_nil());
524+
assert!(!not_nil.is_nil());
542525
}
543526

544527
#[test]
@@ -619,7 +602,7 @@ mod test {
619602
assert!(Uuid::parse_string("urn:uuid:67e55044-10b1-426f-9247-bb680e5fe0c8").is_ok());
620603

621604
// Nil
622-
let nil = Uuid::new_nil();
605+
let nil = Uuid::nil();
623606
assert!(Uuid::parse_string("00000000000000000000000000000000").unwrap() == nil);
624607
assert!(Uuid::parse_string("00000000-0000-0000-0000-000000000000").unwrap() == nil);
625608

branches/try2/src/librustc/middle/lang_items.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,12 @@ use std::hashmap::HashMap;
3333
use std::iter::Enumerate;
3434
use std::vec;
3535

36-
37-
// Get the last "argument" (has to be done recursively to avoid phoney local ambiguity error)
38-
macro_rules! last {
39-
( $first:expr, $( $remainder:expr, )+ ) => ( last!( $( $remainder, )+ ) );
40-
( $first:expr, ) => ( $first )
41-
}
42-
4336
// The actual lang items defined come at the end of this file in one handy table.
4437
// So you probably just want to nip down to the end.
4538
macro_rules! lets_do_this {
46-
// secondary rule to allow us to use `$num` as both an expression
47-
// and a pattern.
48-
(
49-
$( $num:tt, $variant:ident, $name:expr, $method:ident; )*
50-
) => {
51-
lets_do_this!(count = 1 + last!($($num,)*),
52-
$($num, $variant, $name, $method; )*)
53-
};
54-
5539
(
56-
count = $num_lang_items:expr, $( $num:pat, $variant:ident, $name:expr, $method:ident; )*
40+
There are $num_lang_items:expr lang items.
41+
$( $num:pat, $variant:ident, $name:expr, $method:ident; )*
5742
) => {
5843

5944
pub enum LangItem {
@@ -222,6 +207,8 @@ pub fn collect_language_items(crate: &ast::Crate,
222207
}
223208

224209
lets_do_this! {
210+
There are 40 lang items.
211+
225212
// ID, Variant name, Name, Method name;
226213
0, FreezeTraitLangItem, "freeze", freeze_trait;
227214
1, SendTraitLangItem, "send", send_trait;
@@ -274,3 +261,4 @@ lets_do_this! {
274261
38, ExchangeHeapLangItem, "exchange_heap", exchange_heap;
275262
39, GcLangItem, "gc", gc;
276263
}
264+

branches/try2/src/librustc/middle/ty.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,12 +2287,6 @@ pub fn is_instantiable(cx: ctxt, r_ty: t) -> bool {
22872287
::util::ppaux::ty_to_str(cx, ty));
22882288

22892289
let r = match get(ty).sty {
2290-
// fixed length vectors need special treatment compared to
2291-
// normal vectors, since they don't necessarily have the
2292-
// possibilty to have length zero.
2293-
ty_vec(_, vstore_fixed(0)) => false, // don't need no contents
2294-
ty_vec(mt, vstore_fixed(_)) => type_requires(cx, seen, r_ty, mt.ty),
2295-
22962290
ty_nil |
22972291
ty_bot |
22982292
ty_bool |

branches/try2/src/libstd/bool.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ use num::FromPrimitive;
4040
#[cfg(not(test))] use cmp::{Eq, Ord, TotalOrd, Ordering};
4141
#[cfg(not(test))] use ops::{Not, BitAnd, BitOr, BitXor};
4242
#[cfg(not(test))] use default::Default;
43-
#[cfg(not(test))] use num::Zero;
4443

4544
/////////////////////////////////////////////////////////////////////////////
4645
// Freestanding functions
@@ -309,12 +308,6 @@ impl Default for bool {
309308
fn default() -> bool { false }
310309
}
311310

312-
#[cfg(not(test))]
313-
impl Zero for bool {
314-
fn zero() -> bool { false }
315-
fn is_zero(&self) -> bool { *self == false }
316-
}
317-
318311
#[cfg(test)]
319312
mod tests {
320313
use prelude::*;

branches/try2/src/libstd/char.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use str;
2222

2323
#[cfg(not(test))] use cmp::{Eq, Ord};
2424
#[cfg(not(test))] use default::Default;
25-
#[cfg(not(test))] use num::Zero;
2625

2726
// UTF-8 ranges and tags for encoding characters
2827
static TAG_CONT: uint = 128u;
@@ -449,15 +448,6 @@ impl Default for char {
449448
fn default() -> char { '\x00' }
450449
}
451450

452-
#[cfg(not(test))]
453-
impl Zero for char {
454-
#[inline]
455-
fn zero() -> char { '\x00' }
456-
457-
#[inline]
458-
fn is_zero(&self) -> bool { *self == '\x00' }
459-
}
460-
461451
#[test]
462452
fn test_is_lowercase() {
463453
assert!('a'.is_lowercase());

branches/try2/src/libstd/iter.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2872,6 +2872,12 @@ mod tests {
28722872
}
28732873
}
28742874

2875+
impl Mul<Foo, Foo> for Foo {
2876+
fn mul(&self, _: &Foo) -> Foo {
2877+
Foo
2878+
}
2879+
}
2880+
28752881
impl num::One for Foo {
28762882
fn one() -> Foo {
28772883
Foo

branches/try2/src/libstd/num/mod.rs

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,59 @@ pub trait Orderable: Ord {
5050
/// Returns the number constrained within the range `mn <= self <= mx`.
5151
#[inline(always)] pub fn clamp<T: Orderable>(value: T, mn: T, mx: T) -> T { value.clamp(&mn, &mx) }
5252

53-
pub trait Zero {
54-
fn zero() -> Self; // FIXME (#5527): This should be an associated constant
53+
/// Defines an additive identity element for `Self`.
54+
///
55+
/// # Deriving
56+
///
57+
/// This trait can be automatically be derived using `#[deriving(Zero)]`
58+
/// attribute. If you choose to use this, make sure that the laws outlined in
59+
/// the documentation for `Zero::zero` still hold.
60+
pub trait Zero: Add<Self, Self> {
61+
/// Returns the additive identity element of `Self`, `0`.
62+
///
63+
/// # Laws
64+
///
65+
/// ~~~
66+
/// a + 0 = a ∀ a ∈ Self
67+
/// 0 + a = a ∀ a ∈ Self
68+
/// ~~~
69+
///
70+
/// # Purity
71+
///
72+
/// This function should return the same result at all times regardless of
73+
/// external mutable state, for example values stored in TLS or in
74+
/// `static mut`s.
75+
// FIXME (#5527): This should be an associated constant
76+
fn zero() -> Self;
77+
78+
/// Returns `true` if `self` is equal to the additive identity.
5579
fn is_zero(&self) -> bool;
5680
}
5781

58-
/// Returns `0` of appropriate type.
82+
/// Returns the additive identity, `0`.
5983
#[inline(always)] pub fn zero<T: Zero>() -> T { Zero::zero() }
6084

61-
pub trait One {
62-
fn one() -> Self; // FIXME (#5527): This should be an associated constant
85+
/// Defines a multiplicative identity element for `Self`.
86+
pub trait One: Mul<Self, Self> {
87+
/// Returns the multiplicative identity element of `Self`, `1`.
88+
///
89+
/// # Laws
90+
///
91+
/// ~~~
92+
/// a * 1 = a ∀ a ∈ Self
93+
/// 1 * a = a ∀ a ∈ Self
94+
/// ~~~
95+
///
96+
/// # Purity
97+
///
98+
/// This function should return the same result at all times regardless of
99+
/// external mutable state, for example values stored in TLS or in
100+
/// `static mut`s.
101+
// FIXME (#5527): This should be an associated constant
102+
fn one() -> Self;
63103
}
64104

65-
/// Returns `1` of appropriate type.
105+
/// Returns the multiplicative identity, `1`.
66106
#[inline(always)] pub fn one<T: One>() -> T { One::one() }
67107

68108
pub trait Signed: Num
@@ -993,16 +1033,6 @@ pub fn from_str_radix<T: FromStrRadix>(str: &str, radix: uint) -> Option<T> {
9931033
FromStrRadix::from_str_radix(str, radix)
9941034
}
9951035

996-
impl<T: Zero + 'static> Zero for @T {
997-
fn zero() -> @T { @Zero::zero() }
998-
fn is_zero(&self) -> bool { (**self).is_zero() }
999-
}
1000-
1001-
impl<T: Zero> Zero for ~T {
1002-
fn zero() -> ~T { ~Zero::zero() }
1003-
fn is_zero(&self) -> bool { (**self).is_zero() }
1004-
}
1005-
10061036
/// Saturating math operations
10071037
pub trait Saturating {
10081038
/// Saturating addition operator.

0 commit comments

Comments
 (0)