about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2015-05-12 22:57:52 +0530
committerManish Goregaokar <manishsmail@gmail.com>2015-05-12 22:57:52 +0530
commitbb15c4762dc6eceb8e34a521e0e6ab627066f314 (patch)
tree19084261ca0609eaa14918239affb369c4dd50a7
parente91d272fbb06a0d56f588ca9ee7a2fb256498aec (diff)
parentaa529ef52e54039fcfaa8aa7914be4c581179497 (diff)
downloadrust-bb15c4762dc6eceb8e34a521e0e6ab627066f314.tar.gz
rust-bb15c4762dc6eceb8e34a521e0e6ab627066f314.zip
Rollup merge of #25267 - meqif:explain_e0317, r=alexcrichton
Add diagnostic message for E0317, E0154, E0259 and E0260; part of #24407.

About E0317, I was unsure if I should add an example of what could be wrong, such as `struct i64`, `enum char { A, B }` or `type isize = i64`. I decided against it, since the diagnostic message looks clear enough to me.

What do you think?
-rw-r--r--src/librustc_resolve/diagnostics.rs108
1 files changed, 104 insertions, 4 deletions
diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs
index a896bd31169..7e7af800680 100644
--- a/src/librustc_resolve/diagnostics.rs
+++ b/src/librustc_resolve/diagnostics.rs
@@ -10,8 +10,111 @@
 
 #![allow(non_snake_case)]
 
+// Error messages for EXXXX errors.
+// Each message should start and end with a new line, and be wrapped to 80 characters.
+// In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use `:set tw=0` to disable.
+register_long_diagnostics! {
+
+E0154: r##"
+Imports (`use` statements) are not allowed after non-item statements, such as
+variable declarations and expression statements.
+
+Here is an example that demonstrates the error:
+```
+fn f() {
+    // Variable declaration before import
+    let x = 0;
+    use std::io::Read;
+    ...
+}
+```
+
+The solution is to declare the imports at the top of the block, function, or
+file.
+
+Here is the previous example again, with the correct order:
+```
+fn f() {
+    use std::io::Read;
+    let x = 0;
+    ...
+}
+```
+
+See the Declaration Statements section of the reference for more information
+about what constitutes an Item declaration and what does not:
+
+http://doc.rust-lang.org/reference.html#statements
+"##,
+
+E0259: r##"
+The name chosen for an external crate conflicts with another external crate that
+has been imported into the current module.
+
+Wrong example:
+```
+extern crate a;
+extern crate crate_a as a;
+```
+
+The solution is to choose a different name that doesn't conflict with any
+external crate imported into the current module.
+
+Correct example:
+```
+extern crate a;
+extern crate crate_a as other_name;
+```
+"##,
+
+E0260: r##"
+The name for an item declaration conflicts with an external crate's name.
+
+For instance,
+```
+extern crate abc;
+
+struct abc;
+```
+
+There are two possible solutions:
+
+Solution #1: Rename the item.
+
+```
+extern crate abc;
+
+struct xyz;
+```
+
+Solution #2: Import the crate with a different name.
+
+```
+extern crate abc as xyz;
+
+struct abc;
+```
+
+See the Declaration Statements section of the reference for more information
+about what constitutes an Item declaration and what does not:
+
+http://doc.rust-lang.org/reference.html#statements
+"##,
+
+E0317: r##"
+User-defined types or type parameters cannot shadow the primitive types.
+This error indicates you tried to define a type, struct or enum with the same
+name as an existing primitive type.
+
+See the Types section of the reference for more information about the primitive
+types:
+
+http://doc.rust-lang.org/reference.html#types
+"##
+
+}
+
 register_diagnostics! {
-    E0154,
     E0157,
     E0153,
     E0251, // a named type or value has already been imported in this module
@@ -22,9 +125,6 @@ register_diagnostics! {
     E0256, // import conflicts with type in this module
     E0257, // inherent implementations are only allowed on types defined in the current module
     E0258, // import conflicts with existing submodule
-    E0259, // an extern crate has already been imported into this module
-    E0260, // name conflicts with an external crate that has been imported into this module
-    E0317, // user-defined types or type parameters cannot shadow the primitive types
     E0364, // item is private
     E0365  // item is private
 }