]> git.lizzy.rs Git - rust.git/commitdiff
Require `extern "Rust" fn main()` exactly
authorAlex Crichton <alex@alexcrichton.com>
Mon, 8 Jul 2013 08:03:16 +0000 (01:03 -0700)
committerDaniel Micay <danielmicay@gmail.com>
Tue, 9 Jul 2013 20:56:16 +0000 (16:56 -0400)
src/librustc/middle/typeck/mod.rs
src/test/compile-fail/bad-main.rs
src/test/compile-fail/extern-main-fn.rs [new file with mode: 0644]
src/test/compile-fail/main-wrong-type-2.rs
src/test/compile-fail/main-wrong-type.rs

index bbcfc73853a1e00d292ae078b3ec18afb214c4ea..6f5dde74b5c10909b56acb79c0700295771a7be1 100644 (file)
@@ -319,16 +319,19 @@ fn check_main_fn_ty(ccx: &CrateCtxt,
                 }
                 _ => ()
             }
-            let mut ok = ty::type_is_nil(fn_ty.sig.output);
-            let num_args = fn_ty.sig.inputs.len();
-            ok &= num_args == 0u;
-            if !ok {
-                tcx.sess.span_err(
-                    main_span,
-                    fmt!("Wrong type in main function: found `%s`, \
-                          expected `fn() -> ()`",
-                         ppaux::ty_to_str(tcx, main_t)));
-            }
+            let se_ty = ty::mk_bare_fn(tcx, ty::BareFnTy {
+                purity: ast::impure_fn,
+                abis: abi::AbiSet::Rust(),
+                sig: ty::FnSig {
+                    bound_lifetime_names: opt_vec::Empty,
+                    inputs: ~[],
+                    output: ty::mk_nil()
+                }
+            });
+
+            require_same_types(tcx, None, false, main_span, main_t, se_ty,
+                || fmt!("main function expects type: `%s`",
+                        ppaux::ty_to_str(ccx.tcx, se_ty)));
         }
         _ => {
             tcx.sess.span_bug(main_span,
index 3f366fcd06fd7814ca57bf074ef2c59ecfbe5ad5..da8596fa25b472ac10d25af8573fbf96e52c4dfa 100644 (file)
@@ -8,6 +8,4 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// error-pattern:expected `fn()
-
-fn main(x: int) { }
+fn main(x: int) { } //~ ERROR: main function expects type
diff --git a/src/test/compile-fail/extern-main-fn.rs b/src/test/compile-fail/extern-main-fn.rs
new file mode 100644 (file)
index 0000000..05ce3ee
--- /dev/null
@@ -0,0 +1,11 @@
+// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+extern fn main() {} //~ ERROR: main function expects type
index 136cc2b8680bcffed41c8547d132538b4c449a01..09d5765a80f3f67c9b2a329b26c6e72abc8ef5a3 100644 (file)
@@ -9,5 +9,5 @@
 // except according to those terms.
 
 fn main() -> char {
-//~^ ERROR Wrong type in main function: found `extern "Rust" fn() -> char`
+//~^ ERROR: main function expects type
 }
index f3ecac3f406bd869e573d9530d0de02f5396096e..ae990880523f945f7366827b331ac8d6dfd68008 100644 (file)
@@ -14,5 +14,5 @@ struct S {
 }
 
 fn main(foo: S) {
-//~^ ERROR Wrong type in main function: found `extern "Rust" fn(S)`
+//~^ ERROR: main function expects type
 }