Skip to content

Commit

Permalink
Auto merge of #30278 - steveklabnik:rollup, r=steveklabnik
Browse files Browse the repository at this point in the history
- Successful merges: #30201, #30224, #30261, #30273, #30274
- Failed merges:
  • Loading branch information
bors committed Dec 9, 2015
2 parents 4005d43 + e78629e commit 6f95ae6
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 68 deletions.
24 changes: 10 additions & 14 deletions src/doc/book/traits.md
Expand Up @@ -3,8 +3,8 @@
A trait is a language feature that tells the Rust compiler about
functionality a type must provide.

Do you remember the `impl` keyword, used to call a function with [method
syntax][methodsyntax]?
Recall the `impl` keyword, used to call a function with [method
syntax][methodsyntax]:

```rust
struct Circle {
Expand All @@ -22,8 +22,8 @@ impl Circle {

[methodsyntax]: method-syntax.html

Traits are similar, except that we define a trait with just the method
signature, then implement the trait for that struct. Like this:
Traits are similar, except that we first define a trait with a method
signature, then implement the trait for a type. In this example, we implement the trait `HasArea` for `Circle`:

```rust
struct Circle {
Expand Down Expand Up @@ -399,15 +399,13 @@ fn inverse<T>() -> T
```

This shows off the additional feature of `where` clauses: they allow bounds
where the left-hand side is an arbitrary type (`i32` in this case), not just a
plain type parameter (like `T`). In this example, `i32` must implement
on the left-hand side not only of type parameters `T`, but also of types (`i32` in this case). In this example, `i32` must implement
`ConvertTo<T>`. Rather than defining what `i32` is (since that's obvious), the
`where` clause here is a constraint on `T`.
`where` clause here constrains `T`.

# Default methods

If you already know how a typical implementor will define a method, you can
let your trait supply a default:
A default method can be added to a trait definition if it is already known how a typical implementor will define a method. For example, `is_invalid()` is defined as the opposite of `is_valid()`:

```rust
trait Foo {
Expand All @@ -417,9 +415,7 @@ trait Foo {
}
```

Implementors of the `Foo` trait need to implement `is_valid()`, but they don’t
need to implement `is_invalid()`. They’ll get this default behavior. They can
override the default if they so choose:
Implementors of the `Foo` trait need to implement `is_valid()` but not `is_invalid()` due to the added default behavior. This default behavior can still be overridden as in:

```rust
# trait Foo {
Expand All @@ -446,7 +442,7 @@ impl Foo for OverrideDefault {

fn is_invalid(&self) -> bool {
println!("Called OverrideDefault.is_invalid!");
true // this implementation is a self-contradiction!
true // overrides the expected value of is_invalid()
}
}

Expand Down Expand Up @@ -499,7 +495,7 @@ error: the trait `main::Foo` is not implemented for the type `main::Baz` [E0277]

# Deriving

Implementing traits like `Debug` and `Default` over and over again can become
Implementing traits like `Debug` and `Default` repeatedly can become
quite tedious. For that reason, Rust provides an [attribute][attributes] that
allows you to let Rust automatically implement traits for you:

Expand Down
19 changes: 19 additions & 0 deletions src/doc/reference.md
Expand Up @@ -515,6 +515,25 @@ fn bar() {
# fn main() {}
```

Additionally keyword `super` may be repeated several times after the first
`super` or `self` to refer to ancestor modules.

```rust
mod a {
fn foo() {}

mod b {
mod c {
fn foo() {
super::super::foo(); // call a's foo function
self::super::super::foo(); // call a's foo function
}
}
}
}
# fn main() {}
```

# Syntax extensions

A number of minor features of Rust are not central enough to have their own
Expand Down
16 changes: 1 addition & 15 deletions src/libcollections/vec.rs
Expand Up @@ -920,21 +920,7 @@ impl<T: Clone> Vec<T> {
}
}

/// Appends all elements in a slice to the `Vec`.
///
/// Iterates over the slice `other`, clones each element, and then appends
/// it to this `Vec`. The `other` vector is traversed in-order.
///
/// # Examples
///
/// ```
/// #![feature(vec_push_all)]
/// #![allow(deprecated)]
///
/// let mut vec = vec![1];
/// vec.push_all(&[2, 3, 4]);
/// assert_eq!(vec, [1, 2, 3, 4]);
/// ```
#[allow(missing_docs)]
#[inline]
#[unstable(feature = "vec_push_all",
reason = "likely to be replaced by a more optimized extend",
Expand Down
32 changes: 2 additions & 30 deletions src/libcore/iter.rs
Expand Up @@ -1893,21 +1893,7 @@ pub trait Iterator {
.map(|(_, x)| x)
}

/// Returns the element that gives the maximum value from the
/// specified function.
///
/// Returns the rightmost element if the comparison determines two elements
/// to be equally maximum.
///
/// # Examples
///
/// ```
/// #![feature(iter_cmp)]
/// #![allow(deprecated)]
///
/// let a = [-3_i32, 0, 1, 5, -10];
/// assert_eq!(*a.iter().max_by(|x| x.abs()).unwrap(), -10);
/// ```
#[allow(missing_docs)]
#[inline]
#[unstable(feature = "iter_cmp",
reason = "may want to produce an Ordering directly; see #15311",
Expand Down Expand Up @@ -1945,22 +1931,8 @@ pub trait Iterator {
.map(|(_, x)| x)
}

/// Returns the element that gives the minimum value from the
/// specified function.
///
/// Returns the latest element if the comparison determines two elements
/// to be equally minimum.
///
/// # Examples
///
/// ```
/// #![feature(iter_cmp)]
/// #![allow(deprecated)]
///
/// let a = [-3_i32, 0, 1, 5, -10];
/// assert_eq!(*a.iter().min_by(|x| x.abs()).unwrap(), 0);
/// ```
#[inline]
#[allow(missing_docs)]
#[unstable(feature = "iter_cmp",
reason = "may want to produce an Ordering directly; see #15311",
issue = "27724")]
Expand Down
20 changes: 18 additions & 2 deletions src/librustc/diagnostics.rs
Expand Up @@ -1948,7 +1948,7 @@ fn main() {
You cannot directly use a dereference operation whilst initializing a constant
or a static. To fix this error, restructure your code to avoid this dereference,
perharps moving it inline:
perhaps moving it inline:
```
use std::ops::Deref;
Expand All @@ -1967,6 +1967,23 @@ fn main() {
```
"##,

E0452: r##"
An invalid lint attribute has been given. Erroneous code example:
```
#![allow(foo = "")] // error: malformed lint attribute
```
Lint attributes only accept a list of identifiers (where each identifier is a
lint name). Ensure the attribute is of this form:
```
#![allow(foo)] // ok!
// or:
#![allow(foo, foo2)] // ok!
```
"##,

E0492: r##"
A borrow of a constant containing interior mutability was attempted. Erroneous
code example:
Expand Down Expand Up @@ -2242,7 +2259,6 @@ register_diagnostics! {
E0314, // closure outlives stack frame
E0315, // cannot invoke closure outside of its lifetime
E0316, // nested quantification of lifetimes
E0452, // malformed lint attribute
E0453, // overruled by outer forbid
E0471, // constant evaluation error: ..
E0472, // asm! is unsupported on this target
Expand Down
7 changes: 1 addition & 6 deletions src/libstd/io/error.rs
Expand Up @@ -150,12 +150,7 @@ pub enum ErrorKind {
#[stable(feature = "rust1", since = "1.0.0")]
Other,

/// An error returned when an operation could not be completed because an
/// "end of file" was reached prematurely.
///
/// This typically means that an operation could only succeed if it read a
/// particular number of bytes but only a smaller number of bytes could be
/// read.
#[allow(missing_docs)]
#[unstable(feature = "read_exact_old", reason = "recently added",
issue = "0")]
#[rustc_deprecated(since = "1.6.0", reason = "renamed to UnexpectedEof")]
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/io/mod.rs
Expand Up @@ -576,7 +576,7 @@ pub trait Read {
/// will continue.
///
/// If this function encounters an "end of file" before completely filling
/// the buffer, it returns an error of the kind `ErrorKind::UnexpectedEOF`.
/// the buffer, it returns an error of the kind `ErrorKind::UnexpectedEof`.
/// The contents of `buf` are unspecified in this case.
///
/// If any other read error is encountered then this function immediately
Expand Down
18 changes: 18 additions & 0 deletions src/test/run-fail/overflowing-rsh-5.rs
@@ -0,0 +1,18 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern:thread '<main>' panicked at 'shift operation overflowed'
// compile-flags: -C debug-assertions

#![warn(exceeding_bitshifts)]

fn main() {
let _n = 1i64 >> [64][0];
}
19 changes: 19 additions & 0 deletions src/test/run-fail/overflowing-rsh-6.rs
@@ -0,0 +1,19 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern:thread '<main>' panicked at 'shift operation overflowed'
// compile-flags: -C debug-assertions

#![warn(exceeding_bitshifts)]
#![feature(const_indexing)]

fn main() {
let _n = 1i64 >> [64][0];
}

0 comments on commit 6f95ae6

Please sign in to comment.