about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-01-26 16:23:34 -0800
committerBrian Anderson <banderson@mozilla.com>2012-01-26 16:43:33 -0800
commit28fbb19664db24c9d40e81f74bf75ac1d5d0f36b (patch)
treef11aafd32c44b3f90c981668f6e2fe2533a0ffe0
parent2220d0f20f7faf63de3bb805fcfa0fa7a4c416ee (diff)
downloadrust-28fbb19664db24c9d40e81f74bf75ac1d5d0f36b.tar.gz
rust-28fbb19664db24c9d40e81f74bf75ac1d5d0f36b.zip
rustc: Switch the --no-core switch to a #[no_core] attribute
-rw-r--r--src/comp/driver/driver.rs7
-rw-r--r--src/comp/driver/rustc.rs1
-rw-r--r--src/comp/driver/session.rs1
-rw-r--r--src/comp/front/attr.rs5
-rw-r--r--src/comp/front/core_inject.rs9
-rw-r--r--src/libcore/core.rc7
-rw-r--r--src/rustdoc/astsrv.rs1
-rw-r--r--src/test/compile-fail/no-core-attribute.rs4
8 files changed, 23 insertions, 12 deletions
diff --git a/src/comp/driver/driver.rs b/src/comp/driver/driver.rs
index 92275d360ed..1b57c627455 100644
--- a/src/comp/driver/driver.rs
+++ b/src/comp/driver/driver.rs
@@ -366,7 +366,6 @@ fn build_session_options(match: getopts::match,
         } else if opt_present(match, "emit-llvm") {
             link::output_type_bitcode
         } else { link::output_type_exe };
-    let libcore = !opt_present(match, "no-core");
     let verify = !opt_present(match, "no-verify");
     let save_temps = opt_present(match, "save-temps");
     let extra_debuginfo = opt_present(match, "xg");
@@ -414,7 +413,6 @@ fn build_session_options(match: getopts::match,
     let sopts: @session::options =
         @{crate_type: crate_type,
           static: static,
-          libcore: libcore,
           optimize: opt_level,
           debuginfo: debuginfo,
           extra_debuginfo: extra_debuginfo,
@@ -494,10 +492,11 @@ fn opts() -> [getopts::opt] {
          optflag("no-verify"),
          optflag("no-lint-ctypes"),
          optmulti("cfg"), optflag("test"),
-         optflag("no-core"),
          optflag("lib"), optflag("bin"), optflag("static"), optflag("gc"),
          optflag("no-asm-comments"),
-         optflag("warn-unused-imports")];
+         optflag("warn-unused-imports"),
+         // FIXME: Transitional. Please remove
+         optflag("no-core")];
 }
 
 type output_filenames = @{out_filename: str, obj_filename:str};
diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs
index 4ab6b3491ad..12d10e80653 100644
--- a/src/comp/driver/rustc.rs
+++ b/src/comp/driver/rustc.rs
@@ -33,7 +33,6 @@ options:
     --lib              compile a library crate
     --bin              compile an executable crate (default)
     --static           use or produce static libraries
-    --no-core          omit the 'core' library (used and imported by default)
     --pretty [type]    pretty-print the input instead of compiling
     --ls               list the symbols defined by a crate file
     -L <path>          add a directory to the library search path
diff --git a/src/comp/driver/session.rs b/src/comp/driver/session.rs
index 31ddd3d241f..b570744a665 100644
--- a/src/comp/driver/session.rs
+++ b/src/comp/driver/session.rs
@@ -29,7 +29,6 @@ type options =
     // with additional crate configurations during the compile process
     {crate_type: crate_type,
      static: bool,
-     libcore: bool,
      optimize: uint,
      debuginfo: bool,
      extra_debuginfo: bool,
diff --git a/src/comp/front/attr.rs b/src/comp/front/attr.rs
index 75ee1e822a4..54960d65360 100644
--- a/src/comp/front/attr.rs
+++ b/src/comp/front/attr.rs
@@ -9,6 +9,7 @@ export attr_meta;
 export attr_metas;
 export find_linkage_metas;
 export find_attrs_by_name;
+export attrs_contains_name;
 export find_meta_items_by_name;
 export contains;
 export contains_name;
@@ -56,6 +57,10 @@ fn find_attrs_by_name(attrs: [ast::attribute], name: ast::ident) ->
     ret vec::filter_map(attrs, filter);
 }
 
+fn attrs_contains_name(attrs: [ast::attribute], name: ast::ident) -> bool {
+    vec::is_not_empty(find_attrs_by_name(attrs, name))
+}
+
 fn get_attr_name(attr: ast::attribute) -> ast::ident {
     get_meta_item_name(@attr.node.value)
 }
diff --git a/src/comp/front/core_inject.rs b/src/comp/front/core_inject.rs
index 8e88bd50068..f285d4bf67b 100644
--- a/src/comp/front/core_inject.rs
+++ b/src/comp/front/core_inject.rs
@@ -1,18 +1,23 @@
 import driver::session::session;
-import syntax::ast;
 import syntax::codemap;
+import syntax::ast;
+import front::attr;
 
 export maybe_inject_libcore_ref;
 
 fn maybe_inject_libcore_ref(sess: session,
                             crate: @ast::crate) -> @ast::crate {
-    if sess.opts.libcore {
+    if use_core(crate) {
         inject_libcore_ref(sess, crate)
     } else {
         crate
     }
 }
 
+fn use_core(crate: @ast::crate) -> bool {
+    !attr::attrs_contains_name(crate.node.attrs, "no_core")
+}
+
 fn inject_libcore_ref(sess: session,
                       crate: @ast::crate) -> @ast::crate {
 
diff --git a/src/libcore/core.rc b/src/libcore/core.rc
index 534aeee9ee8..b90c1c16d1a 100644
--- a/src/libcore/core.rc
+++ b/src/libcore/core.rc
@@ -7,9 +7,13 @@
 #[license = "MIT"];
 #[crate_type = "lib"];
 
+// Don't link to core. We are core.
+#[no_core];
+
 #[doc(
     brief = "The Rust core library",
     desc = "
+
 The core library provides functionality that is closely tied to the Rust
 built-in types and runtime services, or that is used in nearly every
 non-trivial program.
@@ -20,7 +24,8 @@ as though the user had written the following:
     use core;
     import core::*;
 
-This behavior can be disabled with the `--no-core` compiler flag."
+This behavior can be disabled with the `no_core` crate attribute."
+
 )];
 
 export box, char, float, bessel, f32, f64, int, str, ptr;
diff --git a/src/rustdoc/astsrv.rs b/src/rustdoc/astsrv.rs
index 769c8ea96ba..bd998b0eec0 100644
--- a/src/rustdoc/astsrv.rs
+++ b/src/rustdoc/astsrv.rs
@@ -66,7 +66,6 @@ fn build_session() -> session::session {
     let sopts: @session::options = @{
         crate_type: session::lib_crate,
         static: false,
-        libcore: false,
         optimize: 0u,
         debuginfo: false,
         extra_debuginfo: false,
diff --git a/src/test/compile-fail/no-core-attribute.rs b/src/test/compile-fail/no-core-attribute.rs
index f39aa2eff2d..7ed010476cd 100644
--- a/src/test/compile-fail/no-core-attribute.rs
+++ b/src/test/compile-fail/no-core-attribute.rs
@@ -1,6 +1,6 @@
-// error-pattern: whatever
+// error-pattern:unresolved name: debug
 #[no_core];
 
 fn main() {
-    log(debug, core::int::max_value);
+    log(debug, 0);
 }
\ No newline at end of file