Skip to content

Commit e0e7a43

Browse files
committed
---
yaml --- r: 154463 b: refs/heads/try2 c: 51b901e h: refs/heads/master i: 154461: ffb6f64 154459: 8872011 154455: 7309472 154447: 074ae76 154431: 668df78 v: v3
1 parent 200ad87 commit e0e7a43

File tree

10 files changed

+152
-35
lines changed

10 files changed

+152
-35
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: f2aa88ca0676249d9c44bb6a2e59cd2b1cdd9c9a
8+
refs/heads/try2: 51b901e16048c5adbe1f12428fe5a79603478f83
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/doc/guide.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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/try2/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/try2/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;
@@ -1017,23 +1014,23 @@ impl Extendable<bool> for BitvSet {
10171014
impl PartialOrd for BitvSet {
10181015
#[inline]
10191016
fn partial_cmp(&self, other: &BitvSet) -> Option<Ordering> {
1020-
let (a_iter, b_iter) = match_words!(self.get_ref(), other.get_ref());
1017+
let (a_iter, b_iter) = match_words(self.get_ref(), other.get_ref());
10211018
iter::order::partial_cmp(a_iter, b_iter)
10221019
}
10231020
}
10241021

10251022
impl Ord for BitvSet {
10261023
#[inline]
10271024
fn cmp(&self, other: &BitvSet) -> Ordering {
1028-
let (a_iter, b_iter) = match_words!(self.get_ref(), other.get_ref());
1025+
let (a_iter, b_iter) = match_words(self.get_ref(), other.get_ref());
10291026
iter::order::cmp(a_iter, b_iter)
10301027
}
10311028
}
10321029

10331030
impl cmp::PartialEq for BitvSet {
10341031
#[inline]
10351032
fn eq(&self, other: &BitvSet) -> bool {
1036-
let (a_iter, b_iter) = match_words!(self.get_ref(), other.get_ref());
1033+
let (a_iter, b_iter) = match_words(self.get_ref(), other.get_ref());
10371034
iter::order::eq(a_iter, b_iter)
10381035
}
10391036
}
@@ -1194,10 +1191,10 @@ impl BitvSet {
11941191
self_bitv.reserve(other_bitv.capacity());
11951192

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

12021199
// Apply values found in other
12031200
for (i, w) in other_words {
@@ -1529,7 +1526,7 @@ impl Set<uint> for BitvSet {
15291526

15301527
#[inline]
15311528
fn is_disjoint(&self, other: &BitvSet) -> bool {
1532-
self.intersection(other).count() > 0
1529+
self.intersection(other).next().is_none()
15331530
}
15341531

15351532
#[inline]
@@ -2271,6 +2268,24 @@ mod tests {
22712268
assert!(set1.is_subset(&set2)); // { 2 } { 2, 4 }
22722269
}
22732270

2271+
#[test]
2272+
fn test_bitv_set_is_disjoint() {
2273+
let a = BitvSet::from_bitv(from_bytes([0b10100010]));
2274+
let b = BitvSet::from_bitv(from_bytes([0b01000000]));
2275+
let c = BitvSet::new();
2276+
let d = BitvSet::from_bitv(from_bytes([0b00110000]));
2277+
2278+
assert!(!a.is_disjoint(&d));
2279+
assert!(!d.is_disjoint(&a));
2280+
2281+
assert!(a.is_disjoint(&b))
2282+
assert!(a.is_disjoint(&c))
2283+
assert!(b.is_disjoint(&a))
2284+
assert!(b.is_disjoint(&c))
2285+
assert!(c.is_disjoint(&a))
2286+
assert!(c.is_disjoint(&b))
2287+
}
2288+
22742289
#[test]
22752290
fn test_bitv_set_intersect_with() {
22762291
// Explicitly 0'ed bits

branches/try2/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/try2/src/libcore/str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ enum Searcher {
562562
impl Searcher {
563563
fn new(haystack: &[u8], needle: &[u8]) -> Searcher {
564564
// FIXME: Tune this.
565-
if needle.len() > haystack.len() - 20 {
565+
if needle.len() + 20 > haystack.len() {
566566
Naive(NaiveSearcher::new())
567567
} else {
568568
let searcher = TwoWaySearcher::new(needle);

branches/try2/src/libcoretest/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ mod ptr;
2929
mod raw;
3030
mod result;
3131
mod slice;
32+
mod str;
3233
mod tuple;

branches/try2/src/libcoretest/str.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[test]
12+
fn strslice_issue_16589() {
13+
assert!("bananas".contains("nana"));
14+
}

branches/try2/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/try2/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)