Skip to content

Commit 28fbb19

Browse files
committed
rustc: Switch the --no-core switch to a #[no_core] attribute
1 parent 2220d0f commit 28fbb19

File tree

8 files changed

+23
-12
lines changed

8 files changed

+23
-12
lines changed

src/comp/driver/driver.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,6 @@ fn build_session_options(match: getopts::match,
366366
} else if opt_present(match, "emit-llvm") {
367367
link::output_type_bitcode
368368
} else { link::output_type_exe };
369-
let libcore = !opt_present(match, "no-core");
370369
let verify = !opt_present(match, "no-verify");
371370
let save_temps = opt_present(match, "save-temps");
372371
let extra_debuginfo = opt_present(match, "xg");
@@ -414,7 +413,6 @@ fn build_session_options(match: getopts::match,
414413
let sopts: @session::options =
415414
@{crate_type: crate_type,
416415
static: static,
417-
libcore: libcore,
418416
optimize: opt_level,
419417
debuginfo: debuginfo,
420418
extra_debuginfo: extra_debuginfo,
@@ -494,10 +492,11 @@ fn opts() -> [getopts::opt] {
494492
optflag("no-verify"),
495493
optflag("no-lint-ctypes"),
496494
optmulti("cfg"), optflag("test"),
497-
optflag("no-core"),
498495
optflag("lib"), optflag("bin"), optflag("static"), optflag("gc"),
499496
optflag("no-asm-comments"),
500-
optflag("warn-unused-imports")];
497+
optflag("warn-unused-imports"),
498+
// FIXME: Transitional. Please remove
499+
optflag("no-core")];
501500
}
502501

503502
type output_filenames = @{out_filename: str, obj_filename:str};

src/comp/driver/rustc.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ options:
3333
--lib compile a library crate
3434
--bin compile an executable crate (default)
3535
--static use or produce static libraries
36-
--no-core omit the 'core' library (used and imported by default)
3736
--pretty [type] pretty-print the input instead of compiling
3837
--ls list the symbols defined by a crate file
3938
-L <path> add a directory to the library search path

src/comp/driver/session.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ type options =
2929
// with additional crate configurations during the compile process
3030
{crate_type: crate_type,
3131
static: bool,
32-
libcore: bool,
3332
optimize: uint,
3433
debuginfo: bool,
3534
extra_debuginfo: bool,

src/comp/front/attr.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export attr_meta;
99
export attr_metas;
1010
export find_linkage_metas;
1111
export find_attrs_by_name;
12+
export attrs_contains_name;
1213
export find_meta_items_by_name;
1314
export contains;
1415
export contains_name;
@@ -56,6 +57,10 @@ fn find_attrs_by_name(attrs: [ast::attribute], name: ast::ident) ->
5657
ret vec::filter_map(attrs, filter);
5758
}
5859

60+
fn attrs_contains_name(attrs: [ast::attribute], name: ast::ident) -> bool {
61+
vec::is_not_empty(find_attrs_by_name(attrs, name))
62+
}
63+
5964
fn get_attr_name(attr: ast::attribute) -> ast::ident {
6065
get_meta_item_name(@attr.node.value)
6166
}

src/comp/front/core_inject.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
import driver::session::session;
2-
import syntax::ast;
32
import syntax::codemap;
3+
import syntax::ast;
4+
import front::attr;
45

56
export maybe_inject_libcore_ref;
67

78
fn maybe_inject_libcore_ref(sess: session,
89
crate: @ast::crate) -> @ast::crate {
9-
if sess.opts.libcore {
10+
if use_core(crate) {
1011
inject_libcore_ref(sess, crate)
1112
} else {
1213
crate
1314
}
1415
}
1516

17+
fn use_core(crate: @ast::crate) -> bool {
18+
!attr::attrs_contains_name(crate.node.attrs, "no_core")
19+
}
20+
1621
fn inject_libcore_ref(sess: session,
1722
crate: @ast::crate) -> @ast::crate {
1823

src/libcore/core.rc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77
#[license = "MIT"];
88
#[crate_type = "lib"];
99

10+
// Don't link to core. We are core.
11+
#[no_core];
12+
1013
#[doc(
1114
brief = "The Rust core library",
1215
desc = "
16+
1317
The core library provides functionality that is closely tied to the Rust
1418
built-in types and runtime services, or that is used in nearly every
1519
non-trivial program.
@@ -20,7 +24,8 @@ as though the user had written the following:
2024
use core;
2125
import core::*;
2226

23-
This behavior can be disabled with the `--no-core` compiler flag."
27+
This behavior can be disabled with the `no_core` crate attribute."
28+
2429
)];
2530

2631
export box, char, float, bessel, f32, f64, int, str, ptr;

src/rustdoc/astsrv.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ fn build_session() -> session::session {
6666
let sopts: @session::options = @{
6767
crate_type: session::lib_crate,
6868
static: false,
69-
libcore: false,
7069
optimize: 0u,
7170
debuginfo: false,
7271
extra_debuginfo: false,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// error-pattern: whatever
1+
// error-pattern:unresolved name: debug
22
#[no_core];
33

44
fn main() {
5-
log(debug, core::int::max_value);
5+
log(debug, 0);
66
}

0 commit comments

Comments
 (0)