rustc: Move core injection to its own module
This commit is contained in:
parent
335302f08d
commit
5610205363
4 changed files with 44 additions and 24 deletions
|
@ -95,27 +95,6 @@ fn time<T>(do_it: bool, what: str, thunk: fn@() -> T) -> T {
|
|||
ret rv;
|
||||
}
|
||||
|
||||
fn inject_libcore_reference(sess: session,
|
||||
crate: @ast::crate) -> @ast::crate {
|
||||
|
||||
fn spanned<T: copy>(x: T) -> @ast::spanned<T> {
|
||||
ret @{node: x,
|
||||
span: {lo: 0u, hi: 0u,
|
||||
expanded_from: codemap::os_none}};
|
||||
}
|
||||
|
||||
let n1 = sess.next_node_id();
|
||||
let n2 = sess.next_node_id();
|
||||
|
||||
let vi1 = spanned(ast::view_item_use("core", [], n1));
|
||||
let vi2 = spanned(ast::view_item_import_glob(@["core"], n2));
|
||||
|
||||
let vis = [vi1, vi2] + crate.node.module.view_items;
|
||||
|
||||
ret @{node: {module: { view_items: vis with crate.node.module }
|
||||
with crate.node} with *crate }
|
||||
}
|
||||
|
||||
enum compile_upto {
|
||||
cu_parse,
|
||||
cu_expand,
|
||||
|
@ -147,9 +126,8 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
|
|||
bind syntax::ext::expand::expand_crate(sess, crate));
|
||||
|
||||
if upto == cu_expand { ret {crate: crate, tcx: none}; }
|
||||
if sess.opts.libcore {
|
||||
crate = inject_libcore_reference(sess, crate);
|
||||
}
|
||||
|
||||
crate = front::core_inject::maybe_inject_libcore_ref(sess, crate);
|
||||
|
||||
let ast_map =
|
||||
time(time_passes, "ast indexing",
|
||||
|
|
35
src/comp/front/core_inject.rs
Normal file
35
src/comp/front/core_inject.rs
Normal file
|
@ -0,0 +1,35 @@
|
|||
import driver::session::session;
|
||||
import syntax::ast;
|
||||
import syntax::codemap;
|
||||
|
||||
export maybe_inject_libcore_ref;
|
||||
|
||||
fn maybe_inject_libcore_ref(sess: session,
|
||||
crate: @ast::crate) -> @ast::crate {
|
||||
if sess.opts.libcore {
|
||||
inject_libcore_ref(sess, crate)
|
||||
} else {
|
||||
crate
|
||||
}
|
||||
}
|
||||
|
||||
fn inject_libcore_ref(sess: session,
|
||||
crate: @ast::crate) -> @ast::crate {
|
||||
|
||||
fn spanned<T: copy>(x: T) -> @ast::spanned<T> {
|
||||
ret @{node: x,
|
||||
span: {lo: 0u, hi: 0u,
|
||||
expanded_from: codemap::os_none}};
|
||||
}
|
||||
|
||||
let n1 = sess.next_node_id();
|
||||
let n2 = sess.next_node_id();
|
||||
|
||||
let vi1 = spanned(ast::view_item_use("core", [], n1));
|
||||
let vi2 = spanned(ast::view_item_import_glob(@["core"], n2));
|
||||
|
||||
let vis = [vi1, vi2] + crate.node.module.view_items;
|
||||
|
||||
ret @{node: {module: { view_items: vis with crate.node.module }
|
||||
with crate.node} with *crate }
|
||||
}
|
|
@ -94,6 +94,7 @@ mod front {
|
|||
mod attr;
|
||||
mod config;
|
||||
mod test;
|
||||
mod core_inject;
|
||||
}
|
||||
|
||||
mod back {
|
||||
|
|
6
src/test/compile-fail/no-core-attribute.rs
Normal file
6
src/test/compile-fail/no-core-attribute.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
// error-pattern: whatever
|
||||
#[no_core];
|
||||
|
||||
fn main() {
|
||||
log(debug, core::int::max_value);
|
||||
}
|
Loading…
Add table
Reference in a new issue