Skip to content

Commit 6dcd5f5

Browse files
committed
---
yaml --- r: 128935 b: refs/heads/try c: 3f5d0b5 h: refs/heads/master i: 128933: 31fff38 128931: 7ff16de 128927: 7e009a5 v: v3
1 parent 459d797 commit 6dcd5f5

File tree

10 files changed

+145
-49
lines changed

10 files changed

+145
-49
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 07d86b46a949a94223da714e35b343243e4ecce4
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a86d9ad15e339ab343a12513f9c90556f677b9ca
5-
refs/heads/try: 3b0084e834efb461a72391166a667cedb5581f53
5+
refs/heads/try: 3f5d0b5b6cd4994c719d57a778697124348a4c1c
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/doc/guide.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ note: in expansion of format_args!
517517
<std macros>:1:1: 3:2 note: in expansion of println!
518518
src/hello_world.rs:4:5: 4:42 note: expansion site
519519
error: aborting due to previous error
520-
Could not execute process `rustc src/hello_world.rs --crate-type bin --out-dir /home/you/projects/hello_world/target -L /home/you/projects/hello_world/target -L /home/you/projects/hello_world/target/deps` (status=101)
520+
Could not compile `hello_world`.
521521
```
522522

523523
Rust will not let us use a value that has not been initialized. So why let us
@@ -532,7 +532,7 @@ in the middle of a string." We add a comma, and then `x`, to indicate that we
532532
want `x` to be the value we're interpolating. The comma is used to separate
533533
arguments we pass to functions and macros, if you're passing more than one.
534534

535-
When you just use the double curly braces, Rust will attempt to display the
535+
When you just use the curly braces, Rust will attempt to display the
536536
value in a meaningful way by checking out its type. If you want to specify the
537537
format in a more detailed manner, there are a [wide number of options
538538
available](/std/fmt/index.html). For now, we'll just stick to the default:
@@ -1888,8 +1888,16 @@ fn main() {
18881888

18891889
The first thing we changed was to `use std::rand`, as the docs
18901890
explained. We then added in a `let` expression to create a variable binding
1891-
named `secret_number`, and we printed out its result. Let's try to compile
1892-
this using `cargo build`:
1891+
named `secret_number`, and we printed out its result.
1892+
1893+
Also, you may wonder why we are using `%` on the result of `rand::random()`.
1894+
This operator is called 'modulo', and it returns the remainder of a division.
1895+
By taking the modulo of the result of `rand::random()`, we're limiting the
1896+
values to be between 0 and 99. Then, we add one to the result, making it from 1
1897+
to 100. Using modulo can give you a very, very small bias in the result, but
1898+
for this example, it is not important.
1899+
1900+
Let's try to compile this using `cargo build`:
18931901

18941902
```{notrust,no_run}
18951903
$ cargo build

branches/try/src/doc/rust.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ sequence (`/**`), are interpreted as a special syntax for `doc`
169169
`#[doc="..."]` around the body of the comment (this includes the comment
170170
characters themselves, ie `/// Foo` turns into `#[doc="/// Foo"]`).
171171

172+
`//!` comments apply to the parent of the comment, rather than the item that
173+
follows. `//!` comments are usually used to display information on the crate
174+
index page.
175+
172176
Non-doc comments are interpreted as a form of whitespace.
173177

174178
## Whitespace

branches/try/src/libcollections/bitv.rs

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use core::prelude::*;
6666
use core::cmp;
6767
use core::default::Default;
6868
use core::fmt;
69-
use core::iter::Take;
69+
use core::iter::{Chain, Enumerate, Repeat, Skip, Take};
7070
use core::iter;
7171
use core::slice;
7272
use core::uint;
@@ -75,25 +75,22 @@ use std::hash;
7575
use {Mutable, Set, MutableSet, MutableSeq};
7676
use vec::Vec;
7777

