]> git.lizzy.rs Git - rust.git/commitdiff
Add new error code
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Mon, 29 May 2017 16:46:29 +0000 (18:46 +0200)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Tue, 30 May 2017 17:19:34 +0000 (19:19 +0200)
12 files changed:
src/librustc/diagnostics.rs
src/librustc/middle/entry.rs
src/librustc/session/mod.rs
src/librustc_errors/lib.rs
src/libsyntax/diagnostics/macros.rs
src/test/ui/missing-items/m2.stderr
src/test/ui/resolve/issue-14254.stderr
src/test/ui/resolve/issue-21221-2.stderr
src/test/ui/resolve/suggest-path-instead-of-mod-dot-item.stderr
src/test/ui/span/issue-35987.stderr
src/test/ui/token/issue-10636-2.stderr
src/test/ui/token/issue-41155.stderr

index 470dcb4bd61e10e431bf8e3392e3734c288081c7..2beb40d6b2f1ab34598a52849779be57a9ca4f72 100644 (file)
@@ -1871,7 +1871,9 @@ extern "C" fn foo(userdata: Box<i32>) {
 
 E0593: r##"
 You tried to supply an `Fn`-based type with an incorrect number of arguments
-than what was expected. Erroneous code example:
+than what was expected.
+
+Erroneous code example:
 
 ```compile_fail,E0593
 fn foo<F: Fn()>(x: F) { }
@@ -1883,6 +1885,21 @@ fn main() {
 ```
 "##,
 
+E0601: r##"
+No `main` function was found in a binary crate. To fix this error, just add a
+`main` function. For example:
+
+```
+fn main() {
+    // Your program will start here.
+    println!("Hello world!");
+}
+```
+
+If you don't know the basics of Rust, you can go look to the Rust Book to get
+started: https://doc.rust-lang.org/book/
+"##,
+
 }
 
 
index 24748b6cf65b8aab05159071a883fcd4821885b4..b26cccf5f161746a3883fa84ba8ddd240de192ef 100644 (file)
@@ -162,7 +162,7 @@ fn configure_main(this: &mut EntryContext) {
         this.session.entry_type.set(Some(config::EntryMain));
     } else {
         // No main function
-        let mut err = this.session.struct_err("main function not found");
+        let mut err = struct_err!(this.session, E0601, "main function not found");
         if !this.non_main_fns.is_empty() {
             // There were some functions named 'main' though. Try to give the user a hint.
             err.note("the main function must be defined at the crate level \
index 28531893659e61f05bb291ccd26e177f6ca4d9e3..827fa72f034045e90701bc34d8679a4745c7c35c 100644 (file)
@@ -158,14 +158,14 @@ pub fn local_crate_disambiguator(&self) -> Symbol {
     pub fn struct_span_warn<'a, S: Into<MultiSpan>>(&'a self,
                                                     sp: S,
                                                     msg: &str)
-                                                    -> DiagnosticBuilder<'a>  {
+                                                    -> DiagnosticBuilder<'a> {
         self.diagnostic().struct_span_warn(sp, msg)
     }
     pub fn struct_span_warn_with_code<'a, S: Into<MultiSpan>>(&'a self,
                                                               sp: S,
                                                               msg: &str,
                                                               code: &str)
-                                                              -> DiagnosticBuilder<'a>  {
+                                                              -> DiagnosticBuilder<'a> {
         self.diagnostic().struct_span_warn_with_code(sp, msg, code)
     }
     pub fn struct_warn<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a>  {
@@ -174,30 +174,34 @@ pub fn struct_warn<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a>  {
     pub fn struct_span_err<'a, S: Into<MultiSpan>>(&'a self,
                                                    sp: S,
                                                    msg: &str)
-                                                   -> DiagnosticBuilder<'a>  {
+                                                   -> DiagnosticBuilder<'a> {
         self.diagnostic().struct_span_err(sp, msg)
     }
     pub fn struct_span_err_with_code<'a, S: Into<MultiSpan>>(&'a self,
                                                              sp: S,
                                                              msg: &str,
                                                              code: &str)
-                                                             -> DiagnosticBuilder<'a>  {
+                                                             -> DiagnosticBuilder<'a> {
         self.diagnostic().struct_span_err_with_code(sp, msg, code)
     }
-    pub fn struct_err<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a>  {
+    // FIXME: This method should be removed (every error should have an associated error code).
+    pub fn struct_err<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
         self.diagnostic().struct_err(msg)
     }
+    pub fn struct_err_with_code<'a>(&'a self, msg: &str, code: &str) -> DiagnosticBuilder<'a> {
+        self.diagnostic().struct_err_with_code(msg, code)
+    }
     pub fn struct_span_fatal<'a, S: Into<MultiSpan>>(&'a self,
                                                      sp: S,
                                                      msg: &str)
