Skip to content

Slightly less mini rollup #23200

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 28 commits into from
Mar 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9b873fa
Fix missed doc grammar rule rename from vec_elems to array_elems
alancutter Mar 1, 2015
33d8a4e
Rearrange tests to be in the same order as implementation
carols10cents Feb 14, 2015
8f091ef
Add tests to stable f32 and f64 methods that didn't have any
carols10cents Feb 14, 2015
1bda1ff
Removing unnecessary pub from a test function
carols10cents Mar 2, 2015
f81f8d8
Register new snapshots (270a677)
Manishearth Mar 7, 2015
52124d7
Fix #23166. Get the Compiler Plugins example compiling again.
rprichard Mar 8, 2015
ead9ab8
Auto merge of #23167 - rprichard:fix-plugin-rustbook, r=steveklabnik
bors Mar 8, 2015
6dcc0e5
Adds an example for PhantomData<T>.
golddranks Mar 2, 2015
3ad1c83
Add description of fold function arguments.
hauleth Mar 2, 2015
45c397d
Fix array syntax in comment.
munds Feb 23, 2015
de44baa
Add default methods to trait documentation
steveklabnik Mar 4, 2015
e56fcbc
Remove reference to NoSend in concurrency chapter of the book
steveklabnik Mar 8, 2015
ce223a6
Mention deref coercions in the String guide.
steveklabnik Mar 8, 2015
5b0acb5
remove 'generally' to reduce confusion
steveklabnik Mar 8, 2015
d65064d
Move 'more strings' after ownership
steveklabnik Mar 8, 2015
044b3bf
Add examples of all three syntaxes in method syntax chapter of trpl
steveklabnik Mar 8, 2015
509c6fc
Rollup merge of #22984 - carols10cents:tests-for-float, r=huonw
Manishearth Mar 8, 2015
0e0bb8a
Rollup merge of #23179 - steveklabnik:mini_rollup, r=steveklabnik
Manishearth Mar 8, 2015
f7c1fce
Rollup merge of #23153 - Manishearth:snap, r=alexcrichton
Manishearth Mar 8, 2015
1149b4d
Rollup merge of #22917 - randfur:master, r=steveklabnik
Manishearth Mar 8, 2015
ea8434f
Rollup merge of #23043 - steveklabnik:doc_default_method, r=nikomatsakis
Manishearth Mar 8, 2015
d1ac69c
Rollup merge of #23180 - steveklabnik:gh23052, r=alexcrichton
Manishearth Mar 8, 2015
c7d5354
Rollup merge of #23181 - steveklabnik:gh22637, r=alexcrichton
Manishearth Mar 8, 2015
b515b4e
Rollup merge of #23184 - steveklabnik:gh22553, r=alexcrichton
Manishearth Mar 8, 2015
10960d3
Rollup merge of #23188 - steveklabnik:gh18787, r=alexcrichton
Manishearth Mar 8, 2015
9f851a7
Rollup merge of #23190 - steveklabnik:fix_as_slice, r=alexcrichton
Manishearth Mar 8, 2015
684cd77
Rollup merge of #23182 - steveklabnik:gh22610, r=Manishearth
Manishearth Mar 8, 2015
3797827
Fix doctest (fixup #23188)
Manishearth Mar 9, 2015
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
2 changes: 1 addition & 1 deletion src/doc/grammar.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ field_expr : expr '.' ident ;
### Array expressions

```antlr
array_expr : '[' "mut" ? vec_elems? ']' ;
array_expr : '[' "mut" ? array_elems? ']' ;

array_elems : [expr [',' expr]*] | [expr ',' ".." expr] ;
```
Expand Down
2 changes: 1 addition & 1 deletion src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2847,7 +2847,7 @@ automatically dereferenced to make the field access possible.
### Array expressions

```{.ebnf .gram}
array_expr : '[' "mut" ? vec_elems? ']' ;
array_expr : '[' "mut" ? array_elems? ']' ;

array_elems : [expr [',' expr]*] | [expr ';' expr] ;
```
Expand Down
2 changes: 1 addition & 1 deletion src/doc/trpl/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
* [Standard Input](standard-input.md)
* [Guessing Game](guessing-game.md)
* [II: Intermediate Rust](intermediate.md)
* [More Strings](more-strings.md)
* [Crates and Modules](crates-and-modules.md)
* [Testing](testing.md)
* [Pointers](pointers.md)
* [Ownership](ownership.md)
* [More Strings](more-strings.md)
* [Patterns](patterns.md)
* [Method Syntax](method-syntax.md)
* [Closures](closures.md)
Expand Down
11 changes: 2 additions & 9 deletions src/doc/trpl/concurrency.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,8 @@ method which has this signature:
fn lock(&self) -> LockResult<MutexGuard<T>>
```

If we [look at the code for MutexGuard](https://github.com/rust-lang/rust/blob/ca4b9674c26c1de07a2042cb68e6a062d7184cef/src/libstd/sync/mutex.rs#L172), we'll see
this:

```ignore
__marker: marker::NoSend,
```

Because our guard is `NoSend`, it's not `Send`. Which means we can't actually
transfer the guard across thread boundaries, which gives us our error.
Because `Send` is not implemented for `MutexGuard<T>`, we can't transfer the
guard across thread boundaries, which gives us our error.

We can use `Arc<T>` to fix this. Here's the working version:

Expand Down
24 changes: 23 additions & 1 deletion src/doc/trpl/method-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,29 @@ You can think of this first parameter as being the `x` in `x.foo()`. The three
variants correspond to the three kinds of thing `x` could be: `self` if it's
just a value on the stack, `&self` if it's a reference, and `&mut self` if it's
a mutable reference. We should default to using `&self`, as it's the most
common.
common. Here's an example of all three variants:

```rust
struct Circle {
x: f64,
y: f64,
radius: f64,
}

impl Circle {
fn reference(&self) {
println!("taking self by reference!");
}

fn mutable_reference(&mut self) {
println!("taking self by mutable reference!");
}

fn takes_ownership(self) {
println!("taking ownership of self!");
}
}
```

Finally, as you may remember, the value of the area of a circle is `π*r²`.
Because we took the `&self` parameter to `area`, we can use it just like any
Expand Down
17 changes: 14 additions & 3 deletions src/doc/trpl/more-strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,18 @@ This will print:

Many more bytes than graphemes!

# Other Documentation
# `Deref` coercions

* [the `&str` API documentation](../std/str/index.html)
* [the `String` API documentation](../std/string/index.html)
References to `String`s will automatically coerce into `&str`s. Like this:

```
fn hello(s: &str) {
println!("Hello, {}!", s);
}

let slice = "Steve";
let string = "Steve".to_string();

hello(slice);
hello(&string);
```
8 changes: 4 additions & 4 deletions src/doc/trpl/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ that implements Roman numeral integer literals.

```ignore
#![crate_type="dylib"]
#![feature(plugin_registrar)]
#![feature(plugin_registrar, rustc_private)]

extern crate syntax;
extern crate rustc;
Expand Down Expand Up @@ -92,13 +92,13 @@ fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
}
};

