Skip to content

Commit 82fb413

Browse files
committed
auto merge of #18596 : alexcrichton/rust/rollup, r=alexcrichton
Let's see if we can clear out the queue entirely today!
2 parents ec28b4a + f2aa8c4 commit 82fb413

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1242
-1331
lines changed

src/doc/guide.md

+21-20
Original file line numberDiff line numberDiff line change
@@ -4467,18 +4467,19 @@ see why consumers matter.
44674467

44684468
## Iterators
44694469

4470-
As we've said before, an iterator is something that we can call the `.next()`
4471-
method on repeatedly, and it gives us a sequence of things. Because you need
4472-
to call the method, this means that iterators are **lazy**. This code, for
4473-
example, does not actually generate the numbers `1-100`, and just creates a
4474-
value that represents the sequence:
4470+
As we've said before, an iterator is something that we can call the
4471+
`.next()` method on repeatedly, and it gives us a sequence of things.
4472+
Because you need to call the method, this means that iterators
4473+
are **lazy** and don't need to generate all of the values upfront.
4474+
This code, for example, does not actually generate the numbers
4475+
`1-100`, and just creates a value that represents the sequence:
44754476

44764477
```{rust}
44774478
let nums = range(1i, 100i);
44784479
```
44794480

44804481
Since we didn't do anything with the range, it didn't generate the sequence.
4481-
Once we add the consumer:
4482+
Let's add the consumer:
44824483

44834484
```{rust}
44844485
let nums = range(1i, 100i).collect::<Vec<int>>();
@@ -4507,8 +4508,8 @@ std::iter::count(1i, 5i);
45074508
```
45084509

45094510
This iterator counts up from one, adding five each time. It will give
4510-
you a new integer every time, forever. Well, technically, until the
4511-
maximum number that an `int` can represent. But since iterators are lazy,
4511+
you a new integer every time, forever (well, technically, until it reaches the
4512+
maximum number representable by an `int`). But since iterators are lazy,
45124513
that's okay! You probably don't want to use `collect()` on it, though...
45134514

45144515
That's enough about iterators. Iterator adapters are the last concept
@@ -5251,8 +5252,8 @@ to do something that it can't currently do? You may be able to write a macro
52515252
to extend Rust's capabilities.
52525253

52535254
You've already used one macro extensively: `println!`. When we invoke
5254-
a Rust macro, we need to use the exclamation mark (`!`). There's two reasons
5255-
that this is true: the first is that it makes it clear when you're using a
5255+
a Rust macro, we need to use the exclamation mark (`!`). There are two reasons
5256+
why this is so: the first is that it makes it clear when you're using a
52565257
macro. The second is that macros allow for flexible syntax, and so Rust must
52575258
be able to tell where a macro starts and ends. The `!(...)` helps with this.
52585259

@@ -5267,7 +5268,7 @@ println!("x is: {}", x);
52675268

52685269
The `println!` macro does a few things:
52695270

5270-
1. It parses the string to find any `{}`s
5271+
1. It parses the string to find any `{}`s.
52715272
2. It checks that the number of `{}`s matches the number of other arguments.
52725273
3. It generates a bunch of Rust code, taking this in mind.
52735274

@@ -5276,8 +5277,8 @@ Rust will generate code that takes all of the types into account. If
52765277
`println!` was a function, it could still do this type checking, but it
52775278
would happen at run time rather than compile time.
52785279

5279-
We can check this out using a special flag to `rustc`. This code, in a file
5280-
`print.rs`:
5280+
We can check this out using a special flag to `rustc`. Put this code in a file
5281+
called `print.rs`:
52815282

52825283
```{rust}
52835284
fn main() {
@@ -5286,7 +5287,7 @@ fn main() {
52865287
}
52875288
```
52885289

5289-
Can have its macros expanded like this: `rustc print.rs --pretty=expanded`, will
5290+
You can have the macros expanded like this: `rustc print.rs --pretty=expanded` – which will
52905291
give us this huge result:
52915292

