about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2017-02-12 15:18:41 +0100
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2017-02-21 15:52:14 +0100
commitb6818be41dea90e53344f84770f5e0faaacee4a8 (patch)
treeb14ffb3c7e637eeefd43490868600432cd82dbf7 /src/libsyntax
parent0a45dd7e711abdd3bcfb6292bba836485ee82fae (diff)
downloadrust-b6818be41dea90e53344f84770f5e0faaacee4a8.tar.gz
rust-b6818be41dea90e53344f84770f5e0faaacee4a8.zip
Add long error explanations
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/diagnostic_list.rs71
-rw-r--r--src/libsyntax/parse/parser.rs34
2 files changed, 85 insertions, 20 deletions
diff --git a/src/libsyntax/diagnostic_list.rs b/src/libsyntax/diagnostic_list.rs
index f482b818f77..2d59051ec4a 100644
--- a/src/libsyntax/diagnostic_list.rs
+++ b/src/libsyntax/diagnostic_list.rs
@@ -201,6 +201,74 @@ where appropriate is ongoing. Try using an unquoted name instead:
 pub fn something() {}
 ```
 "##,
+
+E0583: r##"
+A file wasn't found for an out-of-line module.
+
+Erroneous code example:
+
+```compile_fail,E0583
+mod file_that_doesnt_exist; // error: file not found for module
+
+fn main() {}
+```
+
+Please be sure that a file corresponding to the module exists. If you
+want to use a module named `file_that_doesnt_exist`, you need to have a file
+named `file_that_doesnt_exist.rs` or `file_that_doesnt_exist/mod.rs` in the
+same directory.
+"##,
+
+E0585: r##"
+A documentation comment that doesn't document anything was found.
+
+Erroneous code example:
+
+```compile_fail,E0585
+fn main() {
+    // The following doc comment will fail:
+    /// This is a useless doc comment!
+}
+```
+
+Documentation comments need to be followed by items, including functions,
+types, modules, etc. Examples:
+
+```
+/// I'm documenting the following struct:
+struct Foo;
+
+/// I'm documenting the following function:
+fn foo() {}
+```
+"##,
+
+E0586: r##"
+An inclusive range was used with no end.
+
+Erroneous code example:
+
+```compile_fail,E0586
+let tmp = vec![0, 1, 2, 3, 4, 4, 3, 3, 2, 1];
+let x = &tmp[1...]; // error: inclusive range was used with no end
+```
+
+An inclusive range needs an end in order to *include* it. If you just need a
+start and no end, use a non-inclusive range (with `..`):
+
+```
+let tmp = vec![0, 1, 2, 3, 4, 4, 3, 3, 2, 1];
+let x = &tmp[1..]; // ok!
+```
+
+Or put an end to your inclusive range:
+
+```
+let tmp = vec![0, 1, 2, 3, 4, 4, 3, 3, 2, 1];
+let x = &tmp[1...3]; // ok!
+```
+"##,
+
 }
 
 register_diagnostics! {
@@ -224,8 +292,5 @@ register_diagnostics! {
     E0555, // malformed feature attribute, expected #![feature(...)]
     E0556, // malformed feature, expected just one word
     E0557, // feature has been removed
-    E0583, // file not found for module
     E0584, // file for module `..` found at both .. and ..
-    E0585, // documentation comment that doesn't document anything
-    E0586, // inclusive range with no end
 }
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 464d16f53a3..b5b8a6bc0ef 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -219,7 +219,7 @@ fn is_ident_or_underscore(t: &token::Token) -> bool {
 pub struct ModulePath {
     pub name: String,
     pub path_exists: bool,
-    pub result: Result<ModulePathSuccess, Errors>,
+    pub result: Result<ModulePathSuccess, Error>,
 }
 
 pub struct ModulePathSuccess {
@@ -233,7 +233,7 @@ pub struct ModulePathError {
     pub help_msg: String,
 }
 
-pub enum Errors {
+pub enum Error {
     FileNotFoundForModule {
         mod_name: String,
         default_path: String,
@@ -249,13 +249,13 @@ pub enum Errors {
     InclusiveRangeWithNoEnd,
 }
 
-impl Errors {
+impl Error {
     pub fn span_err<'a>(self, sp: Span, handler: &'a errors::Handler) -> DiagnosticBuilder<'a> {
         match self {
-            Errors::FileNotFoundForModule { ref mod_name,
-                                            ref default_path,
-                                            ref secondary_path,
-                                            ref dir_path } => {
+            Error::FileNotFoundForModule { ref mod_name,
+                                           ref default_path,
+                                           ref secondary_path,
+                                           ref dir_path } => {
                 let mut err = struct_span_err!(handler, sp, E0583,
                                                "file not found for module `{}`", mod_name);
                 err.help(&format!("name the file either {} or {} inside the directory {:?}",
@@ -264,7 +264,7 @@ impl Errors {
                                   dir_path));
                 err
             }
-            Errors::DuplicatePaths { ref mod_name, ref default_path, ref secondary_path } => {
+            Error::DuplicatePaths { ref mod_name, ref default_path, ref secondary_path } => {
                 let mut err = struct_span_err!(handler, sp, E0584,
                                                "file for module `{}` found at both {} and {}",
                                                mod_name,
@@ -273,14 +273,14 @@ impl Errors {
                 err.help("delete or rename one of them to remove the ambiguity");
                 err
             }
-            Errors::UselessDocComment => {
+            Error::UselessDocComment => {
                 let mut err = struct_span_err!(handler, sp, E0585,
                                   "found a documentation comment that doesn't document anything");
                 err.help("doc comments must come before what they document, maybe a comment was \
                           intended with `//`?");
                 err
             }
