Skip to content

Commit 8393d99

Browse files
committed
Auto merge of #33833 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 7 pull requests - Successful merges: #33692, #33759, #33779, #33781, #33797, #33810, #33832 - Failed merges:
2 parents dd6e8d4 + 4613835 commit 8393d99

File tree

17 files changed

+353
-30
lines changed

17 files changed

+353
-30
lines changed

src/doc/book/no-stdlib.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,4 @@ which do not trigger a panic can be assured that this function is never
8484
called. The second function, `panic_fmt`, is also used by the failure
8585
mechanisms of the compiler.
8686

87-
[unwind]: https://github.com/rust-lang/rust/blob/master/src/libstd/sys/common/unwind/gcc.rs
87+
[unwind]: https://github.com/rust-lang/rust/blob/master/src/libpanic_unwind/gcc.rs

src/doc/book/primitive-types.md

-2
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ You can use a combo of `&` and `[]` to create a slice from various things. The
175175
detail later in this section. The `[]`s, with a range, let you define the
176176
length of the slice:
177177

178-
[references]: references-and-borrowing.html
179-
180178
```rust
181179
let a = [0, 1, 2, 3, 4];
182180
let complete = &a[..]; // A slice containing all of the elements in a

src/librustc_typeck/diagnostics.rs

+123-27
Original file line numberDiff line numberDiff line change
@@ -978,18 +978,18 @@ are generic.
978978
This will cause an error:
979979
980980
```compile_fail
981-
#![feature(simd)]
981+
#![feature(repr_simd)]
982982
983-
#[simd]
983+
#[repr(simd)]
984984
struct Bad<T>(T, T, T);
985985
```
986986
987987
This will not:
988988
989989
```
990-
#![feature(simd)]
990+
#![feature(repr_simd)]
991991
992-
#[simd]
992+
#[repr(simd)]
993993
struct Good(u32, u32, u32);
994994
```
995995
"##,
@@ -1026,18 +1026,18 @@ will trigger this error.
10261026
This will cause an error:
10271027
10281028
```compile_fail
1029-
#![feature(simd)]
1029+
#![feature(repr_simd)]
10301030
1031-
#[simd]
1031+
#[repr(simd)]
10321032
struct Bad(u16, u32, u32);
10331033
```
10341034
10351035
This will not:
10361036
10371037
```
1038-
#![feature(simd)]
1038+
#![feature(repr_simd)]
10391039
1040-
#[simd]
1040+
#[repr(simd)]
10411041
struct Good(u32, u32, u32);
10421042
```
10431043
"##,
@@ -1049,18 +1049,18 @@ must be machine types so SIMD operations can be applied to them.
10491049
This will cause an error:
10501050
10511051
```compile_fail
1052-
#![feature(simd)]
1052+
#![feature(repr_simd)]
10531053
1054-
#[simd]
1054+
#[repr(simd)]
10551055
struct Bad(String);
10561056
```
10571057
10581058
This will not:
10591059
10601060
```
1061-
#![feature(simd)]
1061+
#![feature(repr_simd)]
10621062
1063-
#[simd]
1063+
#[repr(simd)]
10641064
struct Good(u32, u32, u32);
10651065
```
10661066
"##,
@@ -2387,39 +2387,135 @@ impl Copy for &'static Bar { } // error
23872387
"##,
23882388

23892389
E0207: r##"
2390-
You declared an unused type parameter when implementing a trait on an object.
2391-
Erroneous code example:
2390+
Any type parameter or lifetime parameter of an `impl` must meet at least one of
2391+
the following criteria:
2392+
2393+
- it appears in the self type of the impl
2394+
- for a trait impl, it appears in the trait reference
2395+
- it is bound as an associated type
2396+
2397+
### Error example 1
2398+
2399+
Suppose we have a struct `Foo` and we would like to define some methods for it.
2400+
The following definition leads to a compiler error:
23922401
23932402
```compile_fail
2394-
trait MyTrait {
2395-
fn get(&self) -> usize;
2403+
struct Foo;
2404+
2405+
impl<T: Default> Foo {
2406+
// error: the type parameter `T` is not constrained by the impl trait, self
2407+
// type, or predicates [E0207]
2408+
fn get(&self) -> T {
2409+
<T as Default>::default()
2410+
}
23962411
}
2412+
```
2413+
2414+
The problem is that the parameter `T` does not appear in the self type (`Foo`)
2415+
of the impl. In this case, we can fix the error by moving the type parameter
2416+
from the `impl` to the method `get`:
23972417
2418+
2419+
```
23982420
struct Foo;
23992421
2400-
impl<T> MyTrait for Foo {
2401-
fn get(&self) -> usize {
2402-
0
2422+
// Move the type parameter from the impl to the method
2423+
impl Foo {
2424+
fn get<T: Default>(&self) -> T {
2425+
<T as Default>::default()
24032426
}
24042427
}
24052428
```
24062429
2407-
Please check your object definition and remove unused type
2408-
parameter(s). Example:
2430+
### Error example 2
2431+
2432+
As another example, suppose we have a `Maker` trait and want to establish a
2433+
type `FooMaker` that makes `Foo`s:
2434+
2435+
```compile_fail
2436+
trait Maker {
2437+
type Item;
2438+
fn make(&mut self) -> Self::Item;
2439+
}
2440+
2441+
struct Foo<T> {
2442+
foo: T
2443+
}
2444+
2445+
struct FooMaker;
24092446
2447+
impl<T: Default> Maker for FooMaker {
2448+
// error: the type parameter `T` is not constrained by the impl trait, self
2449+
// type, or predicates [E0207]
2450+
type Item = Foo<T>;
2451+
2452+
fn make(&mut self) -> Foo<T> {
2453+
Foo { foo: <T as Default>::default() }
2454+
}
2455+
}
24102456
```
2411-
trait MyTrait {
2412-
fn get(&self) -> usize;
2457+
2458+
This fails to compile because `T` does not appear in the trait or in the
2459+
implementing type.
2460+
2461+
One way to work around this is to introduce a phantom type parameter into
2462+
`FooMaker`, like so:
2463+
2464+
```
2465+
use std::marker::PhantomData;
2466+
2467+
trait Maker {
2468+
type Item;
2469+
fn make(&mut self) -> Self::Item;
24132470
}
24142471
2415-
struct Foo;
2472+
struct Foo<T> {
2473+
foo: T
2474+
}
24162475
2417-
impl MyTrait for Foo {
2418-
fn get(&self) -> usize {
2419-
0
2476+
// Add a type parameter to `FooMaker`
2477+
struct FooMaker<T> {
2478+
phantom: PhantomData<T>,
2479+
}
2480+
2481+
impl<T: Default> Maker for FooMaker<T> {
2482+
type Item = Foo<T>;
2483+
2484+
fn make(&mut self) -> Foo<T> {
2485+
Foo {
2486+
foo: <T as Default>::default(),
2487+
}
24202488
}
24212489
}
24222490
```
2491+
2492+
Another way is to do away with the associated type in `Maker` and use an input
2493+
type parameter instead:
2494+
2495+
```
2496+
// Use a type parameter instead of an associated type here
2497+
trait Maker<Item> {
2498+
fn make(&mut self) -> Item;
2499+
}
2500+
2501+
struct Foo<T> {
2502+
foo: T
2503+
}
2504+
2505+
struct FooMaker;
2506+
2507+
impl<T: Default> Maker<Foo<T>> for FooMaker {
2508+
fn make(&mut self) -> Foo<T> {
2509+
Foo { foo: <T as Default>::default() }
2510+
}
2511+
}
2512+
```
2513+
2514+
### Additional information
2515+
2516+
For more information, please see [RFC 447].
2517+
2518+
[RFC 447]: https://github.com/rust-lang/rfcs/blob/master/text/0447-no-unused-impl-parameters.md
24232519
"##,
24242520

24252521
E0210: r##"

src/librustdoc/html/static/main.js

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
break;
126126

127127
case "+":
128+
ev.preventDefault();
128129
toggleAllDocs();
129130
break;
130131

src/test/compile-fail/E0062.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2016 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+
struct Foo {
12+
x: i32
13+
}
14+
15+
fn main() {
16+
let x = Foo {
17+
x: 0,
18+
x: 0, //~ ERROR E0062
19+
};
20+
}

src/test/compile-fail/E0063.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 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+
struct Foo {
12+
x: i32,
13+
y: i32
14+
}
15+
16+
fn main() {
17+
let x = Foo { x: 0 }; //~ ERROR E0063
18+
}

src/test/compile-fail/E0067.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2016 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+
use std::collections::LinkedList;
12+
13+
fn main() {
14+
LinkedList::new() += 1; //~ ERROR E0368
15+
//~^ ERROR E0067
16+
}

src/test/compile-fail/E0069.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2016 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+
fn foo() -> u8 {
12+
return; //~ ERROR E0069
13+
}
14+
15+
fn main() {
16+
}

src/test/compile-fail/E0070.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2016 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+
const SOME_CONST : i32 = 12;
12+
13+
fn some_other_func() {}
14+
15+
fn some_function() {
16+
SOME_CONST = 14; //~ ERROR E0070
17+
1 = 3; //~ ERROR E0070
18+
some_other_func() = 4; //~ ERROR E0070
19+
//~^ ERROR E0308
20+
}
21+
22+
fn main() {
23+
}

src/test/compile-fail/E0071.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2016 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+
enum Foo { FirstValue(i32) }
12+
13+
fn main() {
14+
let u = Foo::FirstValue { value: 0 }; //~ ERROR E0071
15+
let t = u32 { value: 4 }; //~ ERROR E0071
16+
}

src/test/compile-fail/E0072.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2016 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+
struct ListNode { //~ ERROR E0072
12+
head: u8,
13+
tail: Option<ListNode>,
14+
}
15+
16+
fn main() {
17+
}

src/test/compile-fail/E0075.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2016 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+
#![feature(repr_simd)]
12+
13+
#[repr(simd)]
14+
struct Bad; //~ ERROR E0075
15+
16+
fn main() {
17+
}

0 commit comments

Comments
 (0)