52925293
```{rust,ignore}
@@ -5325,12 +5326,12 @@ invoke the `println_args` function with the generated arguments.
53255326
This is the code that Rust actually compiles. You can see all of the extra
53265327
information that's here. We get all of the type safety and options that it
53275328
provides, but at compile time, and without needing to type all of this out.
5328-
This is how macros are powerful. Without them, you would need to type all of
5329-
this by hand to get a type checked `println`.
5329+
This is how macros are powerful: without them you would need to type all of
5330+
this by hand to get a type-checked `println`.
53305331

53315332
For more on macros, please consult [the Macros Guide](guide-macros.html).
5332-
Macros are a very advanced and still slightly experimental feature, but don't
5333-
require a deep understanding to call, since they look just like functions. The
5333+
Macros are a very advanced and still slightly experimental feature, but they don't
5334+
require a deep understanding to be called, since they look just like functions. The
53345335
Guide can help you if you want to write your own.
53355336

53365337
# Unsafe
@@ -5347,8 +5348,8 @@ keyword, which indicates that the function may not behave properly.
53475348

53485349
Second, if you'd like to create some sort of shared-memory data structure, Rust
53495350
won't allow it, because memory must be owned by a single owner. However, if
5350-
you're planning on making access to that shared memory safe, such as with a
5351-
mutex, _you_ know that it's safe, but Rust can't know. Writing an `unsafe`
5351+
you're planning on making access to that shared memory safe such as with a
5352+
mutex _you_ know that it's safe, but Rust can't know. Writing an `unsafe`
53525353
block allows you to ask the compiler to trust you. In this case, the _internal_
53535354
implementation of the mutex is considered unsafe, but the _external_ interface
53545355
we present is safe. This allows it to be effectively used in normal Rust, while

src/doc/reference.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ mod math {
831831
}
832832
```
833833

834-
Modules and types share the same namespace. Declaring a named type that has
834+
Modules and types share the same namespace. Declaring a named type with
835835
the same name as a module in scope is forbidden: that is, a type definition,
836836
trait, struct, enumeration, or type parameter can't shadow the name of a module
837837
in scope, or vice versa.
@@ -870,8 +870,8 @@ view_item : extern_crate_decl | use_decl ;
870870
```
871871

872872
A view item manages the namespace of a module. View items do not define new
873-
items, but rather, simply change other items' visibility. There are several
874-
kinds of view item:
873+
items, but rather, simply change other items' visibility. There are two
874+
kinds of view items:
875875

876876
* [`extern crate` declarations](#extern-crate-declarations)
877877
* [`use` declarations](#use-declarations)
@@ -896,7 +896,7 @@ external crate when it was compiled. If no `crateid` is provided, a default
896896
`name` attribute is assumed, equal to the `ident` given in the
897897
`extern_crate_decl`.
898898

899-
Four examples of `extern crate` declarations:
899+
Three examples of `extern crate` declarations:
900900

901901
```{.ignore}
902902
extern crate pcre;

src/etc/vim/autoload/rust.vim

+6-6
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,14 @@ function! s:WithPath(func, ...)
178178
call mkdir(tmpdir)
179179

180180
let save_cwd = getcwd()
181-
silent exe 'lcd' tmpdir
181+
silent exe 'lcd' fnameescape(tmpdir)
182182

183183
let path = 'unnamed.rs'
184184

185185
let save_mod = &mod
186186
set nomod
187187

188-
silent exe 'keepalt write! ' . path
188+
silent exe 'keepalt write! ' . fnameescape(path)
189189
if pathisempty
190190
silent keepalt 0file
191191
endif
@@ -195,10 +195,10 @@ function! s:WithPath(func, ...)
195195

196196
call call(a:func, [path] + a:000)
197197
finally
198-
if exists("save_mod") | let &mod = save_mod | endif
199-
if exists("save_write") | let &write = save_write | endif
200-
if exists("save_cwd") | silent exe 'lcd' save_cwd | endif
201-
if exists("tmpdir") | silent call s:RmDir(tmpdir) | endif
198+
if exists("save_mod") | let &mod = save_mod | endif
199+
if exists("save_write") | let &write = save_write | endif
200+
if exists("save_cwd") | silent exe 'lcd' fnameescape(save_cwd) | endif
201+
if exists("tmpdir") | silent call s:RmDir(tmpdir) | endif
202202
endtry
203203
endfunction
204204

src/libcore/result.rs

-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@
276276
277277
#![stable]
278278

279-
use clone::Clone;
280279
use cmp::PartialEq;
281280
use std::fmt::Show;
282281
use slice;

src/libcore/str.rs

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use mem;
2020
use char;
2121
use char::Char;
22-
use clone::Clone;
2322
use cmp;
2423
use cmp::{PartialEq, Eq};
2524
use default::Default;

src/librand/distributions/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,13 @@ fn ziggurat<R:Rng>(
227227
// creating a f64), so we might as well reuse some to save
228228
// generating a whole extra random number. (Seems to be 15%
229229
// faster.)
230+
//
231+
// This unfortunately misses out on the benefits of direct
232+
// floating point generation if an RNG like dSMFT is
233+
// used. (That is, such RNGs create floats directly, highly
234+
// efficiently and overload next_f32/f64, so by not calling it
235+
// this may be slower than it would be otherwise.)
236+
// FIXME: investigate/optimise for the above.
230237
let bits: u64 = rng.gen();
231238
let i = (bits & 0xff) as uint;
232239
let f = (bits >> 11) as f64 / SCALE;

src/librand/lib.rs

+40
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,46 @@ pub trait Rng {
7878
(self.next_u32() as u64 << 32) | (self.next_u32() as u64)
7979
}
8080

81+
/// Return the next random f32 selected from the half-open
82+
/// interval `[0, 1)`.
83+
///
84+
/// By default this is implemented in terms of `next_u32`, but a
85+
/// random number generator which can generate numbers satisfying
86+
/// the requirements directly can overload this for performance.
87+
/// It is required that the return value lies in `[0, 1)`.
88+
///
89+
/// See `Closed01` for the closed interval `[0,1]`, and
90+
/// `Open01` for the open interval `(0,1)`.
91+
fn next_f32(&mut self) -> f32 {
92+
const MANTISSA_BITS: uint = 24;
93+
const IGNORED_BITS: uint = 8;
94+
const SCALE: f32 = (1u64 << MANTISSA_BITS) as f32;
95+
96+
// using any more than `MANTISSA_BITS` bits will
97+
// cause (e.g.) 0xffff_ffff to correspond to 1
98+
// exactly, so we need to drop some (8 for f32, 11
99+
// for f64) to guarantee the open end.
100+
(self.next_u32() >> IGNORED_BITS) as f32 / SCALE
101+
}
102+
103+
/// Return the next random f64 selected from the half-open
104+
/// interval `[0, 1)`.
105+
///
106+
/// By default this is implemented in terms of `next_u64`, but a
107+
/// random number generator which can generate numbers satisfying
108+
/// the requirements directly can overload this for performance.
109+
/// It is required that the return value lies in `[0, 1)`.
110+
///
111+
/// See `Closed01` for the closed interval `[0,1]`, and
112+
/// `Open01` for the open interval `(0,1)`.
113+
fn next_f64(&mut self) -> f64 {
114+
const MANTISSA_BITS: uint = 53;
115+
const IGNORED_BITS: uint = 11;
116+
const SCALE: f64 = (1u64 << MANTISSA_BITS) as f64;
117+
118+
(self.next_u64() >> IGNORED_BITS) as f64 / SCALE
119+
}
120+
81121
/// Fill `dest` with random data.
82122
///
83123
/// This has a default implementation in terms of `next_u64` and

src/librand/rand_impls.rs

+9-14
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ impl Rand for u64 {
9696
}
9797

9898
macro_rules! float_impls {
99-
($mod_name:ident, $ty:ty, $mantissa_bits:expr, $method_name:ident, $ignored_bits:expr) => {
99+
($mod_name:ident, $ty:ty, $mantissa_bits:expr, $method_name:ident) => {
100100
mod $mod_name {
101101
use {Rand, Rng, Open01, Closed01};
102102

103-
static SCALE: $ty = (1u64 << $mantissa_bits) as $ty;
103+
const SCALE: $ty = (1u64 << $mantissa_bits) as $ty;
104104

105105
impl Rand for $ty {
106106
/// Generate a floating point number in the half-open
@@ -110,11 +110,7 @@ macro_rules! float_impls {
110110
/// and `Open01` for the open interval `(0,1)`.
111111
#[inline]
112112
fn rand<R: Rng>(rng: &mut R) -> $ty {
113-
// using any more than `mantissa_bits` bits will
114-
// cause (e.g.) 0xffff_ffff to correspond to 1
115-
// exactly, so we need to drop some (8 for f32, 11
116-
// for f64) to guarantee the open end.
117-
(rng.$method_name() >> $ignored_bits) as $ty / SCALE
113+
rng.$method_name()
118114
}
119115
}
120116
impl Rand for Open01<$ty> {
@@ -124,23 +120,22 @@ macro_rules! float_impls {
124120
// the precision of f64/f32 at 1.0), so that small
125121
// numbers are larger than 0, but large numbers
126122
// aren't pushed to/above 1.
127-
Open01(((rng.$method_name() >> $ignored_bits) as $ty + 0.25) / SCALE)
123+
Open01(rng.$method_name() + 0.25 / SCALE)
128124
}
129125
}
130126
impl Rand for Closed01<$ty> {
131127
#[inline]
132128
fn rand<R: Rng>(rng: &mut R) -> Closed01<$ty> {
133-
// divide by the maximum value of the numerator to
134-
// get a non-zero probability of getting exactly
135-
// 1.0.
136-
Closed01((rng.$method_name() >> $ignored_bits) as $ty / (SCALE - 1.0))
129+
// rescale so that 1.0 - epsilon becomes 1.0
130+
// precisely.
131+
Closed01(rng.$method_name() * SCALE / (SCALE - 1.0))
137132
}
138133
}
139134
}
140135
}
141136
}
142-
float_impls! { f64_rand_impls, f64, 53, next_u64, 11 }
143-
float_impls! { f32_rand_impls, f32, 24, next_u32, 8 }
137+
float_impls! { f64_rand_impls, f64, 53, next_f64 }
138+
float_impls! { f32_rand_impls, f32, 24, next_f32 }
144139

145140
impl Rand for char {
146141
#[inline]

src/librustc/lint/builtin.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use std::cmp;
3939
use std::collections::HashMap;
4040
use std::collections::hash_map::{Occupied, Vacant};
4141
use std::slice;
42-
use std::{int, i8, i16, i32, i64, uint, u8, u16, u32, u64, f32, f64};
42+
use std::{i8, i16, i32, i64, u8, u16, u32, u64, f32, f64};
4343
use syntax::abi;
4444
use syntax::ast_map;
4545
use syntax::ast_util::is_shift_binop;
@@ -180,19 +180,19 @@ impl LintPass for TypeLimits {
180180

181181
if is_shift_binop(binop) {
182182
let opt_ty_bits = match ty::get(ty::expr_ty(cx.tcx, &**l)).sty {
183-
ty::ty_int(t) => Some(int_ty_bits(t)),
184-
ty::ty_uint(t) => Some(uint_ty_bits(t)),
183+
ty::ty_int(t) => Some(int_ty_bits(t, cx.sess().targ_cfg.int_type)),
184+
ty::ty_uint(t) => Some(uint_ty_bits(t, cx.sess().targ_cfg.uint_type)),
185185
_ => None
186186
};
187187

188188
if let Some(bits) = opt_ty_bits {
189189
let exceeding = if let ast::ExprLit(ref lit) = r.node {
190-
if let ast::LitInt(shift, _) = lit.node { shift > bits }
190+
if let ast::LitInt(shift, _) = lit.node { shift >= bits }
191191
else { false }
192192
} else {
193193
match eval_const_expr_partial(cx.tcx, &**r) {
194-
Ok(const_int(shift)) => { shift as u64 > bits },
195-
Ok(const_uint(shift)) => { shift > bits },
194+
Ok(const_int(shift)) => { shift as u64 >= bits },
195+
Ok(const_uint(shift)) => { shift >= bits },
196196
_ => { false }
197197
}
198198
};
@@ -312,19 +312,19 @@ impl LintPass for TypeLimits {
312312
}
313313
}
314314

315-
fn int_ty_bits(int_ty: ast::IntTy) -> u64 {
315+
fn int_ty_bits(int_ty: ast::IntTy, target_int_ty: ast::IntTy) -> u64 {
316316
match int_ty {
317-
ast::TyI => int::BITS as u64,
317+
ast::TyI => int_ty_bits(target_int_ty, target_int_ty),
318318
ast::TyI8 => i8::BITS as u64,
319319
ast::TyI16 => i16::BITS as u64,
320320
ast::TyI32 => i32::BITS as u64,
321321
ast::TyI64 => i64::BITS as u64
322322
}
323323
}
324324

325-
fn uint_ty_bits(uint_ty: ast::UintTy) -> u64 {
325+
fn uint_ty_bits(uint_ty: ast::UintTy, target_uint_ty: ast::UintTy) -> u64 {
326326
match uint_ty {
327-
ast::TyU => uint::BITS as u64,
327+
ast::TyU => uint_ty_bits(target_uint_ty, target_uint_ty),
328328
ast::TyU8 => u8::BITS as u64,
329329
ast::TyU16 => u16::BITS as u64,
330330
ast::TyU32 => u32::BITS as u64,

src/librustc/lint/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
532532
}
533533
}
534534

535-
fn visit_ids(&self, f: |&mut ast_util::IdVisitor<Context>|) {
535+
fn visit_ids(&mut self, f: |&mut ast_util::IdVisitor<Context>|) {
536536
let mut v = ast_util::IdVisitor {
537537
operation: self,
538538
pass_through_items: false,
@@ -749,7 +749,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
749749

750750
// Output any lints that were previously added to the session.
751751
impl<'a, 'tcx> IdVisitingOperation for Context<'a, 'tcx> {
752-
fn visit_id(&self, id: ast::NodeId) {
752+
fn visit_id(&mut self, id: ast::NodeId) {
753753
match self.tcx.sess.lints.borrow_mut().pop(&id) {
754754
None => {}
755755
Some(lints) => {

src/librustc/metadata/common.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl astencode_tag {
148148
pub fn from_uint(value : uint) -> Option<astencode_tag> {
149149
let is_a_tag = first_astencode_tag <= value && value <= last_astencode_tag;
150150
if !is_a_tag { None } else {
151-
Some(unsafe { mem::transmute(value) })
151+
Some(unsafe { mem::transmute::<uint, astencode_tag>(value) })
152152
}
153153
}
154154
}
@@ -247,4 +247,3 @@ pub const tag_type_param_def: uint = 0xa5;
247247

248248
pub const tag_item_generics: uint = 0xa6;
249249
pub const tag_method_ty_generics: uint = 0xa7;
250-

0 commit comments

Comments
 (0)