-                                                     -> DiagnosticBuilder<'a>  {
+                                                     -> DiagnosticBuilder<'a> {
         self.diagnostic().struct_span_fatal(sp, msg)
     }
     pub fn struct_span_fatal_with_code<'a, S: Into<MultiSpan>>(&'a self,
                                                                sp: S,
                                                                msg: &str,
                                                                code: &str)
-                                                               -> DiagnosticBuilder<'a>  {
+                                                               -> DiagnosticBuilder<'a> {
         self.diagnostic().struct_span_fatal_with_code(sp, msg, code)
     }
     pub fn struct_fatal<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a>  {
index f7191e49216375c6e21da99d2a94d2805f8c00cc..d1aaaf4ba7b378c7e8dd0f2f9e78cf5b15a525b8 100644 (file)
@@ -345,9 +345,15 @@ pub fn struct_span_err_with_code<'a, S: Into<MultiSpan>>(&'a self,
         result.code(code.to_owned());
         result
     }
+    // FIXME: This method should be removed (every error should have an associated error code).
     pub fn struct_err<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
         DiagnosticBuilder::new(self, Level::Error, msg)
     }
+    pub fn struct_err_with_code<'a>(&'a self, msg: &str, code: &str) -> DiagnosticBuilder<'a> {
+        let mut result = DiagnosticBuilder::new(self, Level::Error, msg);
+        result.code(code.to_owned());
+        result
+    }
     pub fn struct_span_fatal<'a, S: Into<MultiSpan>>(&'a self,
                                                      sp: S,
                                                      msg: &str)
index 25e0428248df4f7a9a6d03ad9ff75babb52582f5..13016d72127eabd3ad511892e22c54ef72c66aa4 100644 (file)
@@ -38,6 +38,14 @@ macro_rules! span_warn {
     })
 }
 
+#[macro_export]
+macro_rules! struct_err {
+    ($session:expr, $code:ident, $($message:tt)*) => ({
+        __diagnostic_used!($code);
+        $session.struct_err_with_code(&format!($($message)*), stringify!($code))
+    })
+}
+
 #[macro_export]
 macro_rules! span_err_or_warn {
     ($is_warning:expr, $session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
index 26748d18ffa954ac004fa583d92c45abebce771f..2d699c66359d82edf2165b32632776fb229fa207 100644 (file)
@@ -1,4 +1,4 @@
-error: main function not found
+error[E0601]: main function not found
 
 error[E0046]: not all trait items implemented, missing: `CONSTANT`, `Type`, `method`
   --> $DIR/m2.rs:20:1
index 8aaad906ea28a477e8c7324b2815ed46e1469ade..009d969fc285d703b6ae838023045ca81ae5c294 100644 (file)
@@ -142,7 +142,7 @@ error[E0425]: cannot find value `bah` in this scope
 133 |         bah;
     |         ^^^ did you mean `Self::bah`?
 
-error: main function not found
+error[E0601]: main function not found
 
 error: aborting due to previous error(s)
 
index f0b22754e6444607af28f16310bbe92a490c5f7e..b35f1bd26706ccfc5bafcf5b03018d13ac9159a8 100644 (file)
@@ -7,7 +7,7 @@ error[E0405]: cannot find trait `T` in this scope
 help: possible candidate is found in another module, you can import it into scope
    | use foo::bar::T;
 
-error: main function not found
+error[E0601]: main function not found
 
 error: cannot continue compilation due to previous error
 
index 24cef694737e05e8cc32825e0954ed7de2504d24..a34c27a47da8288892b482a4f6043f34cf56b902 100644 (file)
@@ -72,7 +72,7 @@ error[E0423]: expected function, found module `a::b`
    |        |
    |        did you mean `I`?
 
-error: main function not found
+error[E0601]: main function not found
 
 error: aborting due to previous error(s)
 
index e53ea6a55afb5dc3a9b1028bba5f5d89312fe0e9..a2597aba0bd295af2c3efe6c5821cb24027572ba 100644 (file)
@@ -7,7 +7,7 @@ error[E0404]: expected trait, found type parameter `Add`
 help: possible better candidate is found in another module, you can import it into scope
    | use std::ops::Add;
 
-error: main function not found
+error[E0601]: main function not found
 
 error: cannot continue compilation due to previous error
 
index faa30dca94581effc840dcc6ba1f3f9f90b4407e..4b0b05ca65adc89eee6a6baf957dc68bcc75ef57 100644 (file)
@@ -22,7 +22,7 @@ error: expected expression, found `)`
 19 | } //~ ERROR: incorrect close delimiter
    | ^
 
-error: main function not found
+error[E0601]: main function not found
 
 error: aborting due to previous error(s)
 
index 96c2d764e7101f2e76760b84fdd69395ba0b762a..56f71a2995382759495c4daf6e8dfaa1160e19ff 100644 (file)
@@ -12,7 +12,7 @@ error[E0412]: cannot find type `S` in this scope
 11 | impl S {
    |      ^ not found in this scope
 
-error: main function not found
+error[E0601]: main function not found
 
 error: aborting due to previous error(s)