From 481b18acd09b480cc1ca50ea726cf91847f928f1 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 30 Nov 2019 13:28:53 +0100 Subject: Small error codes explanation cleanup (E0092, E0093 and E0094) --- src/librustc_error_codes/error_codes/E0092.md | 7 ++++--- src/librustc_error_codes/error_codes/E0093.md | 8 +++++--- src/librustc_error_codes/error_codes/E0094.md | 3 ++- src/librustc_error_codes/error_codes/E0106.md | 4 ++-- 4 files changed, 13 insertions(+), 9 deletions(-) (limited to 'src/librustc_error_codes/error_codes') diff --git a/src/librustc_error_codes/error_codes/E0092.md b/src/librustc_error_codes/error_codes/E0092.md index 2750a7d45b4..e289534bf7a 100644 --- a/src/librustc_error_codes/error_codes/E0092.md +++ b/src/librustc_error_codes/error_codes/E0092.md @@ -1,4 +1,5 @@ -You tried to declare an undefined atomic operation function. +An undefined atomic operation function was declared. + Erroneous code example: ```compile_fail,E0092 @@ -11,8 +12,8 @@ extern "rust-intrinsic" { ``` Please check you didn't make a mistake in the function's name. All intrinsic -functions are defined in librustc_codegen_llvm/intrinsic.rs and in -libcore/intrinsics.rs in the Rust source code. Example: +functions are defined in `librustc_codegen_llvm/intrinsic.rs` and in +`libcore/intrinsics.rs` in the Rust source code. Example: ``` #![feature(intrinsics)] diff --git a/src/librustc_error_codes/error_codes/E0093.md b/src/librustc_error_codes/error_codes/E0093.md index 9633f794d8b..8e7de1a9d37 100644 --- a/src/librustc_error_codes/error_codes/E0093.md +++ b/src/librustc_error_codes/error_codes/E0093.md @@ -1,4 +1,6 @@ -You declared an unknown intrinsic function. Erroneous code example: +An unknown intrinsic function was declared. + +Erroneous code example: ```compile_fail,E0093 #![feature(intrinsics)] @@ -15,8 +17,8 @@ fn main() { ``` Please check you didn't make a mistake in the function's name. All intrinsic -functions are defined in librustc_codegen_llvm/intrinsic.rs and in -libcore/intrinsics.rs in the Rust source code. Example: +functions are defined in `librustc_codegen_llvm/intrinsic.rs` and in +`libcore/intrinsics.rs` in the Rust source code. Example: ``` #![feature(intrinsics)] diff --git a/src/librustc_error_codes/error_codes/E0094.md b/src/librustc_error_codes/error_codes/E0094.md index 4d27f616d2d..42baa65bf9f 100644 --- a/src/librustc_error_codes/error_codes/E0094.md +++ b/src/librustc_error_codes/error_codes/E0094.md @@ -1,4 +1,5 @@ -You gave an invalid number of type parameters to an intrinsic function. +An invalid number of type parameters was given to an intrinsic function. + Erroneous code example: ```compile_fail,E0094 diff --git a/src/librustc_error_codes/error_codes/E0106.md b/src/librustc_error_codes/error_codes/E0106.md index 8a49c1f79e4..60ca1ddc283 100644 --- a/src/librustc_error_codes/error_codes/E0106.md +++ b/src/librustc_error_codes/error_codes/E0106.md @@ -2,7 +2,7 @@ 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 lifetime elision rules (see below). -Here are some simple examples of where you'll run into this error: +Erroneous code examples: ```compile_fail,E0106 struct Foo1 { x: &bool } @@ -27,7 +27,7 @@ function signatures which allows you to leave out lifetimes in certain cases. For more background on lifetime elision see [the book][book-le]. The lifetime elision rules require that any function signature with an elided -output lifetime must either have +output lifetime must either have: - exactly one input lifetime - or, multiple input lifetimes, but the function must also be a method with a -- cgit 1.4.1-3-g733a5 From 7693bb9e1d122bea1b0645dcc201c6ed79c910e2 Mon Sep 17 00:00:00 2001 From: Reese Williams Date: Mon, 2 Dec 2019 21:52:04 -0500 Subject: Add long error for E0631 and update ui tests. --- src/librustc_error_codes/error_codes.rs | 2 +- src/librustc_error_codes/error_codes/E0631.md | 29 ++++++++++++++++++++++ .../ui/anonymous-higher-ranked-lifetime.stderr | 1 + .../expect-fn-supply-fn.stderr | 3 ++- .../expect-infer-var-appearing-twice.stderr | 1 + src/test/ui/closures/issue-41366.stderr | 3 ++- src/test/ui/issues/issue-43623.stderr | 3 ++- src/test/ui/issues/issue-60283.stderr | 3 ++- src/test/ui/mismatched_types/E0631.stderr | 1 + .../closure-arg-type-mismatch.stderr | 3 ++- .../ui/mismatched_types/closure-mismatch.stderr | 3 ++- src/test/ui/mismatched_types/fn-variance-1.stderr | 1 + src/test/ui/mismatched_types/issue-36053-2.stderr | 3 ++- .../unboxed-closures-vtable-mismatch.stderr | 1 + 14 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 src/librustc_error_codes/error_codes/E0631.md (limited to 'src/librustc_error_codes/error_codes') diff --git a/src/librustc_error_codes/error_codes.rs b/src/librustc_error_codes/error_codes.rs index 7f111b42403..9e4b704170b 100644 --- a/src/librustc_error_codes/error_codes.rs +++ b/src/librustc_error_codes/error_codes.rs @@ -347,6 +347,7 @@ E0622: include_str!("./error_codes/E0622.md"), E0623: include_str!("./error_codes/E0623.md"), E0624: include_str!("./error_codes/E0624.md"), E0626: include_str!("./error_codes/E0626.md"), +E0631: include_str!("./error_codes/E0631.md"), E0633: include_str!("./error_codes/E0633.md"), E0635: include_str!("./error_codes/E0635.md"), E0636: include_str!("./error_codes/E0636.md"), @@ -580,7 +581,6 @@ E0745: include_str!("./error_codes/E0745.md"), // rustc_const_unstable attribute must be paired with stable/unstable // attribute E0630, - E0631, // type mismatch in closure arguments E0632, // cannot provide explicit generic arguments when `impl Trait` is // used in argument position E0634, // type has conflicting packed representaton hints diff --git a/src/librustc_error_codes/error_codes/E0631.md b/src/librustc_error_codes/error_codes/E0631.md new file mode 100644 index 00000000000..ad419f82250 --- /dev/null +++ b/src/librustc_error_codes/error_codes/E0631.md @@ -0,0 +1,29 @@ +This error indicates a type mismatch in closure arguments. + +Erroneous code example: + +```compile_fail,E0631 +fn test_strings(string_vec: Vec) -> Vec { + string_vec + .iter() + .map(|arg: &i32| arg.eq("Test String")) + .collect() +} +``` + +The closure passed to `map` expects a `&String` argument, since `some_vec` +has the type `Vec`. +However, the closure argument is annotated as an `&i32`, which does not match +the type of the iterable. + +This can be resolved by changing the type annotation or removing it entirely +if it can be inferred. + +``` +fn test_strings(string_vec: Vec) -> Vec { + string_vec + .iter() + .map(|arg| arg.eq("Test String")) + .collect() +} +``` diff --git a/src/test/ui/anonymous-higher-ranked-lifetime.stderr b/src/test/ui/anonymous-higher-ranked-lifetime.stderr index 9be44c7f448..c6d9a61bdd9 100644 --- a/src/test/ui/anonymous-higher-ranked-lifetime.stderr +++ b/src/test/ui/anonymous-higher-ranked-lifetime.stderr @@ -121,3 +121,4 @@ LL | fn h2(_: F) where F: for<'t0> Fn(&(), Box, &'t0 (), fn(&(), error: aborting due to 11 previous errors +For more information about this error, try `rustc --explain E0631`. diff --git a/src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr b/src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr index a15444207f5..00333958468 100644 --- a/src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr +++ b/src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr @@ -77,4 +77,5 @@ LL | with_closure_expecting_fn_with_bound_region(|x: Foo<'_>, y| { error: aborting due to 5 previous errors -For more information about this error, try `rustc --explain E0308`. +Some errors have detailed explanations: E0308, E0631. +For more information about an error, try `rustc --explain E0308`. diff --git a/src/test/ui/closure-expected-type/expect-infer-var-appearing-twice.stderr b/src/test/ui/closure-expected-type/expect-infer-var-appearing-twice.stderr index 9fbe95a9c39..1c6564ee426 100644 --- a/src/test/ui/closure-expected-type/expect-infer-var-appearing-twice.stderr +++ b/src/test/ui/closure-expected-type/expect-infer-var-appearing-twice.stderr @@ -13,3 +13,4 @@ LL | with_closure(|x: u32, y: i32| { error: aborting due to previous error +For more information about this error, try `rustc --explain E0631`. diff --git a/src/test/ui/closures/issue-41366.stderr b/src/test/ui/closures/issue-41366.stderr index 91d26efbc4f..2f2871e9f0e 100644 --- a/src/test/ui/closures/issue-41366.stderr +++ b/src/test/ui/closures/issue-41366.stderr @@ -19,4 +19,5 @@ LL | (&|_|()) as &dyn for<'x> Fn(>::V); error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0271`. +Some errors have detailed explanations: E0271, E0631. +For more information about an error, try `rustc --explain E0271`. diff --git a/src/test/ui/issues/issue-43623.stderr b/src/test/ui/issues/issue-43623.stderr index 2c57b8585d9..d90eb53f900 100644 --- a/src/test/ui/issues/issue-43623.stderr +++ b/src/test/ui/issues/issue-43623.stderr @@ -25,4 +25,5 @@ LL | break_me::; error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0271`. +Some errors have detailed explanations: E0271, E0631. +For more information about an error, try `rustc --explain E0271`. diff --git a/src/test/ui/issues/issue-60283.stderr b/src/test/ui/issues/issue-60283.stderr index 69c1d85e4e1..d13dcd54a47 100644 --- a/src/test/ui/issues/issue-60283.stderr +++ b/src/test/ui/issues/issue-60283.stderr @@ -27,4 +27,5 @@ LL | foo((), drop) error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0271`. +Some errors have detailed explanations: E0271, E0631. +For more information about an error, try `rustc --explain E0271`. diff --git a/src/test/ui/mismatched_types/E0631.stderr b/src/test/ui/mismatched_types/E0631.stderr index 88c1efdbb90..06f5c058f81 100644 --- a/src/test/ui/mismatched_types/E0631.stderr +++ b/src/test/ui/mismatched_types/E0631.stderr @@ -46,3 +46,4 @@ LL | bar(f); error: aborting due to 4 previous errors +For more information about this error, try `rustc --explain E0631`. diff --git a/src/test/ui/mismatched_types/closure-arg-type-mismatch.stderr b/src/test/ui/mismatched_types/closure-arg-type-mismatch.stderr index 85cad61210e..ed502824712 100644 --- a/src/test/ui/mismatched_types/closure-arg-type-mismatch.stderr +++ b/src/test/ui/mismatched_types/closure-arg-type-mismatch.stderr @@ -45,4 +45,5 @@ LL | baz(f); error: aborting due to 5 previous errors -For more information about this error, try `rustc --explain E0271`. +Some errors have detailed explanations: E0271, E0631. +For more information about an error, try `rustc --explain E0271`. diff --git a/src/test/ui/mismatched_types/closure-mismatch.stderr b/src/test/ui/mismatched_types/closure-mismatch.stderr index fd2b9f3c66b..f3874c0907b 100644 --- a/src/test/ui/mismatched_types/closure-mismatch.stderr +++ b/src/test/ui/mismatched_types/closure-mismatch.stderr @@ -24,4 +24,5 @@ LL | baz(|_| ()); error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0271`. +Some errors have detailed explanations: E0271, E0631. +For more information about an error, try `rustc --explain E0271`. diff --git a/src/test/ui/mismatched_types/fn-variance-1.stderr b/src/test/ui/mismatched_types/fn-variance-1.stderr index 1a82dd53edc..88c92661994 100644 --- a/src/test/ui/mismatched_types/fn-variance-1.stderr +++ b/src/test/ui/mismatched_types/fn-variance-1.stderr @@ -24,3 +24,4 @@ LL | apply(&mut 3, takes_imm); error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0631`. diff --git a/src/test/ui/mismatched_types/issue-36053-2.stderr b/src/test/ui/mismatched_types/issue-36053-2.stderr index 72f3220cc1a..da018aa8948 100644 --- a/src/test/ui/mismatched_types/issue-36053-2.stderr +++ b/src/test/ui/mismatched_types/issue-36053-2.stderr @@ -18,4 +18,5 @@ LL | once::<&str>("str").fuse().filter(|a: &str| true).count(); error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0599`. +Some errors have detailed explanations: E0599, E0631. +For more information about an error, try `rustc --explain E0599`. diff --git a/src/test/ui/mismatched_types/unboxed-closures-vtable-mismatch.stderr b/src/test/ui/mismatched_types/unboxed-closures-vtable-mismatch.stderr index 2daf4781c7e..3c999f200d9 100644 --- a/src/test/ui/mismatched_types/unboxed-closures-vtable-mismatch.stderr +++ b/src/test/ui/mismatched_types/unboxed-closures-vtable-mismatch.stderr @@ -12,3 +12,4 @@ LL | let z = call_it(3, f); error: aborting due to previous error +For more information about this error, try `rustc --explain E0631`. -- cgit 1.4.1-3-g733a5 From 26a1ba85b890cdf7bbb7066c3a18aab84aef171f Mon Sep 17 00:00:00 2001 From: Reese Williams Date: Tue, 3 Dec 2019 07:51:11 -0500 Subject: Use simpler code example for E0631 long error. --- src/librustc_error_codes/error_codes/E0631.md | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'src/librustc_error_codes/error_codes') diff --git a/src/librustc_error_codes/error_codes/E0631.md b/src/librustc_error_codes/error_codes/E0631.md index ad419f82250..6188d5f61a7 100644 --- a/src/librustc_error_codes/error_codes/E0631.md +++ b/src/librustc_error_codes/error_codes/E0631.md @@ -3,27 +3,25 @@ This error indicates a type mismatch in closure arguments. Erroneous code example: ```compile_fail,E0631 -fn test_strings(string_vec: Vec) -> Vec { - string_vec - .iter() - .map(|arg: &i32| arg.eq("Test String")) - .collect() +fn foo(f: F) { +} + +fn main() { + foo(|x: &str| {}); } ``` -The closure passed to `map` expects a `&String` argument, since `some_vec` -has the type `Vec`. -However, the closure argument is annotated as an `&i32`, which does not match -the type of the iterable. +The error occurs because `foo` accepts a closure that takes an `i32` argument, +but in `main`, it is passed a closure with a `&str` argument. This can be resolved by changing the type annotation or removing it entirely if it can be inferred. ``` -fn test_strings(string_vec: Vec) -> Vec { - string_vec - .iter() - .map(|arg| arg.eq("Test String")) - .collect() +fn foo(f: F) { +} + +fn main() { + foo(|x: i32| {}); } ``` -- cgit 1.4.1-3-g733a5 From c911bb1a2e5efc35a8e76bfe6e2581f4a9dfc20b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 30 Nov 2019 13:42:50 +0100 Subject: clean up E0107 error explanation --- src/librustc_error_codes/error_codes/E0107.md | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src/librustc_error_codes/error_codes') diff --git a/src/librustc_error_codes/error_codes/E0107.md b/src/librustc_error_codes/error_codes/E0107.md index bfe0d21f312..4d22b17fe10 100644 --- a/src/librustc_error_codes/error_codes/E0107.md +++ b/src/librustc_error_codes/error_codes/E0107.md @@ -1,4 +1,6 @@ -This error means that an incorrect number of generic arguments were provided: +An incorrect number of generic arguments were provided. + +Erroneous code example: ```compile_fail,E0107 struct Foo { x: T } @@ -9,6 +11,7 @@ struct Baz { x: Foo } // error: wrong number of type arguments: // expected 1, found 2 fn foo(x: T, y: U) {} +fn f() {} fn main() { let x: bool = true; @@ -16,12 +19,26 @@ fn main() { // expected 2, found 1 foo::(x, 2, 4); // error: wrong number of type arguments: // expected 2, found 3 + f::<'static>(); // error: wrong number of lifetime arguments + // expected 0, found 1 } +``` + +When using/declaring an item with generic arguments, you must provide the exact +same number: + +``` +struct Foo { x: T } + +struct Bar { x: Foo } // ok! +struct Baz { x: Foo, y: Foo } // ok! +fn foo(x: T, y: U) {} fn f() {} fn main() { - f::<'static>(); // error: wrong number of lifetime arguments: - // expected 0, found 1 + let x: bool = true; + foo::(x, 12); // ok! + f(); // ok! } ``` -- cgit 1.4.1-3-g733a5 From c2ce7dd756c36cb619c7f231ab6596d6b180afed Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 4 Dec 2019 13:27:17 +0100 Subject: Clean up E0116 error code long explanation --- src/librustc_error_codes/error_codes/E0116.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/librustc_error_codes/error_codes') diff --git a/src/librustc_error_codes/error_codes/E0116.md b/src/librustc_error_codes/error_codes/E0116.md index 27759a42343..ca849c2a128 100644 --- a/src/librustc_error_codes/error_codes/E0116.md +++ b/src/librustc_error_codes/error_codes/E0116.md @@ -1,11 +1,15 @@ -You can only define an inherent implementation for a type in the same crate -where the type was defined. For example, an `impl` block as below is not allowed -since `Vec` is defined in the standard library: +An inherent implementation was defined for a type outside the current crate. + +Erroneous code example: ```compile_fail,E0116 impl Vec { } // error ``` +You can only define an inherent implementation for a type in the same crate +where the type was defined. For example, an `impl` block as above is not allowed +since `Vec` is defined in the standard library. + To fix this problem, you can do either of these things: - define a trait that has the desired associated functions/types/constants and -- cgit 1.4.1-3-g733a5 From 1e5450d4cb7bb951bbdb9bc2b09a984b132c4280 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 4 Dec 2019 13:31:40 +0100 Subject: Clean up E0117 error code long explanation --- src/librustc_error_codes/error_codes/E0117.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/librustc_error_codes/error_codes') diff --git a/src/librustc_error_codes/error_codes/E0117.md b/src/librustc_error_codes/error_codes/E0117.md index bd362305662..7fa211d4a27 100644 --- a/src/librustc_error_codes/error_codes/E0117.md +++ b/src/librustc_error_codes/error_codes/E0117.md @@ -1,3 +1,11 @@ +The `Drop` trait was implemented on a non-struct type. + +Erroneous code example: + +```compile_fail,E0117 +impl Drop for u32 {} +``` + This error indicates a violation of one of Rust's orphan rules for trait implementations. The rule prohibits any implementation of a foreign trait (a trait defined in another crate) where @@ -6,12 +14,6 @@ trait defined in another crate) where - all of the parameters being passed to the trait (if there are any) are also foreign. -Here's one example of this error: - -```compile_fail,E0117 -impl Drop for u32 {} -``` - To avoid this kind of error, ensure that at least one local type is referenced by the `impl`: -- cgit 1.4.1-3-g733a5 From 9eaea4d3ea1ae6d6858af1a83a7d44c759a31212 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 4 Dec 2019 13:35:26 +0100 Subject: Clean up E0118 error code long explanation --- src/librustc_error_codes/error_codes/E0118.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/librustc_error_codes/error_codes') diff --git a/src/librustc_error_codes/error_codes/E0118.md b/src/librustc_error_codes/error_codes/E0118.md index baf35ffbb0b..5cb5f506e0a 100644 --- a/src/librustc_error_codes/error_codes/E0118.md +++ b/src/librustc_error_codes/error_codes/E0118.md @@ -1,5 +1,7 @@ -You're trying to write an inherent implementation for something which isn't a -struct nor an enum. Erroneous code example: +An inherent implementation was defined for something which isn't a struct nor +an enum. + +Erroneous code example: ```compile_fail,E0118 impl (u8, u8) { // error: no base type found for inherent implementation -- cgit 1.4.1-3-g733a5 From ae753a55ac8b16772ad7617c8512433921271abc Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 4 Dec 2019 13:36:50 +0100 Subject: some error codes long explanation --- src/librustc_error_codes/error_codes/E0109.md | 1 + src/librustc_error_codes/error_codes/E0119.md | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'src/librustc_error_codes/error_codes') diff --git a/src/librustc_error_codes/error_codes/E0109.md b/src/librustc_error_codes/error_codes/E0109.md index 5bc229ade52..2eab9725a6f 100644 --- a/src/librustc_error_codes/error_codes/E0109.md +++ b/src/librustc_error_codes/error_codes/E0109.md @@ -1,4 +1,5 @@ You tried to provide a generic argument to a type which doesn't need it. + Erroneous code example: ```compile_fail,E0109 diff --git a/src/librustc_error_codes/error_codes/E0119.md b/src/librustc_error_codes/error_codes/E0119.md index 0af3bd4a0de..e596349e5e2 100644 --- a/src/librustc_error_codes/error_codes/E0119.md +++ b/src/librustc_error_codes/error_codes/E0119.md @@ -1,5 +1,6 @@ There are conflicting trait implementations for the same type. -Example of erroneous code: + +Erroneous code example: ```compile_fail,E0119 trait MyTrait { -- cgit 1.4.1-3-g733a5