diff --git a/src/doc/book/traits.md b/src/doc/book/traits.md index 01cd20bc792d2..f9e3299f9e726 100644 --- a/src/doc/book/traits.md +++ b/src/doc/book/traits.md @@ -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 ``` 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`. 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: diff --git a/src/doc/reference.md b/src/doc/reference.md index 98074f09441c4..0262ff5a71aad 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -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 diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 89b1b99cfa39d..ddad7533a081f 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -920,21 +920,7 @@ impl Vec { } } - /// 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", diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 86c00a254ca22..959b6a97c5ccb 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -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", @@ -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")] diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index b09dbe161f42a..86dd363993aec 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -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 @@ 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 diff --git a/src/libstd/io/error.rs b/src/libstd/io/error.rs index 4af9596d6d0e9..1ff8f572a7f57 100644 --- a/src/libstd/io/error.rs +++ b/src/libstd/io/error.rs @@ -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")] diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index e957297bf6235..efe40cf07c130 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -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 diff --git a/src/test/run-fail/overflowing-rsh-5.rs b/src/test/run-fail/overflowing-rsh-5.rs new file mode 100644 index 0000000000000..34a7ff833bbbd --- /dev/null +++ b/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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// error-pattern:thread '
' 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 index 0000000000000..b6f4348b184de --- /dev/null +++ b/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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// error-pattern:thread '
' panicked at 'shift operation overflowed' +// compile-flags: -C debug-assertions + +#![warn(exceeding_bitshifts)] +#![feature(const_indexing)] + +fn main() { + let _n = 1i64 >> [64][0]; +}