Skip to content

Commit 375c95b

Browse files
committed
move std_inject to libsyntax
1 parent 520671f commit 375c95b

File tree

4 files changed

+35
-31
lines changed

4 files changed

+35
-31
lines changed

src/librustc/driver/driver.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,14 @@ pub fn phase_2_configure_and_expand(sess: &Session,
197197
time(time_passes, "gated feature checking", (), |_|
198198
front::feature_gate::check_crate(sess, &krate));
199199

200+
let any_exe = sess.crate_types.borrow().iter().any(|ty| {
201+
*ty == config::CrateTypeExecutable
202+
});
203+
200204
krate = time(time_passes, "crate injection", krate, |krate|
201-
front::std_inject::maybe_inject_crates_ref(sess, krate));
205+
syntax::std_inject::maybe_inject_crates_ref(krate,
206+
sess.opts.alt_std_name.clone(),
207+
any_exe));
202208

203209
// strip before expansion to allow macros to depend on
204210
// configuration variables e.g/ in
@@ -299,7 +305,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
299305
sess.diagnostic()));
300306

301307
krate = time(time_passes, "prelude injection", krate, |krate|
302-
front::std_inject::maybe_inject_prelude(sess, krate));
308+
syntax::std_inject::maybe_inject_prelude(krate));
303309

304310
time(time_passes, "checking that all macro invocations are gone", &krate, |krate|
305311
syntax::ext::expand::check_for_macros(&sess.parse_sess, krate));

src/librustc/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ pub mod middle {
117117
}
118118

119119
pub mod front {
120-
pub mod std_inject;
121120
pub mod feature_gate;
122121
}
123122

src/libsyntax/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ pub mod owned_slice;
6767
pub mod parse;
6868
pub mod ptr;
6969
pub mod show_span;
70+
pub mod std_inject;
7071
pub mod test;
7172
pub mod visit;
7273

src/librustc/front/std_inject.rs renamed to src/libsyntax/std_inject.rs

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,33 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use driver::config;
12-
use driver::session::Session;
13-
14-
use syntax::ast;
15-
use syntax::attr;
16-
use syntax::codemap::DUMMY_SP;
17-
use syntax::codemap;
18-
use syntax::fold::Folder;
19-
use syntax::fold;
20-
use syntax::owned_slice::OwnedSlice;
21-
use syntax::parse::token::InternedString;
22-
use syntax::parse::token::special_idents;
23-
use syntax::parse::token;
24-
use syntax::ptr::P;
25-
use syntax::util::small_vector::SmallVector;
11+
use ast;
12+
use attr;
13+
use codemap::DUMMY_SP;
14+
use codemap;
15+
use fold::Folder;
16+
use fold;
17+
use owned_slice::OwnedSlice;
18+
use parse::token::InternedString;
19+
use parse::token::special_idents;
20+
use parse::token;
21+
use ptr::P;
22+
use util::small_vector::SmallVector;
2623

2724
use std::mem;
2825

29-
pub fn maybe_inject_crates_ref(sess: &Session, krate: ast::Crate)
26+
pub fn maybe_inject_crates_ref(krate: ast::Crate, alt_std_name: Option<String>, any_exe: bool)
3027
-> ast::Crate {
3128
if use_std(&krate) {
32-
inject_crates_ref(sess, krate)
29+
inject_crates_ref(krate, alt_std_name, any_exe)
3330
} else {
3431
krate
3532
}
3633
}
3734

38-
pub fn maybe_inject_prelude(sess: &Session, krate: ast::Crate) -> ast::Crate {
35+
pub fn maybe_inject_prelude(krate: ast::Crate) -> ast::Crate {
3936
if use_std(&krate) {
40-
inject_prelude(sess, krate)
37+
inject_prelude(krate)
4138
} else {
4239
krate
4340
}
@@ -56,14 +53,15 @@ fn no_prelude(attrs: &[ast::Attribute]) -> bool {
5653
}
5754

5855
struct StandardLibraryInjector<'a> {
59-
sess: &'a Session,
56+
alt_std_name: Option<String>,
57+
any_exe: bool,
6058
}
6159

6260
impl<'a> fold::Folder for StandardLibraryInjector<'a> {
6361
fn fold_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
6462

6563
// The name to use in `extern crate "name" as std;`
66-
let actual_crate_name = match self.sess.opts.alt_std_name {
64+
let actual_crate_name = match self.alt_std_name {
6765
Some(ref s) => token::intern_and_get_ident(s.as_slice()),
6866
None => token::intern_and_get_ident("std"),
6967
};
@@ -83,10 +81,7 @@ impl<'a> fold::Folder for StandardLibraryInjector<'a> {
8381
span: DUMMY_SP
8482
});
8583

86-
let any_exe = self.sess.crate_types.borrow().iter().any(|ty| {
87-
*ty == config::CrateTypeExecutable
88-
});
89-
if use_start(&krate) && any_exe {
84+
if use_start(&krate) && self.any_exe {
9085
let visible_rt_name = "rt";
9186
let actual_rt_name = "native";
9287
// Gensym the ident so it can't be named
@@ -124,9 +119,12 @@ impl<'a> fold::Folder for StandardLibraryInjector<'a> {
124119
}
125120
}
126121

127-
fn inject_crates_ref(sess: &Session, krate: ast::Crate) -> ast::Crate {
122+
fn inject_crates_ref(krate: ast::Crate,
123+
alt_std_name: Option<String>,
124+
any_exe: bool) -> ast::Crate {
128125
let mut fold = StandardLibraryInjector {
129-
sess: sess,
126+
alt_std_name: alt_std_name,
127+
any_exe: any_exe,
130128
};
131129
fold.fold_crate(krate)
132130
}
@@ -231,7 +229,7 @@ impl<'a> fold::Folder for PreludeInjector<'a> {
231229
}
232230
}
233231

234-
fn inject_prelude(_: &Session, krate: ast::Crate) -> ast::Crate {
232+
fn inject_prelude(krate: ast::Crate) -> ast::Crate {
235233
let mut fold = PreludeInjector;
236234
fold.fold_crate(krate)
237235
}

0 commit comments

Comments
 (0)