Skip to content

Commit 6f95ae6

Browse files
author
bors
committed
Auto merge of rust-lang#30278 - steveklabnik:rollup, r=steveklabnik
- Successful merges: rust-lang#30201, rust-lang#30224, rust-lang#30261, rust-lang#30273, rust-lang#30274 - Failed merges:
2 parents 4005d43 + e78629e commit 6f95ae6

File tree

9 files changed

+89
-68
lines changed

9 files changed

+89
-68
lines changed

src/doc/book/traits.md

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
A trait is a language feature that tells the Rust compiler about
44
functionality a type must provide.
55

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

99
```rust
1010
struct Circle {
@@ -22,8 +22,8 @@ impl Circle {
2222

2323
[methodsyntax]: method-syntax.html
2424

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

2828
```rust
2929
struct Circle {
@@ -399,15 +399,13 @@ fn inverse<T>() -> T
399399
```
400400

401401
This shows off the additional feature of `where` clauses: they allow bounds
402-
where the left-hand side is an arbitrary type (`i32` in this case), not just a
403-
plain type parameter (like `T`). In this example, `i32` must implement
402+
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
404403
`ConvertTo<T>`. Rather than defining what `i32` is (since that's obvious), the
405-
`where` clause here is a constraint on `T`.
404+
`where` clause here constrains `T`.
406405

407406
# Default methods
408407

409-
If you already know how a typical implementor will define a method, you can
410-
let your trait supply a default:
408+
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()`:
411409

412410
```rust
413411
trait Foo {
@@ -417,9 +415,7 @@ trait Foo {
417415
}
418416
```
419417

420-
Implementors of the `Foo` trait need to implement `is_valid()`, but they don’t
421-
need to implement `is_invalid()`. They’ll get this default behavior. They can
422-
override the default if they so choose:
418+
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:
423419

424420
```rust
425421
# trait Foo {
@@ -446,7 +442,7 @@ impl Foo for OverrideDefault {
446442

447443
fn is_invalid(&self) -> bool {
448444
println!("Called OverrideDefault.is_invalid!");
449-
true // this implementation is a self-contradiction!
445+
true // overrides the expected value of is_invalid()
450446
}
451447
}
452448

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

500496
# Deriving
501497

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

src/doc/reference.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,25 @@ fn bar() {
515515
# fn main() {}
516516
```
517517

518+
Additionally keyword `super` may be repeated several times after the first
519+
`super` or `self` to refer to ancestor modules.
520+
521+
```rust
522+
mod a {
523+
fn foo() {}
524+
525+
mod b {
526+
mod c {
527+
fn foo() {
528+
super::super::foo(); // call a's foo function
529+
self::super::super::foo(); // call a's foo function
530+
}
531+
}
532+
}
533+
}
534+
# fn main() {}
535+
```
536+
518537
# Syntax extensions
519538

520539
A number of minor features of Rust are not central enough to have their own

src/libcollections/vec.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -920,21 +920,7 @@ impl<T: Clone> Vec<T> {
920920
}
921921
}
922922

923-
/// Appends all elements in a slice to the `Vec`.
924-
///
925-
/// Iterates over the slice `other`, clones each element, and then appends
926-
/// it to this `Vec`. The `other` vector is traversed in-order.
927-
///
928-
/// # Examples
929-
///
930-
/// ```
931-
/// #![feature(vec_push_all)]
932-
/// #![allow(deprecated)]
933-
///
934-
/// let mut vec = vec![1];
935-
/// vec.push_all(&[2, 3, 4]);
936-
/// assert_eq!(vec, [1, 2, 3, 4]);
937-
/// ```
923+
#[allow(missing_docs)]
938924
#[inline]
939925
#[unstable(feature = "vec_push_all",
940926
reason = "likely to be replaced by a more optimized extend",

src/libcore/iter.rs

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,21 +1893,7 @@ pub trait Iterator {
18931893
.map(|(_, x)| x)
18941894
}
18951895

1896-
/// Returns the element that gives the maximum value from the
1897-
/// specified function.
1898-
///
1899-
/// Returns the rightmost element if the comparison determines two elements
1900-
/// to be equally maximum.
1901-
///
1902-
/// # Examples
1903-
///
1904-
/// ```
1905-
/// #![feature(iter_cmp)]
1906-
/// #![allow(deprecated)]
1907-
///
1908-
/// let a = [-3_i32, 0, 1, 5, -10];
1909-
/// assert_eq!(*a.iter().max_by(|x| x.abs()).unwrap(), -10);
1910-
/// ```
1896+
#[allow(missing_docs)]
19111897
#[inline]
19121898
#[unstable(feature = "iter_cmp",
19131899
reason = "may want to produce an Ordering directly; see #15311",
@@ -1945,22 +1931,8 @@ pub trait Iterator {
19451931
.map(|(_, x)| x)
19461932
}
19471933