78+
type MatchWords<'a> = Chain<MaskWords<'a>, Skip<Take<Enumerate<Repeat<uint>>>>>;
7879
// Take two BitV's, and return iterators of their words, where the shorter one
7980
// has been padded with 0's
80-
macro_rules! match_words(
81-
($a_expr:expr, $b_expr:expr) => ({
82-
let a = $a_expr;
83-
let b = $b_expr;
84-
let a_len = a.storage.len();
85-
let b_len = b.storage.len();
86-
87-
// have to uselessly pretend to pad the longer one for type matching
88-
if a_len < b_len {
89-
(a.mask_words(0).chain(iter::Repeat::new(0u).enumerate().take(b_len).skip(a_len)),
90-
b.mask_words(0).chain(iter::Repeat::new(0u).enumerate().take(0).skip(0)))
91-
} else {
92-
(a.mask_words(0).chain(iter::Repeat::new(0u).enumerate().take(0).skip(0)),
93-
b.mask_words(0).chain(iter::Repeat::new(0u).enumerate().take(a_len).skip(b_len)))
94-
}
95-
})
96-
)
81+
fn match_words <'a,'b>(a: &'a Bitv, b: &'b Bitv) -> (MatchWords<'a>, MatchWords<'b>) {
82+
let a_len = a.storage.len();
83+
let b_len = b.storage.len();
84+
85+
// have to uselessly pretend to pad the longer one for type matching
86+
if a_len < b_len {
87+
(a.mask_words(0).chain(Repeat::new(0u).enumerate().take(b_len).skip(a_len)),
88+
b.mask_words(0).chain(Repeat::new(0u).enumerate().take(0).skip(0)))
89+
} else {
90+
(a.mask_words(0).chain(Repeat::new(0u).enumerate().take(0).skip(0)),
91+
b.mask_words(0).chain(Repeat::new(0u).enumerate().take(a_len).skip(b_len)))
92+
}
93+
}
9794

