From 1cf6a8203826cf176eaf093b722b4f5d123f79da Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Wed, 17 Jun 2015 22:13:37 +0200 Subject: [PATCH 01/17] README: make it clear rustc is the compiler --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e54473a8b4172..f54c22110b301 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Rust is a systems programming language that is fast, memory safe and multithreaded, but does not employ a garbage collector or otherwise impose significant runtime overhead. -This repo contains the code for `rustc`, the Rust compiler, as well +This repo contains the code for the compiler (`rustc`), as well as standard libraries, tools and documentation for Rust. ## Quick Start From 0adda45c04f1c4a950e1e676ae590758c7b827df Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Mon, 22 Jun 2015 19:26:51 +0200 Subject: [PATCH 02/17] book: fix sentence --- src/doc/trpl/documentation.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/doc/trpl/documentation.md b/src/doc/trpl/documentation.md index 53754e2688dd6..746558b3b9448 100644 --- a/src/doc/trpl/documentation.md +++ b/src/doc/trpl/documentation.md @@ -33,8 +33,10 @@ pub fn new(value: T) -> Rc { ``` This code generates documentation that looks [like this][rc-new]. I've left the -implementation out, with a regular comment in its place. That's the first thing -to notice about this annotation: it uses `///`, instead of `//`. The triple slash +implementation out, with a regular comment in its place. + +The first thing to notice about this annotation is that it uses +`///` instead of `//`. The triple slash indicates a documentation comment. Documentation comments are written in Markdown. From e13077f7f089664a847f9fa1f081f0ff8f413726 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Mon, 22 Jun 2015 19:27:31 +0200 Subject: [PATCH 03/17] book: whitespace --- src/doc/trpl/documentation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/documentation.md b/src/doc/trpl/documentation.md index 746558b3b9448..7d9d6aa39f85d 100644 --- a/src/doc/trpl/documentation.md +++ b/src/doc/trpl/documentation.md @@ -382,7 +382,7 @@ $ rustdoc --test path/to/my/crate/root.rs $ cargo test ``` -That's right, `cargo test` tests embedded documentation too. However, +That's right, `cargo test` tests embedded documentation too. However, `cargo test` will not test binary crates, only library ones. This is due to the way `rustdoc` works: it links against the library to be tested, but with a binary, there’s nothing to link to. From 35abf86a1b6ac40d6a8478b9a7bc9da1ebf7b96f Mon Sep 17 00:00:00 2001 From: Adam Heins Date: Thu, 25 Jun 2015 19:29:23 -0400 Subject: [PATCH 04/17] Improve sentence flow. --- src/doc/trpl/link-args.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/link-args.md b/src/doc/trpl/link-args.md index ee5159afb8e6f..cdaef6cd9b510 100644 --- a/src/doc/trpl/link-args.md +++ b/src/doc/trpl/link-args.md @@ -17,7 +17,7 @@ Note that this feature is currently hidden behind the `feature(link_args)` gate because this is not a sanctioned way of performing linking. Right now rustc shells out to the system linker, so it makes sense to provide extra command line arguments, but this will not always be the case. In the future rustc may use -LLVM directly to link native libraries in which case `link_args` will have no +LLVM directly to link native libraries, in which case `link_args` will have no meaning. It is highly recommended to *not* use this attribute, and rather use the more From 7d0198d5d2cc13d5030e42ccd1109adebea25b34 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Sat, 27 Jun 2015 15:45:48 +0200 Subject: [PATCH 05/17] test: fix some indents --- src/test/compile-fail/no-send-res-ports.rs | 2 +- src/test/run-pass/issue-2718.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/compile-fail/no-send-res-ports.rs b/src/test/compile-fail/no-send-res-ports.rs index b80d15bb6f3c6..60b2d22079e2c 100644 --- a/src/test/compile-fail/no-send-res-ports.rs +++ b/src/test/compile-fail/no-send-res-ports.rs @@ -20,7 +20,7 @@ fn main() { _x: Port<()>, } - impl Drop for foo { + impl Drop for foo { fn drop(&mut self) {} } diff --git a/src/test/run-pass/issue-2718.rs b/src/test/run-pass/issue-2718.rs index 1a139bdf0fb27..2da2f1e82a693 100644 --- a/src/test/run-pass/issue-2718.rs +++ b/src/test/run-pass/issue-2718.rs @@ -165,7 +165,7 @@ pub mod pipes { p: Option<*const packet>, } - impl Drop for send_packet { + impl Drop for send_packet { fn drop(&mut self) { unsafe { if self.p != None { @@ -194,7 +194,7 @@ pub mod pipes { p: Option<*const packet>, } - impl Drop for recv_packet { + impl Drop for recv_packet { fn drop(&mut self) { unsafe { if self.p != None { From 516941b74f61f058625fab936ad0fd2c97943e22 Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Tue, 30 Jun 2015 14:10:24 +0200 Subject: [PATCH 06/17] fmt: Update docs and mention :#? pretty-printing --- src/libcollections/fmt.rs | 45 ++++++++++++++++++++------------------- src/libcore/fmt/mod.rs | 5 ++++- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/libcollections/fmt.rs b/src/libcollections/fmt.rs index 72d0ca85357a4..7df259e9b36a8 100644 --- a/src/libcollections/fmt.rs +++ b/src/libcollections/fmt.rs @@ -128,15 +128,15 @@ //! This allows multiple actual types to be formatted via `{:x}` (like `i8` as //! well as `isize`). The current mapping of types to traits is: //! -//! * *nothing* ⇒ `Display` -//! * `?` ⇒ `Debug` -//! * `o` ⇒ `Octal` -//! * `x` ⇒ `LowerHex` -//! * `X` ⇒ `UpperHex` -//! * `p` ⇒ `Pointer` -//! * `b` ⇒ `Binary` -//! * `e` ⇒ `LowerExp` -//! * `E` ⇒ `UpperExp` +//! * *nothing* ⇒ [`Display`](trait.Display.html) +//! * `?` ⇒ [`Debug`](trait.Debug.html) +//! * `o` ⇒ [`Octal`](trait.Octal.html) +//! * `x` ⇒ [`LowerHex`](trait.LowerHex.html) +//! * `X` ⇒ [`UpperHex`](trait.UpperHex.html) +//! * `p` ⇒ [`Pointer`](trait.Pointer.html) +//! * `b` ⇒ [`Binary`](trait.Binary.html) +//! * `e` ⇒ [`LowerExp`](trait.LowerExp.html) +//! * `E` ⇒ [`UpperExp`](trait.UpperExp.html) //! //! What this means is that any type of argument which implements the //! `fmt::Binary` trait can then be formatted with `{:b}`. Implementations @@ -367,11 +367,11 @@ //! should always be printed. //! * '-' - Currently not used //! * '#' - This flag is indicates that the "alternate" form of printing should -//! be used. For array slices, the alternate form omits the brackets. -//! For the integer formatting traits, the alternate forms are: +//! be used. The alternate forms are: +//! * `#?` - pretty-print the `Debug` formatting //! * `#x` - precedes the argument with a "0x" //! * `#X` - precedes the argument with a "0x" -//! * `#t` - precedes the argument with a "0b" +//! * `#b` - precedes the argument with a "0b" //! * `#o` - precedes the argument with a "0o" //! * '0' - This is used to indicate for integer formats that the padding should //! both be done with a `0` character as well as be sign-aware. A format @@ -408,19 +408,20 @@ //! //! There are three possible ways to specify the desired `precision`: //! -//! There are three possible ways to specify the desired `precision`: -//! 1. An integer `.N`, -//! 2. an integer followed by dollar sign `.N$`, or -//! 3. an asterisk `.*`. +//! 1. An integer `.N`: +//! +//! the integer `N` itself is the precision. +//! +//! 2. An integer followed by dollar sign `.N$`: //! -//! The first specification, `.N`, means the integer `N` itself is the precision. +//! use format *argument* `N` (which must be a `usize`) as the precision. //! -//! The second, `.N$`, means use format *argument* `N` (which must be a `usize`) as the precision. +//! 3. An asterisk `.*`: //! -//! Finally, `.*` means that this `{...}` is associated with *two* format inputs rather than one: -//! the first input holds the `usize` precision, and the second holds the value to print. Note -//! that in this case, if one uses the format string `{:.*}`, then the `` part -//! refers to the *value* to print, and the `precision` must come in the input preceding ``. +//! `.*` means that this `{...}` is associated with *two* format inputs rather than one: the +//! first input holds the `usize` precision, and the second holds the value to print. Note that +//! in this case, if one uses the format string `{:.*}`, then the `` part refers +//! to the *value* to print, and the `precision` must come in the input preceding ``. //! //! For example, these: //! diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index cbbb186af7609..35dea6d15f0e9 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -267,7 +267,7 @@ impl<'a> Display for Arguments<'a> { } } -/// Format trait for the `:?` format. Useful for debugging, all types +/// Format trait for the `?` character. Useful for debugging, all types /// should implement this. /// /// Generally speaking, you should just `derive` a `Debug` implementation. @@ -312,6 +312,9 @@ impl<'a> Display for Arguments<'a> { /// There are a number of `debug_*` methods on `Formatter` to help you with manual /// implementations, such as [`debug_struct`][debug_struct]. /// +/// `Debug` implementations using either `derive` or the debug builder API +/// on `Formatter` support pretty printing using the alternate flag: `{:#?}`. +/// /// [debug_struct]: ../std/fmt/struct.Formatter.html#method.debug_struct #[stable(feature = "rust1", since = "1.0.0")] #[rustc_on_unimplemented = "`{Self}` cannot be formatted using `:?`; if it is \ From c158be082f07c2b2ed0a5f1db33627709396ac63 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 29 Jun 2015 16:00:57 +0200 Subject: [PATCH 07/17] Add E0195 error explanation --- src/librustc_typeck/diagnostics.rs | 39 +++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index d4977c5d3941c..1e83c1b6900a4 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1250,6 +1250,44 @@ information see the [opt-in builtin traits RFC](https://github.com/rust-lang/ rfcs/blob/master/text/0019-opt-in-builtin-traits.md). "##, +E0195: r##" +Your method's lifetime parameters do not match the trait declaration. +Erroneous code example: + +``` +trait Trait { + fn t<'a,'b:'a>(x: &'a str, y: &'b str); +} + +struct Foo; + +impl Trait for Foo { + fn t<'a,'b>(x: &'a str, y: &'b str) { // error: lifetime parameters + // or bounds on method `t` + // do not match the trait + // declaration + } +} +``` + +The 'b lifetime constraints for `t` implementation does not match the +trait declaration. Ensure lifetime declarations match exactly in both trait +declaration and implementation. Example: + +``` +trait Trait { + fn t<'a,'b:'a>(x: &'a str, y: &'b str); +} + +struct Foo; + +impl Trait for Foo { + fn t<'a,'b:'a>(x: &'a str, y: &'b str) { // ok! + } +} +``` +"##, + E0197: r##" Inherent implementations (one that do not implement a trait but provide methods associated with a type) are always safe because they are not @@ -1686,7 +1724,6 @@ register_diagnostics! { E0193, // cannot bound type where clause bounds may only be attached to types // involving type parameters E0194, - E0195, // lifetime parameters or bounds on method do not match the trait declaration E0196, // cannot determine a type for this closure E0203, // type parameter has more than one relaxed default bound, // and only one is supported From 20f22b7f0e29068414933dd6d41c6a5785d3fd75 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 30 Jun 2015 10:35:46 +0200 Subject: [PATCH 08/17] Add E0093 error explanation --- src/librustc_typeck/diagnostics.rs | 37 +++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 1e83c1b6900a4..57fbd52f71f4e 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1022,6 +1022,42 @@ type Foo = Box; // ok! ``` "##, +E0093: r##" +You called an unknown intrinsic function. Erroneous code example: + +``` +#![feature(intrinsics)] + +extern "rust-intrinsic" { + fn foo(); +} + +fn main() { + unsafe { + foo(); + } +} +``` + +Please check you didn't make a mistake in the function's name. All intrinsic +functions are defined in librustc_trans/trans/intrinsic.rs and in +libcore/intrinsics.rs. Example: + +``` +#![feature(intrinsics)] + +extern "rust-intrinsic" { + fn atomic_fence(); +} + +fn main() { + unsafe { + atomic_fence(); + } +} +``` +"##, + E0106: r##" This error indicates that a lifetime is missing from a type. If it is an error inside a function signature, the problem may be with failing to adhere to the @@ -1688,7 +1724,6 @@ register_diagnostics! { E0086, E0090, E0092, - E0093, E0094, E0101, E0102, From ed6940fd384b1e42c3e3ad229e022af2e13b79c7 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 30 Jun 2015 10:44:20 +0200 Subject: [PATCH 09/17] Add E0094 error explanation --- src/librustc_typeck/diagnostics.rs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 57fbd52f71f4e..4d3d18cb16c02 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1029,7 +1029,7 @@ You called an unknown intrinsic function. Erroneous code example: #![feature(intrinsics)] extern "rust-intrinsic" { - fn foo(); + fn foo(); // error: unrecognized intrinsic function: `foo` } fn main() { @@ -1047,7 +1047,7 @@ libcore/intrinsics.rs. Example: #![feature(intrinsics)] extern "rust-intrinsic" { - fn atomic_fence(); + fn atomic_fence(); // ok! } fn main() { @@ -1058,6 +1058,31 @@ fn main() { ``` "##, +E0094: r##" +You gave an invalid number of type parameters to an intrinsic function. +Erroneous code example: + +``` +#![feature(intrinsics)] + +extern "rust-intrinsic" { + fn size_of() -> usize; // error: intrinsic has wrong number + // of type parameters +} +``` + +Please check you give the right number of lifetime parameters and/or the +function definition. Example: + +``` +#![feature(intrinsics)] + +extern "rust-intrinsic" { + fn size_of() -> usize; // ok! +} +``` +"##, + E0106: r##" This error indicates that a lifetime is missing from a type. If it is an error inside a function signature, the problem may be with failing to adhere to the @@ -1724,7 +1749,6 @@ register_diagnostics! { E0086, E0090, E0092, - E0094, E0101, E0102, E0103, From 0ba2db5fde29bfac76a69cff819cb8388be90392 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 30 Jun 2015 10:47:49 +0200 Subject: [PATCH 10/17] Add E0211 error explanation --- src/librustc_typeck/diagnostics.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 4d3d18cb16c02..e81acc497b1b4 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1528,6 +1528,29 @@ impl Copy for &'static Bar { } // error ``` "##, +E0211: r##" +You used an intrinsic function which doesn't correspond to its +definition. Erroneous code example: + +``` +#![feature(intrinsics)] + +extern "rust-intrinsic" { + fn size_of(); // error: intrinsic has wrong type +} +``` + +Please check the function definition. Example: + +``` +#![feature(intrinsics)] + +extern "rust-intrinsic" { + fn size_of() -> usize; +} +``` +"##, + E0243: r##" This error indicates that not enough type parameters were found in a type or trait. @@ -1790,7 +1813,6 @@ register_diagnostics! { E0208, E0209, // builtin traits can only be implemented on structs or enums E0210, // type parameter is not constrained by any local type - E0211, E0212, // cannot extract an associated type from a higher-ranked trait bound E0213, // associated types are not accepted in this context E0214, // parenthesized parameters may only be used with a trait From 758ea34146f4651cb78e2167de3c335007a8f26d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 30 Jun 2015 10:58:52 +0200 Subject: [PATCH 11/17] Add E0092 error explanation --- src/librustc_typeck/diagnostics.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index e81acc497b1b4..49f58d0d9e9de 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1022,6 +1022,32 @@ type Foo = Box; // ok! ``` "##, +E0092: r##" +You tried to call an undefined atomic operation function. +Erroneous code example: + +``` +#![feature(intrinsics)] + +extern "rust-intrinsic" { + fn atomic_foo(); // error: unrecognized atomic operation + // function +} +``` + +Please check you didn't make a mistake in the function's name. All intrinsic +functions are defined in librustc_trans/trans/intrinsic.rs and in +libcore/intrinsics.rs. Example: + +``` +#![feature(intrinsics)] + +extern "rust-intrinsic" { + fn atomic_fence(); // ok! +} +``` +"##, + E0093: r##" You called an unknown intrinsic function. Erroneous code example: @@ -1771,7 +1797,6 @@ register_diagnostics! { E0085, E0086, E0090, - E0092, E0101, E0102, E0103, From edf6132be88fa2a51176f84d5fbee45046880717 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 30 Jun 2015 11:19:16 +0200 Subject: [PATCH 12/17] Add E0101 error explanation --- src/librustc_typeck/diagnostics.rs | 51 ++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 49f58d0d9e9de..affa0768697da 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1023,7 +1023,7 @@ type Foo = Box; // ok! "##, E0092: r##" -You tried to call an undefined atomic operation function. +You tried to declare an undefined atomic operation function. Erroneous code example: ``` @@ -1037,7 +1037,7 @@ extern "rust-intrinsic" { Please check you didn't make a mistake in the function's name. All intrinsic functions are defined in librustc_trans/trans/intrinsic.rs and in -libcore/intrinsics.rs. Example: +libcore/intrinsics.rs in the Rust source code. Example: ``` #![feature(intrinsics)] @@ -1049,7 +1049,7 @@ extern "rust-intrinsic" { "##, E0093: r##" -You called an unknown intrinsic function. Erroneous code example: +You declared an unknown intrinsic function. Erroneous code example: ``` #![feature(intrinsics)] @@ -1067,7 +1067,7 @@ fn main() { Please check you didn't make a mistake in the function's name. All intrinsic functions are defined in librustc_trans/trans/intrinsic.rs and in -libcore/intrinsics.rs. Example: +libcore/intrinsics.rs in the Rust source code. Example: ``` #![feature(intrinsics)] @@ -1097,8 +1097,9 @@ extern "rust-intrinsic" { } ``` -Please check you give the right number of lifetime parameters and/or the -function definition. Example: +Please check that you provided the right number of lifetime parameters +and verify with the function declaration in the Rust source code. +Example: ``` #![feature(intrinsics)] @@ -1109,6 +1110,32 @@ extern "rust-intrinsic" { ``` "##, +E0101: r##" +You hit this error because the compiler the compiler lacks information +to determine a type for this expression. Erroneous code example: + +``` +fn main() { + let x = |_| {}; // error: cannot determine a type for this expression +} +``` + +You have two possibilities to solve this situation: + * Give an explicit definition of the expression + * Infer the expression + +Examples: + +``` +fn main() { + let x = |_ : u32| {}; // ok! + // or: + let x = |_| {}; + x(0u32); +} +``` +"##, + E0106: r##" This error indicates that a lifetime is missing from a type. If it is an error inside a function signature, the problem may be with failing to adhere to the @@ -1343,21 +1370,20 @@ Erroneous code example: ``` trait Trait { - fn t<'a,'b:'a>(x: &'a str, y: &'b str); + fn bar<'a,'b:'a>(x: &'a str, y: &'b str); } struct Foo; impl Trait for Foo { - fn t<'a,'b>(x: &'a str, y: &'b str) { // error: lifetime parameters - // or bounds on method `t` - // do not match the trait - // declaration + fn bar<'a,'b>(x: &'a str, y: &'b str) { + // error: lifetime parameters or bounds on method `bar` + // do not match the trait declaration } } ``` -The 'b lifetime constraints for `t` implementation does not match the +The `'b` lifetime constraint for bar() implementation does not match the trait declaration. Ensure lifetime declarations match exactly in both trait declaration and implementation. Example: @@ -1797,7 +1823,6 @@ register_diagnostics! { E0085, E0086, E0090, - E0101, E0102, E0103, E0104, From a481c4ecdc95bf9247f262334f288ff78001ff6c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 30 Jun 2015 11:57:47 +0200 Subject: [PATCH 13/17] Add E0117 error explanation --- src/librustc_typeck/diagnostics.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index affa0768697da..7cc13a1a07737 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1244,6 +1244,26 @@ impl Bytes { ... } // error, same as above ``` "##, +E0117: r##" +You tried to implement a trait on a type which isn't defined in your crate. +Erroneous code example: + +``` +impl Drop for u32 {} +``` + +The type on which you want to implement the trait has to be defined in +your crate. Example: + +``` +pub struct Foo; // you define your type in your crate + +impl Drop for Foo { // and you can implement the trait on it! + // code of trait implementation here +} +``` +"##, + E0121: r##" In order to be consistent with Rust's lack of global type inference, type placeholders are disallowed by design in item signatures. @@ -1826,7 +1846,6 @@ register_diagnostics! { E0102, E0103, E0104, - E0117, E0118, E0119, E0120, From 2881e83c96c6f35fdc6741bbb3f951507ef74ca5 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 30 Jun 2015 12:12:45 +0200 Subject: [PATCH 14/17] Add E0207 error explanation --- src/librustc_typeck/diagnostics.rs | 37 +++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 7cc13a1a07737..83e6ea74d83dc 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1600,6 +1600,42 @@ impl Copy for &'static Bar { } // error ``` "##, +E0207: r##" +You passed an unused type parameter when implementing a trait +on an object. Erroneous code example: + +``` +trait MyTrait { + fn get(&self) -> usize; +} + +struct Foo; + +impl MyTrait for Foo { + fn get(&self) -> usize { + 0 + } +} +``` + +Please check your object definition and remove unused type +parameter(s). Example: + +``` +trait MyTrait { + fn get(&self) -> usize; +} + +struct Foo; + +impl MyTrait for Foo { + fn get(&self) -> usize { + 0 + } +} +``` +"##, + E0211: r##" You used an intrinsic function which doesn't correspond to its definition. Erroneous code example: @@ -1878,7 +1914,6 @@ register_diagnostics! { E0196, // cannot determine a type for this closure E0203, // type parameter has more than one relaxed default bound, // and only one is supported - E0207, // type parameter is not constrained by the impl trait, self type, or predicate E0208, E0209, // builtin traits can only be implemented on structs or enums E0210, // type parameter is not constrained by any local type From be38926b6941f13b1f03c2e3523b98dd256b3c7b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 30 Jun 2015 12:35:01 +0200 Subject: [PATCH 15/17] Add E0119 error explanation Add more explanations --- src/librustc_typeck/diagnostics.rs | 85 +++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 8 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 83e6ea74d83dc..05ddfe89bcf5c 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1245,15 +1245,16 @@ impl Bytes { ... } // error, same as above "##, E0117: r##" -You tried to implement a trait on a type which isn't defined in your crate. -Erroneous code example: +You got this error because because you tried to implement a foreign +trait for a foreign type (with maybe a foreign type parameter). Erroneous +code example: ``` impl Drop for u32 {} ``` -The type on which you want to implement the trait has to be defined in -your crate. Example: +The type, trait or the type parameter (or all of them) has to be defined +in your crate. Example: ``` pub struct Foo; // you define your type in your crate @@ -1261,6 +1262,75 @@ pub struct Foo; // you define your type in your crate impl Drop for Foo { // and you can implement the trait on it! // code of trait implementation here } + +trait Bar { // or define your trait in your crate + fn get(&self) -> usize; +} + +impl Bar for u32 { // and then you implement it on a foreign type + fn get(&self) -> usize { 0 } +} + +impl From for i32 { // or you use a type from your crate as + // a type parameter + fn from(i: Foo) -> i32 { + 0 + } +} +``` +"##, + +E0119: r##" +There are conflicting trait implementations for the same type. +Erroneous code example: + +``` +trait MyTrait { + fn get(&self) -> usize; +} + +impl MyTrait for T { + fn get(&self) -> usize { 0 } +} + +struct Foo { + value: usize +} + +impl MyTrait for Foo { // error: conflicting implementations for trait + // `MyTrait` + fn get(&self) -> usize { self.value } +} +``` + +When you write: + +``` +impl MyTrait for T { + fn get(&self) -> usize { 0 } +} +``` + +This makes the trait implemented on all types in the scope. So if you +try to implement it on another one after that, the implementations will +conflict. Example: + +``` +trait MyTrait { + fn get(&self) -> usize; +} + +impl MyTrait for T { + fn get(&self) -> usize { 0 } +} + +struct Foo; + +fn main() { + let f = Foo; + + f.get(); // the trait is implemented so we can use it +} ``` "##, @@ -1403,7 +1473,7 @@ impl Trait for Foo { } ``` -The `'b` lifetime constraint for bar() implementation does not match the +The lifetime constraint `'b` for bar() implementation does not match the trait declaration. Ensure lifetime declarations match exactly in both trait declaration and implementation. Example: @@ -1601,8 +1671,8 @@ impl Copy for &'static Bar { } // error "##, E0207: r##" -You passed an unused type parameter when implementing a trait -on an object. Erroneous code example: +You declared an unused type parameter when implementing a trait on an object. +Erroneous code example: ``` trait MyTrait { @@ -1883,7 +1953,6 @@ register_diagnostics! { E0103, E0104, E0118, - E0119, E0120, E0122, E0123, From bc1b43cd0bbd14c72aebb81f3496cbe287241f7c Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Sat, 27 Jun 2015 22:58:49 +0200 Subject: [PATCH 16/17] doc: add example for Stdin::read_line --- src/libstd/io/stdio.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 9fd48f6795039..2a64d0f6e8c19 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -204,6 +204,28 @@ impl Stdin { /// /// For detailed semantics of this method, see the documentation on /// `BufRead::read_line`. + /// + /// # Examples + /// + /// ```no_run + /// use std::io; + /// + /// let mut input = String::new(); + /// match io::stdin().read_line(&mut input) { + /// Ok(n) => { + /// println!("{} bytes read", n); + /// println!("{}", input); + /// } + /// Err(error) => println!("error: {}", error), + /// } + /// ``` + /// + /// You can run the example one of two ways: + /// + /// - Pipe some text to it, e.g. `printf foo | path/to/executable` + /// - Give it text interactively by running the executable directly, + // in which case it will wait for the Enter key to be pressed before + /// continuing #[stable(feature = "rust1", since = "1.0.0")] pub fn read_line(&mut self, buf: &mut String) -> io::Result { self.lock().read_line(buf) From 8b81f76593ce044b0d822f07061c93b515f7dc01 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 30 Jun 2015 18:46:31 -0400 Subject: [PATCH 17/17] Make note of Ord's derive ordering Fixes #26620 --- src/libcore/cmp.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index 0269499ad5414..52ed29c1b61f4 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -166,6 +166,8 @@ impl Ordering { /// /// - total and antisymmetric: exactly one of `a < b`, `a == b` or `a > b` is true; and /// - transitive, `a < b` and `b < c` implies `a < c`. The same must hold for both `==` and `>`. +/// +/// When this trait is `derive`d, it produces a lexicographic ordering. #[stable(feature = "rust1", since = "1.0.0")] pub trait Ord: Eq + PartialOrd { /// This method returns an `Ordering` between `self` and `other`.