1948-
/// Returns the element that gives the minimum value from the
1949-
/// specified function.
1950-
///
1951-
/// Returns the latest element if the comparison determines two elements
1952-
/// to be equally minimum.
1953-
///
1954-
/// # Examples
1955-
///
1956-
/// ```
1957-
/// #![feature(iter_cmp)]
1958-
/// #![allow(deprecated)]
1959-
///
1960-
/// let a = [-3_i32, 0, 1, 5, -10];
1961-
/// assert_eq!(*a.iter().min_by(|x| x.abs()).unwrap(), 0);
1962-
/// ```
19631934
#[inline]
1935+
#[allow(missing_docs)]
19641936
#[unstable(feature = "iter_cmp",
19651937
reason = "may want to produce an Ordering directly; see #15311",
19661938
issue = "27724")]

src/librustc/diagnostics.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,7 +1948,7 @@ fn main() {
19481948
19491949
You cannot directly use a dereference operation whilst initializing a constant
19501950
or a static. To fix this error, restructure your code to avoid this dereference,
1951-
perharps moving it inline:
1951+
perhaps moving it inline:
19521952
19531953
```
19541954
use std::ops::Deref;
@@ -1967,6 +1967,23 @@ fn main() {
19671967
```
19681968
"##,
19691969

1970+
E0452: r##"
1971+
An invalid lint attribute has been given. Erroneous code example:
1972+
1973+
```
1974+
#![allow(foo = "")] // error: malformed lint attribute
1975+
```
1976+
1977+
Lint attributes only accept a list of identifiers (where each identifier is a
1978+
lint name). Ensure the attribute is of this form:
1979+
1980+
```
1981+
#![allow(foo)] // ok!
1982+
// or:
1983+
#![allow(foo, foo2)] // ok!
1984+
```
1985+
"##,
1986+
19701987
E0492: r##"
19711988
A borrow of a constant containing interior mutability was attempted. Erroneous
19721989
code example:
@@ -2242,7 +2259,6 @@ register_diagnostics! {
22422259
E0314, // closure outlives stack frame
22432260
E0315, // cannot invoke closure outside of its lifetime
22442261
E0316, // nested quantification of lifetimes
2245-
E0452, // malformed lint attribute
22462262
E0453, // overruled by outer forbid
22472263
E0471, // constant evaluation error: ..
22482264
E0472, // asm! is unsupported on this target

src/libstd/io/error.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,7 @@ pub enum ErrorKind {
150150
#[stable(feature = "rust1", since = "1.0.0")]
151151
Other,
152152

153-
/// An error returned when an operation could not be completed because an
154-
/// "end of file" was reached prematurely.
155-
///
156-
/// This typically means that an operation could only succeed if it read a
157-
/// particular number of bytes but only a smaller number of bytes could be
158-
/// read.
153+
#[allow(missing_docs)]
159154
#[unstable(feature = "read_exact_old", reason = "recently added",
160155
issue = "0")]
161156
#[rustc_deprecated(since = "1.6.0", reason = "renamed to UnexpectedEof")]

src/libstd/io/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ pub trait Read {
576576
/// will continue.
577577
///
578578
/// If this function encounters an "end of file" before completely filling
579-
/// the buffer, it returns an error of the kind `ErrorKind::UnexpectedEOF`.
579+
/// the buffer, it returns an error of the kind `ErrorKind::UnexpectedEof`.
580580
/// The contents of `buf` are unspecified in this case.
581581
///
582582
/// If any other read error is encountered then this function immediately
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// error-pattern:thread '<main>' panicked at 'shift operation overflowed'
12+
// compile-flags: -C debug-assertions
13+
14+
#![warn(exceeding_bitshifts)]
15+
16+
fn main() {
17+
let _n = 1i64 >> [64][0];
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// error-pattern:thread '<main>' panicked at 'shift operation overflowed'
12+
// compile-flags: -C debug-assertions
13+
14+
#![warn(exceeding_bitshifts)]
15+
#![feature(const_indexing)]
16+
17+
fn main() {
18+
let _n = 1i64 >> [64][0];
19+
}

0 commit comments

Comments
 (0)