Skip to content

Rollup of 7 pull requests #33833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
May 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/doc/book/no-stdlib.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ which do not trigger a panic can be assured that this function is never
called. The second function, `panic_fmt`, is also used by the failure
mechanisms of the compiler.

[unwind]: https://github.com/rust-lang/rust/blob/master/src/libstd/sys/common/unwind/gcc.rs
[unwind]: https://github.com/rust-lang/rust/blob/master/src/libpanic_unwind/gcc.rs
2 changes: 0 additions & 2 deletions src/doc/book/primitive-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ You can use a combo of `&` and `[]` to create a slice from various things. The
detail later in this section. The `[]`s, with a range, let you define the
length of the slice:

[references]: references-and-borrowing.html

```rust
let a = [0, 1, 2, 3, 4];
let complete = &a[..]; // A slice containing all of the elements in a
Expand Down
150 changes: 123 additions & 27 deletions src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -978,18 +978,18 @@ are generic.
This will cause an error:

```compile_fail
#![feature(simd)]
#![feature(repr_simd)]

#[simd]
#[repr(simd)]
struct Bad<T>(T, T, T);
```

This will not:

```
#![feature(simd)]
#![feature(repr_simd)]

#[simd]
#[repr(simd)]
struct Good(u32, u32, u32);
```
"##,
Expand Down Expand Up @@ -1026,18 +1026,18 @@ will trigger this error.
This will cause an error:

```compile_fail
#![feature(simd)]
#![feature(repr_simd)]

#[simd]
#[repr(simd)]
struct Bad(u16, u32, u32);
```

This will not:

```
#![feature(simd)]
#![feature(repr_simd)]

#[simd]
#[repr(simd)]
struct Good(u32, u32, u32);
```
"##,
Expand All @@ -1049,18 +1049,18 @@ must be machine types so SIMD operations can be applied to them.
This will cause an error:

```compile_fail
#![feature(simd)]
#![feature(repr_simd)]

#[simd]
#[repr(simd)]
struct Bad(String);
```

This will not:

```
#![feature(simd)]
#![feature(repr_simd)]

#[simd]
#[repr(simd)]
struct Good(u32, u32, u32);
```
"##,
Expand Down Expand Up @@ -2387,39 +2387,135 @@ impl Copy for &'static Bar { } // error
"##,

E0207: r##"
You declared an unused type parameter when implementing a trait on an object.
Erroneous code example:
Any type parameter or lifetime parameter of an `impl` must meet at least one of
the following criteria:

- it appears in the self type of the impl
- for a trait impl, it appears in the trait reference
- it is bound as an associated type

### Error example 1

Suppose we have a struct `Foo` and we would like to define some methods for it.
The following definition leads to a compiler error:

```compile_fail
trait MyTrait {
fn get(&self) -> usize;
struct Foo;

impl<T: Default> Foo {
// error: the type parameter `T` is not constrained by the impl trait, self
// type, or predicates [E0207]
fn get(&self) -> T {
<T as Default>::default()
}
}
```

The problem is that the parameter `T` does not appear in the self type (`Foo`)
of the impl. In this case, we can fix the error by moving the type parameter
from the `impl` to the method `get`:


```
struct Foo;

impl<T> MyTrait for Foo {
fn get(&self) -> usize {
0
// Move the type parameter from the impl to the method
impl Foo {
fn get<T: Default>(&self) -> T {
<T as Default>::default()
}
}
```

Please check your object definition and remove unused type
parameter(s). Example:
### Error example 2

As another example, suppose we have a `Maker` trait and want to establish a
type `FooMaker` that makes `Foo`s:

```compile_fail
trait Maker {
type Item;
fn make(&mut self) -> Self::Item;
}

struct Foo<T> {
foo: T
}

struct FooMaker;

impl<T: Default> Maker for FooMaker {
// error: the type parameter `T` is not constrained by the impl trait, self
// type, or predicates [E0207]
type Item = Foo<T>;

fn make(&mut self) -> Foo<T> {
Foo { foo: <T as Default>::default() }
}
}
```
trait MyTrait {
fn get(&self) -> usize;

This fails to compile because `T` does not appear in the trait or in the
implementing type.

One way to work around this is to introduce a phantom type parameter into
`FooMaker`, like so:

```
use std::marker::PhantomData;

trait Maker {
type Item;
fn make(&mut self) -> Self::Item;
}

struct Foo;
struct Foo<T> {
foo: T
}

impl MyTrait for Foo {
fn get(&self) -> usize {
0
// Add a type parameter to `FooMaker`
struct FooMaker<T> {
phantom: PhantomData<T>,
}

impl<T: Default> Maker for FooMaker<T> {
type Item = Foo<T>;

fn make(&mut self) -> Foo<T> {
Foo {
foo: <T as Default>::default(),
}
}
}
```

Another way is to do away with the associated type in `Maker` and use an input
type parameter instead:

```
// Use a type parameter instead of an associated type here
trait Maker<Item> {
fn make(&mut self) -> Item;
}

struct Foo<T> {
foo: T
}

struct FooMaker;

impl<T: Default> Maker<Foo<T>> for FooMaker {
fn make(&mut self) -> Foo<T> {
Foo { foo: <T as Default>::default() }
}
}
```

### Additional information

For more information, please see [RFC 447].

[RFC 447]: https://github.com/rust-lang/rfcs/blob/master/text/0447-no-unused-impl-parameters.md
"##,

E0210: r##"
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
break;

case "+":
ev.preventDefault();
toggleAllDocs();
break;

Expand Down
20 changes: 20 additions & 0 deletions src/test/compile-fail/E0062.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2016 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.

struct Foo {
x: i32
}

fn main() {
let x = Foo {
x: 0,
x: 0, //~ ERROR E0062
};
}
18 changes: 18 additions & 0 deletions src/test/compile-fail/E0063.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2016 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.

struct Foo {
x: i32,
y: i32
}

fn main() {
let x = Foo { x: 0 }; //~ ERROR E0063
}
16 changes: 16 additions & 0 deletions src/test/compile-fail/E0067.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2016 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.

use std::collections::LinkedList;

fn main() {
LinkedList::new() += 1; //~ ERROR E0368
//~^ ERROR E0067
}
16 changes: 16 additions & 0 deletions src/test/compile-fail/E0069.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2016 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.

fn foo() -> u8 {
return; //~ ERROR E0069
}

fn main() {
}
23 changes: 23 additions & 0 deletions src/test/compile-fail/E0070.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2016 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.

const SOME_CONST : i32 = 12;

fn some_other_func() {}

fn some_function() {
SOME_CONST = 14; //~ ERROR E0070
1 = 3; //~ ERROR E0070
some_other_func() = 4; //~ ERROR E0070
//~^ ERROR E0308
}

fn main() {
}
16 changes: 16 additions & 0 deletions src/test/compile-fail/E0071.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2016 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.

enum Foo { FirstValue(i32) }

fn main() {
let u = Foo::FirstValue { value: 0 }; //~ ERROR E0071
let t = u32 { value: 4 }; //~ ERROR E0071
}
17 changes: 17 additions & 0 deletions src/test/compile-fail/E0072.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2016 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.

struct ListNode { //~ ERROR E0072
head: u8,
tail: Option<ListNode>,
}

fn main() {
}
17 changes: 17 additions & 0 deletions src/test/compile-fail/E0075.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2016 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.

#![feature(repr_simd)]

#[repr(simd)]
struct Bad; //~ ERROR E0075

fn main() {
}
Loading