let mut text = &text;
let mut text = &*text;
let mut total = 0;
while !text.is_empty() {
match NUMERALS.iter().find(|&&(rn, _)| text.starts_with(rn)) {
Some(&(rn, val)) => {
total += val;
text = text.slice_from(rn.len());
text = &text[rn.len()..];
}
None => {
cx.span_err(sp, "invalid Roman numeral");
Expand All @@ -107,7 +107,7 @@ fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
}
}

MacEager::expr(cx.expr_usize(sp, total))
MacEager::expr(cx.expr_u32(sp, total))
}

#[plugin_registrar]
Expand Down
4 changes: 2 additions & 2 deletions src/doc/trpl/pointers.md
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,8 @@ use-case for boxes.
### Returning data

This is important enough to have its own section entirely. The TL;DR is this:
you don't generally want to return pointers, even when you might in a language
like C or C++.
you don't want to return pointers, even when you might in a language like C or
C++.

See [Returning Pointers](#returning-pointers) below for more.

Expand Down
43 changes: 43 additions & 0 deletions src/doc/trpl/traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,3 +435,46 @@ println!("the inverse of {} is {:?}", 2.0f64, inverse(2.0f64));
println!("the inverse of {} is {:?}", 0.0f32, inverse(0.0f32));
println!("the inverse of {} is {:?}", 0.0f64, inverse(0.0f64));
```

## Default methods

There's one last feature of traits we should cover: default methods. It's
easiest just to show an example:

```rust
trait Foo {
fn bar(&self);

fn baz(&self) { println!("We called baz."); }
}
```

Implementors of the `Foo` trait need to implement `bar()`, but they don't
need to implement `baz()`. They'll get this default behavior. They can
override the default if they so choose:

```rust
# trait Foo {
# fn bar(&self);
# fn baz(&self) { println!("We called baz."); }
# }
struct UseDefault;

impl Foo for UseDefault {
fn bar(&self) { println!("We called bar."); }
}

struct OverrideDefault;

impl Foo for OverrideDefault {
fn bar(&self) { println!("We called bar."); }

fn baz(&self) { println!("Override baz!"); }
}

let default = UseDefault;
default.baz(); // prints "We called bar."

let over = OverrideDefault;
over.baz(); // prints "Override baz!"
```
4 changes: 0 additions & 4 deletions src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,11 +545,7 @@ extern "rust-intrinsic" {
pub fn u32_mul_with_overflow(x: u32, y: u32) -> (u32, bool);
/// Performs checked `u64` multiplication.
pub fn u64_mul_with_overflow(x: u64, y: u64) -> (u64, bool);
}

// SNAP 880fb89
#[cfg(not(stage0))]
extern "rust-intrinsic" {
/// Returns (a + b) mod 2^N, where N is the width of N in bits.
pub fn overflowing_add<T>(a: T, b: T) -> T;
/// Returns (a - b) mod 2^N, where N is the width of N in bits.
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ pub trait IteratorExt: Iterator + Sized {
///
/// ```
/// let a = [1, 2, 3, 4, 5];
/// assert!(a.iter().fold(0, |a, &b| a + b) == 15);
/// assert!(a.iter().fold(0, |acc, &item| acc + item) == 15);
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
40 changes: 39 additions & 1 deletion src/libcore/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,45 @@ pub trait PhantomFn<A:?Sized,R:?Sized=()> { }
/// instance, it will behave *as if* an instance of the type `T` were
/// present for the purpose of various automatic analyses.
///
/// For example, embedding a `PhantomData<T>` will inform the compiler
/// # Examples
///
/// When handling external resources over a foreign function interface, `PhantomData<T>` can
/// prevent mismatches by enforcing types in the method implementations, although the struct
/// doesn't actually contain values of the resource type.
///
/// ```
/// # trait ResType { fn foo(&self); };
/// # struct ParamType;
/// # mod foreign_lib {
/// # pub fn new(_: usize) -> *mut () { 42 as *mut () }
/// # pub fn do_stuff(_: *mut (), _: usize) {}
/// # }
/// # fn convert_params(_: ParamType) -> usize { 42 }
/// use std::marker::PhantomData;
/// use std::mem;
///
/// struct ExternalResource<R> {
/// resource_handle: *mut (),
/// resource_type: PhantomData<R>,
/// }
///
/// impl<R: ResType> ExternalResource<R> {
/// fn new() -> ExternalResource<R> {
/// let size_of_res = mem::size_of::<R>();
/// ExternalResource {
/// resource_handle: foreign_lib::new(size_of_res),
/// resource_type: PhantomData,
/// }
/// }
///
/// fn do_stuff(&self, param: ParamType) {
/// let foreign_params = convert_params(param);
/// foreign_lib::do_stuff(self.resource_handle, foreign_params);
/// }
/// }
/// ```
///
/// Another example: embedding a `PhantomData<T>` will inform the compiler
/// that one or more instances of the type `T` could be dropped when
/// instances of the type itself is dropped, though that may not be
/// apparent from the other structure of the type itself. This is
Expand Down
22 changes: 0 additions & 22 deletions src/libcore/num/wrapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

use ops::*;

#[cfg(not(stage0))]
use intrinsics::{overflowing_add, overflowing_sub, overflowing_mul};

use intrinsics::{i8_add_with_overflow, u8_add_with_overflow};
Expand Down Expand Up @@ -40,7 +39,6 @@ pub trait OverflowingOps {
fn overflowing_mul(self, rhs: Self) -> (Self, bool);
}

#[cfg(not(stage0))]
macro_rules! wrapping_impl {
($($t:ty)*) => ($(
impl WrappingOps for $t {
Expand All @@ -66,26 +64,6 @@ macro_rules! wrapping_impl {
)*)
}

#[cfg(stage0)]
macro_rules! wrapping_impl {
($($t:ty)*) => ($(
impl WrappingOps for $t {
#[inline(always)]
fn wrapping_add(self, rhs: $t) -> $t {
self + rhs
}
#[inline(always)]
fn wrapping_sub(self, rhs: $t) -> $t {
self - rhs
}
#[inline(always)]
fn wrapping_mul(self, rhs: $t) -> $t {
self * rhs
}
}
)*)
}

wrapping_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 }

#[unstable(feature = "core", reason = "may be removed, renamed, or relocated")]
Expand Down
Loading