9895
static TRUE: bool = true;
9996
static FALSE: bool = false;
@@ -1014,23 +1011,23 @@ impl Extendable<bool> for BitvSet {
10141011
impl PartialOrd for BitvSet {
10151012
#[inline]
10161013
fn partial_cmp(&self, other: &BitvSet) -> Option<Ordering> {
1017-
let (a_iter, b_iter) = match_words!(self.get_ref(), other.get_ref());
1014+
let (a_iter, b_iter) = match_words(self.get_ref(), other.get_ref());
10181015
iter::order::partial_cmp(a_iter, b_iter)
10191016
}
10201017
}
10211018

10221019
impl Ord for BitvSet {
10231020
#[inline]
10241021
fn cmp(&self, other: &BitvSet) -> Ordering {
1025-
let (a_iter, b_iter) = match_words!(self.get_ref(), other.get_ref());
1022+
let (a_iter, b_iter) = match_words(self.get_ref(), other.get_ref());
10261023
iter::order::cmp(a_iter, b_iter)
10271024
}
10281025
}
10291026

10301027
impl cmp::PartialEq for BitvSet {
10311028
#[inline]
10321029
fn eq(&self, other: &BitvSet) -> bool {
1033-
let (a_iter, b_iter) = match_words!(self.get_ref(), other.get_ref());
1030+
let (a_iter, b_iter) = match_words(self.get_ref(), other.get_ref());
10341031
iter::order::eq(a_iter, b_iter)
10351032
}
10361033
}
@@ -1191,10 +1188,10 @@ impl BitvSet {
11911188
self_bitv.reserve(other_bitv.capacity());
11921189

11931190
// virtually pad other with 0's for equal lengths
1194-
let self_len = self_bitv.storage.len();
1195-
let other_len = other_bitv.storage.len();
1196-
let mut other_words = other_bitv.mask_words(0)
1197-
.chain(iter::Repeat::new(0u).enumerate().take(self_len).skip(other_len));
1191+
let mut other_words = {
1192+
let (_, result) = match_words(self_bitv, other_bitv);
1193+
result
1194+
};
11981195

11991196
// Apply values found in other
12001197
for (i, w) in other_words {
@@ -1524,7 +1521,7 @@ impl Set<uint> for BitvSet {
15241521

15251522
#[inline]
15261523
fn is_disjoint(&self, other: &BitvSet) -> bool {
1527-
self.intersection(other).count() > 0
1524+
self.intersection(other).next().is_none()
15281525
}
15291526

15301527
#[inline]
@@ -2266,6 +2263,24 @@ mod tests {
22662263
assert!(set1.is_subset(&set2)); // { 2 } { 2, 4 }
22672264
}
22682265

2266+
#[test]
2267+
fn test_bitv_set_is_disjoint() {
2268+
let a = BitvSet::from_bitv(from_bytes([0b10100010]));
2269+
let b = BitvSet::from_bitv(from_bytes([0b01000000]));
2270+
let c = BitvSet::new();
2271+
let d = BitvSet::from_bitv(from_bytes([0b00110000]));
2272+
2273+
assert!(!a.is_disjoint(&d));
2274+
assert!(!d.is_disjoint(&a));
2275+
2276+
assert!(a.is_disjoint(&b))
2277+
assert!(a.is_disjoint(&c))
2278+
assert!(b.is_disjoint(&a))
2279+
assert!(b.is_disjoint(&c))
2280+
assert!(c.is_disjoint(&a))
2281+
assert!(c.is_disjoint(&b))
2282+
}
2283+
22692284
#[test]
22702285
fn test_bitv_set_intersect_with() {
22712286
// Explicitly 0'ed bits

branches/try/src/libcollections/str.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,6 @@ the string is valid for the `'static` lifetime, otherwise known as the
4444
lifetime of the entire program. As can be inferred from the type, these static
4545
strings are not mutable.
4646
47-
# Mutability
48-
49-
Many languages have immutable strings by default, and Rust has a particular
50-
flavor on this idea. As with the rest of Rust types, strings are immutable by
51-
default. If a string is declared as `mut`, however, it may be mutated. This
52-
works the same way as the rest of Rust's type system in the sense that if
53-
there's a mutable reference to a string, there may only be one mutable reference
54-
to that string. With these guarantees, strings can easily transition between
55-
being mutable/immutable with the same benefits of having mutable strings in
56-
other languages.
57-
5847
# Representation
5948
6049
Rust's string type, `str`, is a sequence of unicode scalar values encoded as a

branches/try/src/libcore/num/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,17 +1345,19 @@ checked_impl!(CheckedMul, checked_mul, i16, intrinsics::i16_mul_with_overflow)
13451345
checked_impl!(CheckedMul, checked_mul, i32, intrinsics::i32_mul_with_overflow)
13461346
checked_impl!(CheckedMul, checked_mul, i64, intrinsics::i64_mul_with_overflow)
13471347

1348-
/// Performs division that returns `None` instead of wrapping around on underflow or overflow.
1348+
/// Performs division that returns `None` instead of failing on division by zero and instead of
1349+
/// wrapping around on underflow and overflow.
13491350
pub trait CheckedDiv: Div<Self, Self> {
1350-
/// Divides two numbers, checking for underflow or overflow. If underflow or overflow happens,
1351-
/// `None` is returned.
1351+
/// Divides two numbers, checking for underflow, overflow and division by zero. If any of that
1352+
/// happens, / `None` is returned.
13521353
///
13531354
/// # Example
13541355
///
13551356
/// ```rust
13561357
/// use std::num::CheckedDiv;
13571358
/// assert_eq!((-127i8).checked_div(&-1), Some(127));
13581359
/// assert_eq!((-128i8).checked_div(&-1), None);
1360+
/// assert_eq!((1i8).checked_div(&0), None);
13591361
/// ```
13601362
fn checked_div(&self, v: &Self) -> Option<Self>;
13611363
}

branches/try/src/libcore/option.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl<T> Option<T> {
244244
}
245245
}
246246

247-
/// Moves a value out of an option type and returns it, consuming the `Option`.
247+
/// Returns the inner `T` of a `Some(T)`.
248248
///
249249
/// # Failure
250250
///

branches/try/src/librustc/middle/trans/base.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ use std::cell::{Cell, RefCell};
8787
use std::rc::Rc;
8888
use std::{i8, i16, i32, i64};
8989
use syntax::abi::{X86, X86_64, Arm, Mips, Mipsel, Rust, RustCall};
90-
use syntax::abi::{RustIntrinsic, Abi};
90+
use syntax::abi::{RustIntrinsic, Abi, OsWindows};
9191
use syntax::ast_util::{local_def, is_local};
9292
use syntax::attr::AttrMetaMethods;
9393
use syntax::attr;
@@ -2446,6 +2446,13 @@ pub fn create_entry_wrapper(ccx: &CrateContext,
24462446
&ccx.int_type);
24472447

24482448
let llfn = decl_cdecl_fn(ccx, "main", llfty, ty::mk_nil());
2449+
2450+
// FIXME: #16581: Marking a symbol in the executable with `dllexport`
2451+
// linkage forces MinGW's linker to output a `.reloc` section for ASLR
2452+
if ccx.sess().targ_cfg.os == OsWindows {
2453+
unsafe { llvm::LLVMRustSetDLLExportStorageClass(llfn) }
2454+
}
2455+
24492456
let llbb = "top".with_c_str(|buf| {
24502457
unsafe {
24512458
llvm::LLVMAppendBasicBlockInContext(ccx.llcx, llfn, buf)

branches/try/src/libstd/io/fs.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,15 @@ impl File {
236236
})
237237
}
238238

239-
/// Tests whether this stream has reached EOF.
239+
/// Returns true if the stream has reached the end of the file.
240240
///
241241
/// If true, then this file will no longer continue to return data via
242242
/// `read`.
243+
///
244+
/// Note that the operating system will not return an `EOF` indicator
245+
/// until you have attempted to read past the end of the file, so if
246+
/// you've read _exactly_ the number of bytes in the file, this will
247+
/// return `false`, not `true`.
243248
pub fn eof(&self) -> bool {
244249
self.last_nread == 0
245250
}

branches/try/src/libtime/lib.rs

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -90,6 +90,30 @@ impl Timespec {
9090
}
9191
}
9292

93+
impl Add<Timespec, Timespec> for Timespec {
94+
fn add(&self, other: &Timespec) -> Timespec {
95+
let mut sec = self.sec + other.sec;
96+
let mut nsec = self.nsec + other.nsec;
97+
if nsec >= NSEC_PER_SEC {
98+
nsec -= NSEC_PER_SEC;
99+
sec += 1;
100+
}
101+
Timespec::new(sec, nsec)
102+
}
103+
}
104+
105+
impl Sub<Timespec, Timespec> for Timespec {
106+
fn sub(&self, other: &Timespec) -> Timespec {
107+
let mut sec = self.sec - other.sec;
108+
let mut nsec = self.nsec - other.nsec;
109+
if nsec < 0 {
110+
nsec += NSEC_PER_SEC;
111+
sec -= 1;
112+
}
113+
Timespec::new(sec, nsec)
114+
}
115+
}
116+
93117
/**
94118
* Returns the current time as a `timespec` containing the seconds and
95119
* nanoseconds since 1970-01-01T00:00:00Z.
@@ -1489,6 +1513,46 @@ mod tests {
14891513
assert!(d.gt(c));
14901514
}
14911515

1516+
fn test_timespec_add() {
1517+
let a = Timespec::new(1, 2);
1518+
let b = Timespec::new(2, 3);
1519+
let c = a + b;
1520+
assert_eq!(c.sec, 3);
1521+
assert_eq!(c.nsec, 5);
1522+
1523+
let p = Timespec::new(1, super::NSEC_PER_SEC - 2);
1524+
let q = Timespec::new(2, 2);
1525+
let r = p + q;
1526+
assert_eq!(r.sec, 4);
1527+
assert_eq!(r.nsec, 0);
1528+
1529+
let u = Timespec::new(1, super::NSEC_PER_SEC - 2);
1530+
let v = Timespec::new(2, 3);
1531+
let w = u + v;
1532+
assert_eq!(w.sec, 4);
1533+
assert_eq!(w.nsec, 1);
1534+
}
1535+
1536+
fn test_timespec_sub() {
1537+
let a = Timespec::new(2, 3);
1538+
let b = Timespec::new(1, 2);
1539+
let c = a - b;
1540+
assert_eq!(c.sec, 1);
1541+
assert_eq!(c.nsec, 1);
1542+
1543+
let p = Timespec::new(2, 0);
1544+
let q = Timespec::new(1, 2);
1545+
let r = p - q;
1546+
assert_eq!(r.sec, 0);
1547+
assert_eq!(r.nsec, super::NSEC_PER_SEC - 2);
1548+
1549+
let u = Timespec::new(1, 2);
1550+
let v = Timespec::new(2, 3);
1551+
let w = u - v;
1552+
assert_eq!(w.sec, -2);
1553+
assert_eq!(w.nsec, super::NSEC_PER_SEC - 1);
1554+
}
1555+
14921556
#[test]
14931557
#[ignore(cfg(target_os = "android"))] // FIXME #10958
14941558
fn run_tests() {
@@ -1505,6 +1569,8 @@ mod tests {
15051569
test_ctime();
15061570
test_strftime();
15071571
test_timespec_eq_ord();
1572+
test_timespec_add();
1573+
test_timespec_sub();
15081574
}
15091575

15101576
#[bench]

0 commit comments

Comments
 (0)