-            Errors::InclusiveRangeWithNoEnd => {
+            Error::InclusiveRangeWithNoEnd => {
                 let mut err = struct_span_err!(handler, sp, E0586,
                                                "inclusive range with no end");
                 err.help("inclusive ranges must be bounded at the end (`...b` or `a...b`)");
@@ -518,7 +518,7 @@ impl<'a> Parser<'a> {
             }
             _ => {
                 Err(if self.prev_token_kind == PrevTokenKind::DocComment {
-                        self.span_fatal_err(self.prev_span, Errors::UselessDocComment)
+                        self.span_fatal_err(self.prev_span, Error::UselessDocComment)
                     } else {
                         let mut err = self.fatal(&format!("expected identifier, found `{}`",
                                                           self.this_token_to_string()));
@@ -1009,7 +1009,7 @@ impl<'a> Parser<'a> {
     pub fn span_fatal(&self, sp: Span, m: &str) -> DiagnosticBuilder<'a> {
         self.sess.span_diagnostic.struct_span_fatal(sp, m)
     }
-    pub fn span_fatal_err(&self, sp: Span, err: Errors) -> DiagnosticBuilder<'a> {
+    pub fn span_fatal_err(&self, sp: Span, err: Error) -> DiagnosticBuilder<'a> {
         err.span_err(sp, self.diagnostic())
     }
     pub fn span_fatal_help(&self, sp: Span, m: &str, help: &str) -> DiagnosticBuilder<'a> {
@@ -2001,7 +2001,7 @@ impl<'a> Parser<'a> {
                     limits: RangeLimits)
                     -> PResult<'a, ast::ExprKind> {
         if end.is_none() && limits == RangeLimits::Closed {
-            Err(self.span_fatal_err(self.span, Errors::InclusiveRangeWithNoEnd))
+            Err(self.span_fatal_err(self.span, Error::InclusiveRangeWithNoEnd))
         } else {
             Ok(ExprKind::Range(start, end, limits))
         }
@@ -3916,7 +3916,7 @@ impl<'a> Parser<'a> {
                     let unused_attrs = |attrs: &[_], s: &mut Self| {
                         if attrs.len() > 0 {
                             if s.prev_token_kind == PrevTokenKind::DocComment {
-                                self.span_fatal_err(s.prev_span, Errors::UselessDocComment).emit();
+                                s.span_fatal_err(s.prev_span, Error::UselessDocComment).emit();
                             } else {
                                 s.span_err(s.span, "expected statement after outer attribute");
                             }
@@ -5050,7 +5050,7 @@ impl<'a> Parser<'a> {
             }
             token::CloseDelim(token::Brace) => {}
             token::DocComment(_) => return Err(self.span_fatal_err(self.span,
-                                                                   Errors::UselessDocComment)),
+                                                                   Error::UselessDocComment)),
             _ => return Err(self.span_fatal_help(self.span,
                     &format!("expected `,`, or `}}`, found `{}`", self.this_token_to_string()),
                     "struct fields should be separated by commas")),
@@ -5231,13 +5231,13 @@ impl<'a> Parser<'a> {
                 directory_ownership: DirectoryOwnership::Owned,
                 warn: false,
             }),
-            (false, false) => Err(Errors::FileNotFoundForModule {
+            (false, false) => Err(Error::FileNotFoundForModule {
                 mod_name: mod_name.clone(),
                 default_path: default_path_str,
                 secondary_path: secondary_path_str,
                 dir_path: format!("{}", dir_path.display()),
             }),
-            (true, true) => Err(Errors::DuplicatePaths {
+            (true, true) => Err(Error::DuplicatePaths {
                 mod_name: mod_name.clone(),
                 default_path: default_path_str,
                 secondary_path: secondary_path_str,