Skip to content

Rolling up PRs in the queue #18596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 51 commits into from
Nov 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
c582974
vim: Fix :RustRun when cwd has a space in it
lilyball Oct 23, 2014
56f1a67
Guide: Iterators, Macros and Unsafe wording fixes
chastell Oct 26, 2014
1bfe6a2
Guide: Iterators: …are always lazy + rewrap as per request
chastell Oct 28, 2014
5bf9ef2
Convert some notes to help messages
ftxqxd Oct 18, 2014
e49be7a
rand: Add next_f64/f32 to Rng.
huonw Nov 2, 2014
ab9a1b7
Change Json methods to &str and allow Indexing
Nov 2, 2014
1571aba
Fix ICE when checking call overload
bkoropoff Nov 3, 2014
7a8e73e
Add regression test for #18532
bkoropoff Nov 3, 2014
3ceb011
Ignore whitespace tokens when re-computing spans in save_analysis
nrc Nov 3, 2014
2b6c2b6
Dump char and byte positions in save_analysis
nrc Nov 3, 2014
9bc4da3
Doc: corrects obsolete pointer syntax
gamazeps Nov 3, 2014
138b76b
Separate string->integer implementation in strconv
brendanzab Nov 2, 2014
251fdc8
Remove unnecessary features from strconv
brendanzab Nov 2, 2014
84f4b58
Clean up from_str_float and use iterators
brendanzab Nov 2, 2014
01ded58
Simplify float string conversion function further
brendanzab Nov 2, 2014
8bd37e6
Deprecate {f32, f64}::from_str_hex
brendanzab Nov 2, 2014
e9618ce
Small doc fixes
cakebaker Nov 3, 2014
32b903d
Also fix undefined behaviour when shift equals the number of bits
hirschenberger Nov 3, 2014
fbb90c3
Clean-up transmutes in libsyntax
arielb1 Oct 25, 2014
961ee0a
Allow impls for traits as a concrete type
nrc Oct 21, 2014
f9e52fb
tests
nrc Oct 30, 2014
a87078a
Clean-up transmutes in librustc
arielb1 Oct 25, 2014
319d778
Restructure AST so that the associated type definition carries
nikomatsakis Oct 28, 2014
94d142b
Add in the bounds into the typeparameterdefs for assoc types
nikomatsakis Oct 29, 2014
d2f8074
Add a 4th space for associated types defined in a trait (currently un…
nikomatsakis Oct 30, 2014
fb9d0cc
Move associated types into the Assoc space and add in the builtin bounds
nikomatsakis Oct 31, 2014
3c84e31
Use a struct rather than a 4-tuple
nikomatsakis Nov 3, 2014
59d47a3
rollup merge of #18132 : P1start/more-help
alexcrichton Nov 3, 2014
b8e2eb7
rollup merge of #18247 : kballard/vim_rust_run_cwd_space
alexcrichton Nov 3, 2014
3aaee49
rollup merge of #18318 : arielb1/transmute-cleanup
alexcrichton Nov 3, 2014
fff2b35
rollup merge of #18355 : chastell/guide_iterators_macros_unsafe_fixes
alexcrichton Nov 3, 2014
8494368
rollup merge of #18447 : nick29581/dst-impl3
alexcrichton Nov 3, 2014
2a7fb35
syntax: Use UFCS in the expansion of `#[deriving(Clone)]`
Nov 3, 2014
8d5208a
core: Fix fallout of changing `#[deriving(Clone)]`
Nov 3, 2014
07bbde8
unicode: Fix fallout of changing `#[deriving(Clone)]`
Nov 3, 2014
6d951b2
std: Fix fallout of changing `#[deriving(Clone)]`
Nov 3, 2014
b8fad35
Add test for second half of issue #15689
Nov 3, 2014
03b568a
Fix error message in compile-fail test
Nov 3, 2014
e7f3109
Fix for bitshift errors lint on cross compilation #18587
hirschenberger Nov 3, 2014
eb79361
rollup merge of #18506 : nikomatsakis/assoc-type-bounds
alexcrichton Nov 3, 2014
a5aba68
rollup merge of #18534 : huonw/next-floats
alexcrichton Nov 3, 2014
ee5d238
rollup merge of #18536 : bjz/strconv
alexcrichton Nov 3, 2014
dbb9c99
rollup merge of #18544 : whataloadofwhat/json
alexcrichton Nov 3, 2014
e98172d
rollup merge of #18560 : bkoropoff/issue-18532
alexcrichton Nov 3, 2014
2659b2e
rollup merge of #18562 : nick29581/dxr-1
alexcrichton Nov 3, 2014
c1b1951
rollup merge of #18564 : nick29581/dxr-1a
alexcrichton Nov 3, 2014
a779e89
rollup merge of #18568 : gamazeps/issue18551
alexcrichton Nov 3, 2014
1b363f0
rollup merge of #18572 : cakebaker/small_doc_changes
alexcrichton Nov 3, 2014
11790a5
rollup merge of #18580 : hirschenberger/issue-17713
alexcrichton Nov 3, 2014
5d6cd77
rollup merge of #18578 : japaric/clone
alexcrichton Nov 3, 2014
f2aa8c4
rollup merge of #18593 : hirschenberger/issue-18587
alexcrichton Nov 3, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions src/doc/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ fn add_one(x: int) -> int {
x + 1;
}

note: consider removing this semicolon:
help: consider removing this semicolon:
x + 1;
^
```
Expand Down Expand Up @@ -4467,18 +4467,19 @@ see why consumers matter.

## Iterators

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

```{rust}
let nums = range(1i, 100i);
```

Since we didn't do anything with the range, it didn't generate the sequence.
Once we add the consumer:
Let's add the consumer:

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

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

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

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

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

The `println!` macro does a few things:

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

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

We can check this out using a special flag to `rustc`. This code, in a file
`print.rs`:
We can check this out using a special flag to `rustc`. Put this code in a file
called `print.rs`:

```{rust}
fn main() {
Expand All @@ -5286,7 +5287,7 @@ fn main() {
}
```

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

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

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

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

Second, if you'd like to create some sort of shared-memory data structure, Rust
won't allow it, because memory must be owned by a single owner. However, if
you're planning on making access to that shared memory safe, such as with a
mutex, _you_ know that it's safe, but Rust can't know. Writing an `unsafe`
you're planning on making access to that shared memory safe such as with a
mutex _you_ know that it's safe, but Rust can't know. Writing an `unsafe`
block allows you to ask the compiler to trust you. In this case, the _internal_
implementation of the mutex is considered unsafe, but the _external_ interface
we present is safe. This allows it to be effectively used in normal Rust, while
Expand Down
8 changes: 4 additions & 4 deletions src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ mod math {
}
```

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

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

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

Four examples of `extern crate` declarations:
Three examples of `extern crate` declarations:

```{.ignore}
extern crate pcre;
Expand Down
12 changes: 6 additions & 6 deletions src/etc/vim/autoload/rust.vim
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,14 @@ function! s:WithPath(func, ...)
call mkdir(tmpdir)

let save_cwd = getcwd()
silent exe 'lcd' tmpdir
silent exe 'lcd' fnameescape(tmpdir)

let path = 'unnamed.rs'

let save_mod = &mod
set nomod

silent exe 'keepalt write! ' . path
silent exe 'keepalt write! ' . fnameescape(path)
if pathisempty
silent keepalt 0file
endif
Expand All @@ -195,10 +195,10 @@ function! s:WithPath(func, ...)

call call(a:func, [path] + a:000)
finally
if exists("save_mod") | let &mod = save_mod | endif
if exists("save_write") | let &write = save_write | endif
if exists("save_cwd") | silent exe 'lcd' save_cwd | endif
if exists("tmpdir") | silent call s:RmDir(tmpdir) | endif
if exists("save_mod") | let &mod = save_mod | endif
if exists("save_write") | let &write = save_write | endif
if exists("save_cwd") | silent exe 'lcd' fnameescape(save_cwd) | endif
if exists("tmpdir") | silent call s:RmDir(tmpdir) | endif
endtry
endfunction

Expand Down
1 change: 0 additions & 1 deletion src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@

#![stable]

use clone::Clone;
use cmp::PartialEq;
use std::fmt::Show;
use slice;
Expand Down
1 change: 0 additions & 1 deletion src/libcore/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use mem;
use char;
use char::Char;
use clone::Clone;
use cmp;
use cmp::{PartialEq, Eq};
use default::Default;
Expand Down
7 changes: 7 additions & 0 deletions src/librand/distributions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ fn ziggurat<R:Rng>(
// creating a f64), so we might as well reuse some to save
// generating a whole extra random number. (Seems to be 15%
// faster.)
//
// This unfortunately misses out on the benefits of direct
// floating point generation if an RNG like dSMFT is
// used. (That is, such RNGs create floats directly, highly
// efficiently and overload next_f32/f64, so by not calling it
// this may be slower than it would be otherwise.)
// FIXME: investigate/optimise for the above.
let bits: u64 = rng.gen();
let i = (bits & 0xff) as uint;
let f = (bits >> 11) as f64 / SCALE;
Expand Down
40 changes: 40 additions & 0 deletions src/librand/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,46 @@ pub trait Rng {
(self.next_u32() as u64 << 32) | (self.next_u32() as u64)
}

/// Return the next random f32 selected from the half-open
/// interval `[0, 1)`.
///
/// By default this is implemented in terms of `next_u32`, but a
/// random number generator which can generate numbers satisfying
/// the requirements directly can overload this for performance.
/// It is required that the return value lies in `[0, 1)`.
///
/// See `Closed01` for the closed interval `[0,1]`, and
/// `Open01` for the open interval `(0,1)`.
fn next_f32(&mut self) -> f32 {
const MANTISSA_BITS: uint = 24;
const IGNORED_BITS: uint = 8;
const SCALE: f32 = (1u64 << MANTISSA_BITS) as f32;

// using any more than `MANTISSA_BITS` bits will
// cause (e.g.) 0xffff_ffff to correspond to 1
// exactly, so we need to drop some (8 for f32, 11
// for f64) to guarantee the open end.
(self.next_u32() >> IGNORED_BITS) as f32 / SCALE
}

/// Return the next random f64 selected from the half-open
/// interval `[0, 1)`.
///
/// By default this is implemented in terms of `next_u64`, but a
/// random number generator which can generate numbers satisfying
/// the requirements directly can overload this for performance.
/// It is required that the return value lies in `[0, 1)`.
///
/// See `Closed01` for the closed interval `[0,1]`, and
/// `Open01` for the open interval `(0,1)`.
fn next_f64(&mut self) -> f64 {
const MANTISSA_BITS: uint = 53;
const IGNORED_BITS: uint = 11;
const SCALE: f64 = (1u64 << MANTISSA_BITS) as f64;

(self.next_u64() >> IGNORED_BITS) as f64 / SCALE
}

/// Fill `dest` with random data.
///
/// This has a default implementation in terms of `next_u64` and
Expand Down
23 changes: 9 additions & 14 deletions src/librand/rand_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ impl Rand for u64 {
}

macro_rules! float_impls {
($mod_name:ident, $ty:ty, $mantissa_bits:expr, $method_name:ident, $ignored_bits:expr) => {
($mod_name:ident, $ty:ty, $mantissa_bits:expr, $method_name:ident) => {
mod $mod_name {
use {Rand, Rng, Open01, Closed01};

static SCALE: $ty = (1u64 << $mantissa_bits) as $ty;
const SCALE: $ty = (1u64 << $mantissa_bits) as $ty;

impl Rand for $ty {
/// Generate a floating point number in the half-open
Expand All @@ -110,11 +110,7 @@ macro_rules! float_impls {
/// and `Open01` for the open interval `(0,1)`.
#[inline]
fn rand<R: Rng>(rng: &mut R) -> $ty {
// using any more than `mantissa_bits` bits will
// cause (e.g.) 0xffff_ffff to correspond to 1
// exactly, so we need to drop some (8 for f32, 11
// for f64) to guarantee the open end.
(rng.$method_name() >> $ignored_bits) as $ty / SCALE
rng.$method_name()
}
}
impl Rand for Open01<$ty> {
Expand All @@ -124,23 +120,22 @@ macro_rules! float_impls {
// the precision of f64/f32 at 1.0), so that small
// numbers are larger than 0, but large numbers
// aren't pushed to/above 1.
Open01(((rng.$method_name() >> $ignored_bits) as $ty + 0.25) / SCALE)
Open01(rng.$method_name() + 0.25 / SCALE)
}
}
impl Rand for Closed01<$ty> {
#[inline]
fn rand<R: Rng>(rng: &mut R) -> Closed01<$ty> {
// divide by the maximum value of the numerator to
// get a non-zero probability of getting exactly
// 1.0.
Closed01((rng.$method_name() >> $ignored_bits) as $ty / (SCALE - 1.0))
// rescale so that 1.0 - epsilon becomes 1.0
// precisely.
Closed01(rng.$method_name() * SCALE / (SCALE - 1.0))
}
}
}
}
}
float_impls! { f64_rand_impls, f64, 53, next_u64, 11 }
float_impls! { f32_rand_impls, f32, 24, next_u32, 8 }
float_impls! { f64_rand_impls, f64, 53, next_f64 }
float_impls! { f32_rand_impls, f32, 24, next_f32 }

impl Rand for char {
#[inline]
Expand Down
20 changes: 10 additions & 10 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use std::cmp;
use std::collections::HashMap;
use std::collections::hash_map::{Occupied, Vacant};
use std::slice;
use std::{int, i8, i16, i32, i64, uint, u8, u16, u32, u64, f32, f64};
use std::{i8, i16, i32, i64, u8, u16, u32, u64, f32, f64};
use syntax::abi;
use syntax::ast_map;
use syntax::ast_util::is_shift_binop;
Expand Down Expand Up @@ -180,19 +180,19 @@ impl LintPass for TypeLimits {

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

if let Some(bits) = opt_ty_bits {
let exceeding = if let ast::ExprLit(ref lit) = r.node {
if let ast::LitInt(shift, _) = lit.node { shift > bits }
if let ast::LitInt(shift, _) = lit.node { shift >= bits }
else { false }
} else {
match eval_const_expr_partial(cx.tcx, &**r) {
Ok(const_int(shift)) => { shift as u64 > bits },
Ok(const_uint(shift)) => { shift > bits },
Ok(const_int(shift)) => { shift as u64 >= bits },
Ok(const_uint(shift)) => { shift >= bits },
_ => { false }
}
};
Expand Down Expand Up @@ -312,19 +312,19 @@ impl LintPass for TypeLimits {
}
}

fn int_ty_bits(int_ty: ast::IntTy) -> u64 {
fn int_ty_bits(int_ty: ast::IntTy, target_int_ty: ast::IntTy) -> u64 {
match int_ty {
ast::TyI => int::BITS as u64,
ast::TyI => int_ty_bits(target_int_ty, target_int_ty),
ast::TyI8 => i8::BITS as u64,
ast::TyI16 => i16::BITS as u64,
ast::TyI32 => i32::BITS as u64,
ast::TyI64 => i64::BITS as u64
}
}

fn uint_ty_bits(uint_ty: ast::UintTy) -> u64 {
fn uint_ty_bits(uint_ty: ast::UintTy, target_uint_ty: ast::UintTy) -> u64 {
match uint_ty {
ast::TyU => uint::BITS as u64,
ast::TyU => uint_ty_bits(target_uint_ty, target_uint_ty),
ast::TyU8 => u8::BITS as u64,
ast::TyU16 => u16::BITS as u64,
ast::TyU32 => u32::BITS as u64,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
}
}

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

// Output any lints that were previously added to the session.
impl<'a, 'tcx> IdVisitingOperation for Context<'a, 'tcx> {
fn visit_id(&self, id: ast::NodeId) {
fn visit_id(&mut self, id: ast::NodeId) {
match self.tcx.sess.lints.borrow_mut().pop(&id) {
None => {}
Some(lints) => {
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/metadata/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl astencode_tag {
pub fn from_uint(value : uint) -> Option<astencode_tag> {
let is_a_tag = first_astencode_tag <= value && value <= last_astencode_tag;
if !is_a_tag { None } else {
Some(unsafe { mem::transmute(value) })
Some(unsafe { mem::transmute::<uint, astencode_tag>(value) })
}
}
}
Expand Down Expand Up @@ -247,4 +247,3 @@ pub const tag_type_param_def: uint = 0xa5;

pub const tag_item_generics: uint = 0xa6;
pub const tag_method_ty_generics: uint = 0xa7;

Loading