]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #30278 - steveklabnik:rollup, r=steveklabnik
authorbors <bors@rust-lang.org>
Wed, 9 Dec 2015 06:05:08 +0000 (06:05 +0000)
committerbors <bors@rust-lang.org>
Wed, 9 Dec 2015 06:05:08 +0000 (06:05 +0000)
- Successful merges: #30201, #30224, #30261, #30273, #30274
- Failed merges:

src/doc/book/traits.md
src/doc/reference.md
src/libcollections/vec.rs
src/libcore/iter.rs
src/librustc/diagnostics.rs
src/libstd/io/error.rs
src/libstd/io/mod.rs
src/test/run-fail/overflowing-rsh-5.rs [new file with mode: 0644]
src/test/run-fail/overflowing-rsh-6.rs [new file with mode: 0644]

index 01cd20bc792d2a803d2072469ec3556f7455bfa1..f9e3299f9e726c2d4db86c2a6ca1b37fc219ea24 100644 (file)
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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()
     }
 }
 
@@ -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:
 
index 98074f09441c4b0e3a220f14dcdeeca803f21be4..0262ff5a71aadc65a1d313950362a9ded50c800c 100644 (file)
@@ -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
index 89b1b99cfa39d1370fb6b2dd4c1ae58ddb3b948b..ddad7533a081f8f89d2649f6c5399f53475c9309 100644 (file)
@@ -920,21 +920,7 @@ fn extend_with_element(&mut self, n: usize, value: 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",
index 86c00a254ca22b84fab28b5c0865583576c034e5..959b6a97c5ccbacbcfdae275fe5efe0cfba13ac0 100644 (file)
@@ -1893,21 +1893,7 @@ fn min(self) -> Option<Self::Item> where Self: Sized, Self::Item: Ord
             .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",
@@ -1945,22 +1931,8 @@ fn max_by_key<B: Ord, F>(self, f: F) -> Option<Self::Item>
             .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")]
index b09dbe161f42ac018979a966b9cf3846ffd7f648..86dd363993aec5c0720129ec28d9d81bde0610b4 100644 (file)
@@ -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;
@@ -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:
@@ -2242,7 +2259,6 @@ impl Foo {
     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
index 4af9596d6d0e91b8b0ca1a724a80f7a0e61ea6bf..1ff8f572a7f571cf179e9a9b3412b74d7a624a13 100644 (file)
@@ -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")]
index e957297bf6235d8d7a061e6c9dde3ae762e37565..efe40cf07c130981514329179759805502c9a57e 100644 (file)
@@ -576,7 +576,7 @@ fn read_to_string(&mut self, buf: &mut String) -> Result<usize> {
     /// 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
diff --git a/src/test/run-fail/overflowing-rsh-5.rs b/src/test/run-fail/overflowing-rsh-5.rs
new file mode 100644 (file)
index 0000000..34a7ff8
--- /dev/null
@@ -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];
+}
diff --git a/src/test/run-fail/overflowing-rsh-6.rs b/src/test/run-fail/overflowing-rsh-6.rs
new file mode 100644 (file)
index 0000000..b6f4348
--- /dev/null
@@ -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];
+}