From a2b7dfa3493b146936547b0f4ca44cc9cd57dd95 Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Sun, 29 May 2016 17:50:08 -0700 Subject: [PATCH 1/2] add explanation for E0429 (`self` use declaration must use brace syntax) This is an item under #32777. --- src/librustc_resolve/diagnostics.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index 35148622052..177a85709e4 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -1029,6 +1029,32 @@ struct Bar2; // ok! ``` "##, +E0429: r##" +To import a namespace itself in addition to some of its members, the `self` +keyword may appear in a brace-enclosed list as the last segment in a `use` +declaration. However, `self` cannot be used alone, without the brace +syntax. + +Example of erroneous code: + +```compile_fail +use std::fmt::self; // error: `self` imports are only allowed within a { } list +``` + +If you only want to import the namespace, do so directly: + +``` +use std::fmt; +``` + +If you also want to import members in the same statement, you may use the brace +syntax: + +``` +use std::fmt::{self, Debug}; +``` +"##, + E0430: r##" The `self` import appears more than once in the list. Erroneous code example: @@ -1235,5 +1261,4 @@ register_diagnostics! { E0420, // is not an associated const E0421, // unresolved associated const E0427, // cannot use `ref` binding mode with ... - E0429, // `self` imports are only allowed within a { } list } From 06ebda837e50634cd1a73d54ce36a6fdec9688c5 Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Mon, 30 May 2016 16:45:41 -0700 Subject: [PATCH 2/2] revise explanation for E0429 (focus on error first) --- src/librustc_resolve/diagnostics.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index 177a85709e4..88eee54852e 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -1030,10 +1030,8 @@ struct Bar2; // ok! "##, E0429: r##" -To import a namespace itself in addition to some of its members, the `self` -keyword may appear in a brace-enclosed list as the last segment in a `use` -declaration. However, `self` cannot be used alone, without the brace -syntax. +The `self` keyword cannot appear alone as the last segment in a `use` +declaration. Example of erroneous code: @@ -1041,18 +1039,18 @@ Example of erroneous code: use std::fmt::self; // error: `self` imports are only allowed within a { } list ``` +To use a namespace itself in addition to some of its members, `self` may appear +as part of a brace-enclosed list of imports: + +``` +use std::fmt::{self, Debug}; +``` + If you only want to import the namespace, do so directly: ``` use std::fmt; ``` - -If you also want to import members in the same statement, you may use the brace -syntax: - -``` -use std::fmt::{self, Debug}; -``` "##, E0430: r##"