Skip to content

Commit 565362d

Browse files
author
Jorge Aparicio
committed
---
yaml --- r: 158582 b: refs/heads/try c: 2a7fb35 h: refs/heads/master v: v3
1 parent b25d1e2 commit 565362d

Some content is hidden

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

79 files changed

+1406
-1328
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: a0a7ab461283322215f0343cd2b5e66fc19a7bd5
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 1b2ad7831f1745bf4a4709a1fa1772afb47c933c
5-
refs/heads/try: 11790a545c77e0f35a00d2b27ff590393d705246
5+
refs/heads/try: 2a7fb3584c974d6bf09182d454a457515aca228b
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/src/doc/guide.md

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ fn add_one(x: int) -> int {
777777
x + 1;
778778
}
779779
780-
help: consider removing this semicolon:
780+
note: consider removing this semicolon:
781781
x + 1;
782782
^
783783
```
@@ -4467,19 +4467,18 @@ see why consumers matter.
44674467

44684468
## Iterators
44694469

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:
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:
44764475

44774476
```{rust}
44784477
let nums = range(1i, 100i);
44794478
```
44804479

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

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

45104509
This iterator counts up from one, adding five each time. It will give
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,
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,
45134512
that's okay! You probably don't want to use `collect()` on it, though...
45144513

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

52545253
You've already used one macro extensively: `println!`. When we invoke
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
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
52575256
macro. The second is that macros allow for flexible syntax, and so Rust must
52585257
be able to tell where a macro starts and ends. The `!(...)` helps with this.
52595258

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

52695268
The `println!` macro does a few things:
52705269

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

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

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

52835282
```{rust}
52845283
fn main() {
@@ -5287,7 +5286,7 @@ fn main() {
52875286
}
52885287
```
52895288

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

52935292
```{rust,ignore}
@@ -5326,12 +5325,12 @@ invoke the `println_args` function with the generated arguments.
53265325
This is the code that Rust actually compiles. You can see all of the extra
53275326
information that's here. We get all of the type safety and options that it
53285327
provides, but at compile time, and without needing to type all of this out.
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`.
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`.
53315330

53325331
For more on macros, please consult [the Macros Guide](guide-macros.html).
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
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
53355334
Guide can help you if you want to write your own.
53365335

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

53495348
Second, if you'd like to create some sort of shared-memory data structure, Rust
53505349
won't allow it, because memory must be owned by a single owner. However, if
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`
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`
53535352
block allows you to ask the compiler to trust you. In this case, the _internal_
53545353
implementation of the mutex is considered unsafe, but the _external_ interface
53555354
we present is safe. This allows it to be effectively used in normal Rust, while

branches/try/src/doc/reference.md

Lines changed: 4 additions & 4 deletions
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 with
834+
Modules and types share the same namespace. Declaring a named type that has
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 two
874-
kinds of view items:
873+
items, but rather, simply change other items' visibility. There are several
874+
kinds of view item:
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-
Three examples of `extern crate` declarations:
899+
Four examples of `extern crate` declarations:
900900

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

branches/try/src/etc/vim/autoload/rust.vim

Lines changed: 6 additions & 6 deletions
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' fnameescape(tmpdir)
181+
silent exe 'lcd' tmpdir
182182

183183
let path = 'unnamed.rs'
184184

185185
let save_mod = &mod
186186
set nomod
187187

188-
silent exe 'keepalt write! ' . fnameescape(path)
188+
silent exe 'keepalt write! ' . 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' fnameescape(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' save_cwd | endif
201+
if exists("tmpdir") | silent call s:RmDir(tmpdir) | endif
202202
endtry
203203
endfunction
204204

branches/try/src/librand/distributions/mod.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,6 @@ 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.
237230
let bits: u64 = rng.gen();
238231
let i = (bits & 0xff) as uint;
239232
let f = (bits >> 11) as f64 / SCALE;

branches/try/src/librand/lib.rs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -78,46 +78,6 @@ 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-
12181
/// Fill `dest` with random data.
12282
///
12383
/// This has a default implementation in terms of `next_u64` and

branches/try/src/librand/rand_impls.rs

Lines changed: 14 additions & 9 deletions
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) => {
99+
($mod_name:ident, $ty:ty, $mantissa_bits:expr, $method_name:ident, $ignored_bits:expr) => {
100100
mod $mod_name {
101101
use {Rand, Rng, Open01, Closed01};
102102

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

105105
impl Rand for $ty {
106106
/// Generate a floating point number in the half-open
@@ -110,7 +110,11 @@ 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-
rng.$method_name()
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
114118
}
115119
}
116120
impl Rand for Open01<$ty> {
@@ -120,22 +124,23 @@ macro_rules! float_impls {
120124
// the precision of f64/f32 at 1.0), so that small
121125
// numbers are larger than 0, but large numbers
122126
// aren't pushed to/above 1.
123-
Open01(rng.$method_name() + 0.25 / SCALE)
127+
Open01(((rng.$method_name() >> $ignored_bits) as $ty + 0.25) / SCALE)
124128
}
125129
}
126130
impl Rand for Closed01<$ty> {
127131
#[inline]
128132
fn rand<R: Rng>(rng: &mut R) -> Closed01<$ty> {
129-
// rescale so that 1.0 - epsilon becomes 1.0
130-
// precisely.
131-
Closed01(rng.$method_name() * SCALE / (SCALE - 1.0))
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))
132137
}
133138
}
134139
}
135140
}
136141
}
137-
float_impls! { f64_rand_impls, f64, 53, next_f64 }
138-
float_impls! { f32_rand_impls, f32, 24, next_f32 }
142+
float_impls! { f64_rand_impls, f64, 53, next_u64, 11 }
143+
float_impls! { f32_rand_impls, f32, 24, next_u32, 8 }
139144

140145
impl Rand for char {
141146
#[inline]

branches/try/src/librustc/lint/builtin.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,12 @@ impl LintPass for TypeLimits {
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
};

branches/try/src/librustc/lint/context.rs

Lines changed: 2 additions & 2 deletions
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(&mut self, f: |&mut ast_util::IdVisitor<Context>|) {
535+
fn visit_ids(&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(&mut self, id: ast::NodeId) {
752+
fn visit_id(&self, id: ast::NodeId) {
753753
match self.tcx.sess.lints.borrow_mut().pop(&id) {
754754
None => {}
755755
Some(lints) => {

branches/try/src/librustc/metadata/common.rs

Lines changed: 2 additions & 1 deletion
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::<uint, astencode_tag>(value) })
151+
Some(unsafe { mem::transmute(value) })
152152
}
153153
}
154154
}
@@ -247,3 +247,4 @@ 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+

branches/try/src/librustc/metadata/decoder.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use std::io::extensions::u64_from_be_bytes;
3636
use std::io;
3737
use std::collections::hash_map::HashMap;
3838
use std::rc::Rc;
39-
use std::str;
39+
use std::u64;
4040
use rbml::reader;
4141
use rbml;
4242
use serialize::Decodable;
@@ -215,9 +215,7 @@ fn each_reexport(d: rbml::Doc, f: |rbml::Doc| -> bool) -> bool {
215215

216216
fn variant_disr_val(d: rbml::Doc) -> Option<ty::Disr> {
217217
reader::maybe_get_doc(d, tag_disr_val).and_then(|val_doc| {
218-
reader::with_doc_data(val_doc, |data| {
219-
str::from_utf8(data).and_then(from_str)
220-
})
218+
reader::with_doc_data(val_doc, |data| u64::parse_bytes(data, 10u))
221219
})
222220
}
223221

0 commit comments

Comments
 (0)