diff --git a/src/doc/book/no-stdlib.md b/src/doc/book/no-stdlib.md index 43bd0507ebbb6..9823a0b6d6355 100644 --- a/src/doc/book/no-stdlib.md +++ b/src/doc/book/no-stdlib.md @@ -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 diff --git a/src/doc/book/primitive-types.md b/src/doc/book/primitive-types.md index 2a4b7ba37f25b..b6a123bb3674c 100644 --- a/src/doc/book/primitive-types.md +++ b/src/doc/book/primitive-types.md @@ -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 diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 45aec9558feaf..40b9b0e01ab9b 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -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); ``` This will not: ``` -#![feature(simd)] +#![feature(repr_simd)] -#[simd] +#[repr(simd)] struct Good(u32, u32, u32); ``` "##, @@ -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); ``` "##, @@ -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); ``` "##, @@ -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 Foo { +// error: the type parameter `T` is not constrained by the impl trait, self +// type, or predicates [E0207] + fn get(&self) -> T { + ::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 MyTrait for Foo { - fn get(&self) -> usize { - 0 +// Move the type parameter from the impl to the method +impl Foo { + fn get(&self) -> T { + ::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 { + foo: T +} + +struct FooMaker; +impl Maker for FooMaker { +// error: the type parameter `T` is not constrained by the impl trait, self +// type, or predicates [E0207] + type Item = Foo; + + fn make(&mut self) -> Foo { + Foo { foo: ::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 { + foo: T +} -impl MyTrait for Foo { - fn get(&self) -> usize { - 0 +// Add a type parameter to `FooMaker` +struct FooMaker { + phantom: PhantomData, +} + +impl Maker for FooMaker { + type Item = Foo; + + fn make(&mut self) -> Foo { + Foo { + foo: ::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 { + fn make(&mut self) -> Item; +} + +struct Foo { + foo: T +} + +struct FooMaker; + +impl Maker> for FooMaker { + fn make(&mut self) -> Foo { + Foo { foo: ::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##" diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 0ec5cab78bc7b..14661dbaec4c5 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -125,6 +125,7 @@ break; case "+": + ev.preventDefault(); toggleAllDocs(); break; diff --git a/src/test/compile-fail/E0062.rs b/src/test/compile-fail/E0062.rs new file mode 100644 index 0000000000000..86ec7db14b5c1 --- /dev/null +++ b/src/test/compile-fail/E0062.rs @@ -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 or the MIT license +// , 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 + }; +} diff --git a/src/test/compile-fail/E0063.rs b/src/test/compile-fail/E0063.rs new file mode 100644 index 0000000000000..c94f807d807ca --- /dev/null +++ b/src/test/compile-fail/E0063.rs @@ -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 or the MIT license +// , 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 +} diff --git a/src/test/compile-fail/E0067.rs b/src/test/compile-fail/E0067.rs new file mode 100644 index 0000000000000..a3fc30ee1c71a --- /dev/null +++ b/src/test/compile-fail/E0067.rs @@ -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 or the MIT license +// , 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 +} diff --git a/src/test/compile-fail/E0069.rs b/src/test/compile-fail/E0069.rs new file mode 100644 index 0000000000000..d164d86348784 --- /dev/null +++ b/src/test/compile-fail/E0069.rs @@ -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 or the MIT license +// , 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() { +} diff --git a/src/test/compile-fail/E0070.rs b/src/test/compile-fail/E0070.rs new file mode 100644 index 0000000000000..ba66bd03aef9d --- /dev/null +++ b/src/test/compile-fail/E0070.rs @@ -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 or the MIT license +// , 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() { +} diff --git a/src/test/compile-fail/E0071.rs b/src/test/compile-fail/E0071.rs new file mode 100644 index 0000000000000..658c8fb155114 --- /dev/null +++ b/src/test/compile-fail/E0071.rs @@ -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 or the MIT license +// , 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 +} diff --git a/src/test/compile-fail/E0072.rs b/src/test/compile-fail/E0072.rs new file mode 100644 index 0000000000000..2f96ba1046d74 --- /dev/null +++ b/src/test/compile-fail/E0072.rs @@ -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 or the MIT license +// , 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, +} + +fn main() { +} diff --git a/src/test/compile-fail/E0075.rs b/src/test/compile-fail/E0075.rs new file mode 100644 index 0000000000000..d7783904e2e98 --- /dev/null +++ b/src/test/compile-fail/E0075.rs @@ -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 or the MIT license +// , 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() { +} diff --git a/src/test/compile-fail/E0076.rs b/src/test/compile-fail/E0076.rs new file mode 100644 index 0000000000000..b0f02a03e0051 --- /dev/null +++ b/src/test/compile-fail/E0076.rs @@ -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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(repr_simd)] + +#[repr(simd)] +struct Bad(u16, u32, u32); //~ ERROR E0076 + +fn main() { +} diff --git a/src/test/compile-fail/E0077.rs b/src/test/compile-fail/E0077.rs new file mode 100644 index 0000000000000..b074e90b2c01f --- /dev/null +++ b/src/test/compile-fail/E0077.rs @@ -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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(repr_simd)] + +#[repr(simd)] +struct Bad(String); //~ ERROR E0077 + +fn main() { +} diff --git a/src/test/compile-fail/E0079.rs b/src/test/compile-fail/E0079.rs new file mode 100644 index 0000000000000..23957c72ff00e --- /dev/null +++ b/src/test/compile-fail/E0079.rs @@ -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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +enum Foo { + Q = "32" //~ ERROR E0079 +} + +fn main() { +} diff --git a/src/test/compile-fail/E0080.rs b/src/test/compile-fail/E0080.rs new file mode 100644 index 0000000000000..0329209d44bc7 --- /dev/null +++ b/src/test/compile-fail/E0080.rs @@ -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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +enum Enum { + X = (1 << 500), //~ ERROR E0080 + Y = (1 / 0) //~ ERROR E0080 +} + +fn main() { +} diff --git a/src/test/compile-fail/E0081.rs b/src/test/compile-fail/E0081.rs new file mode 100644 index 0000000000000..b63265564b334 --- /dev/null +++ b/src/test/compile-fail/E0081.rs @@ -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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +enum Enum { + P = 3, + X = 3, //~ ERROR E0081 + Y = 5 +} + +fn main() { +}