From 020be74f6bc5131b79a46d94a1111c35b187469a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 19 Dec 2019 13:45:28 +0100 Subject: [PATCH 1/4] Clean up E0120 long explanation --- src/librustc_error_codes/error_codes/E0120.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0120.md b/src/librustc_error_codes/error_codes/E0120.md index 99c2a493a46b9..4861ed8e89718 100644 --- a/src/librustc_error_codes/error_codes/E0120.md +++ b/src/librustc_error_codes/error_codes/E0120.md @@ -1,5 +1,7 @@ -An attempt was made to implement Drop on a trait, which is not allowed: only -structs and enums can implement Drop. An example causing this error: +The Drop was implemented on a trait, which is not allowed: only structs and +enums can implement Drop. + +Erroneous code example: ```compile_fail,E0120 trait MyTrait {} @@ -10,7 +12,7 @@ impl Drop for MyTrait { ``` A workaround for this problem is to wrap the trait up in a struct, and implement -Drop on that. An example is shown below: +Drop on that: ``` trait MyTrait {} @@ -22,7 +24,7 @@ impl Drop for MyWrapper { ``` -Alternatively, wrapping trait objects requires something like the following: +Alternatively, wrapping trait objects requires something: ``` trait MyTrait {} From 94d207f4b27ba45b8d33e7e73d0829074a02117d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 19 Dec 2019 13:45:36 +0100 Subject: [PATCH 2/4] Clean up E0121 long explanation --- src/librustc_error_codes/error_codes/E0121.md | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0121.md b/src/librustc_error_codes/error_codes/E0121.md index 069d0fc48fb0f..6c20b2803cbe3 100644 --- a/src/librustc_error_codes/error_codes/E0121.md +++ b/src/librustc_error_codes/error_codes/E0121.md @@ -1,10 +1,24 @@ -In order to be consistent with Rust's lack of global type inference, -type and const placeholders are disallowed by design in item signatures. +The type placeholder `_` was used withing a type on an item's signature. -Examples of this error include: +Erroneous code example: ```compile_fail,E0121 -fn foo() -> _ { 5 } // error, explicitly write out the return type instead +fn foo() -> _ { 5 } // error -static BAR: _ = "test"; // error, explicitly write out the type instead +static BAR: _ = "test"; // error +``` + +In those cases, you need to provide the type explicitly: + +``` +fn foo() -> i32 { 5 } // ok! + +static BAR: &str = "test"; // ok! +``` + +The type placeholder `_` can be used outside item's signature as follows: + +``` +let x = "a4a".split('4') + .collect::>(); // No need to precise the Vec's generic type. ``` From 7f0741db9e521355ab732601f4ab53d586748ad1 Mon Sep 17 00:00:00 2001 From: Dylan DPC Date: Fri, 20 Dec 2019 16:50:20 +0530 Subject: [PATCH 3/4] Update E0120.md --- src/librustc_error_codes/error_codes/E0120.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_error_codes/error_codes/E0120.md b/src/librustc_error_codes/error_codes/E0120.md index 4861ed8e89718..dc7258d87317f 100644 --- a/src/librustc_error_codes/error_codes/E0120.md +++ b/src/librustc_error_codes/error_codes/E0120.md @@ -1,4 +1,4 @@ -The Drop was implemented on a trait, which is not allowed: only structs and +Drop was implemented on a trait, which is not allowed: only structs and enums can implement Drop. Erroneous code example: From dce0f06f953d4f0f46cc7ca108c55f326febc790 Mon Sep 17 00:00:00 2001 From: Dylan DPC Date: Fri, 20 Dec 2019 17:02:39 +0530 Subject: [PATCH 4/4] Update E0121.md --- src/librustc_error_codes/error_codes/E0121.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_error_codes/error_codes/E0121.md b/src/librustc_error_codes/error_codes/E0121.md index 6c20b2803cbe3..06fe396d50d3b 100644 --- a/src/librustc_error_codes/error_codes/E0121.md +++ b/src/librustc_error_codes/error_codes/E0121.md @@ -1,4 +1,4 @@ -The type placeholder `_` was used withing a type on an item's signature. +The type placeholder `_` was used within a type on an item's signature. Erroneous code example: