rustc: Switch the --no-core switch to a #[no_core] attribute

This commit is contained in:
Brian Anderson 2012-01-26 16:23:34 -08:00
parent 2220d0f20f
commit 28fbb19664
8 changed files with 23 additions and 12 deletions

View file

@ -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};

View file

@ -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

View file

@ -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,

View file

@ -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)
}

View file

@ -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 {

View file

@ -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;

View file

@ -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,

View file

@ -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);
}