Skip to content

Commit 88cb454

Browse files
committed
auto merge of #17160 : nick29581/rust/front, r=pcwalton
r?
2 parents ff613ab + 3a01d0f commit 88cb454

File tree

13 files changed

+189
-164
lines changed

13 files changed

+189
-164
lines changed

src/librustc/driver/driver.rs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use back::link;
1313
use back::write;
1414
use driver::session::Session;
1515
use driver::config;
16-
use front;
1716
use lint;
1817
use llvm::{ContextRef, ModuleRef};
1918
use metadata::common::LinkMeta;
@@ -166,7 +165,7 @@ pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
166165
}
167166

168167
if sess.show_span() {
169-
front::show_span::run(sess, &krate);
168+
syntax::show_span::run(sess.diagnostic(), &krate);
170169
}
171170

172171
krate
@@ -194,11 +193,29 @@ pub fn phase_2_configure_and_expand(sess: &Session,
194193
*sess.crate_metadata.borrow_mut() =
195194
collect_crate_metadata(sess, krate.attrs.as_slice());
196195

197-
time(time_passes, "gated feature checking", (), |_|
198-
front::feature_gate::check_crate(sess, &krate));
196+
time(time_passes, "gated feature checking", (), |_| {
197+
let (features, unknown_features) =
198+
syntax::feature_gate::check_crate(&sess.parse_sess.span_diagnostic, &krate);
199+
200+
for uf in unknown_features.iter() {
201+
sess.add_lint(lint::builtin::UNKNOWN_FEATURES,
202+
ast::CRATE_NODE_ID,
203+
*uf,
204+
"unknown feature".to_string());
205+
}
206+
207+
sess.abort_if_errors();
208+
*sess.features.borrow_mut() = features;
209+
});
210+
211+
let any_exe = sess.crate_types.borrow().iter().any(|ty| {
212+
*ty == config::CrateTypeExecutable
213+
});
199214

200215
krate = time(time_passes, "crate injection", krate, |krate|
201-
front::std_inject::maybe_inject_crates_ref(sess, krate));
216+
syntax::std_inject::maybe_inject_crates_ref(krate,
217+
sess.opts.alt_std_name.clone(),
218+
any_exe));
202219

203220
// strip before expansion to allow macros to depend on
204221
// configuration variables e.g/ in
@@ -209,7 +226,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
209226
// baz! should not use this definition unless foo is enabled.
210227

211228
krate = time(time_passes, "configuration 1", krate, |krate|
212-
front::config::strip_unconfigured_items(krate));
229+
syntax::config::strip_unconfigured_items(krate));
213230

214231
let mut addl_plugins = Some(addl_plugins);
215232
let Plugins { macros, registrars }
@@ -219,7 +236,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
219236
let mut registry = Registry::new(&krate);
220237

221238
time(time_passes, "plugin registration", (), |_| {
222-
if sess.features.rustc_diagnostic_macros.get() {
239+
if sess.features.borrow().rustc_diagnostic_macros {
223240
registry.register_macro("__diagnostic_used",
224241
diagnostics::plugin::expand_diagnostic_used);
225242
registry.register_macro("__register_diagnostic",
@@ -271,7 +288,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
271288
os::setenv("PATH", os::join_paths(new_path.as_slice()).unwrap());
272289
}
273290
let cfg = syntax::ext::expand::ExpansionConfig {
274-
deriving_hash_type_parameter: sess.features.default_type_params.get(),
291+
deriving_hash_type_parameter: sess.features.borrow().default_type_params,
275292
crate_name: crate_name.to_string(),
276293
};
277294
let ret = syntax::ext::expand::expand_crate(&sess.parse_sess,
@@ -290,13 +307,16 @@ pub fn phase_2_configure_and_expand(sess: &Session,
290307

291308
// strip again, in case expansion added anything with a #[cfg].
292309
krate = time(time_passes, "configuration 2", krate, |krate|
293-
front::config::strip_unconfigured_items(krate));
310+
syntax::config::strip_unconfigured_items(krate));
294311

295312
krate = time(time_passes, "maybe building test harness", krate, |krate|
296-
front::test::modify_for_testing(sess, krate));
313+
syntax::test::modify_for_testing(&sess.parse_sess,
314+
&sess.opts.cfg,
315+
krate,
316+
sess.diagnostic()));
297317

298318
krate = time(time_passes, "prelude injection", krate, |krate|
299-
front::std_inject::maybe_inject_prelude(sess, krate));
319+
syntax::std_inject::maybe_inject_prelude(krate));
300320

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

src/librustc/driver/session.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
use driver::config;
1313
use driver::driver;
14-
use front;
1514
use metadata::cstore::CStore;
1615
use metadata::filesearch;
1716
use lint;
@@ -21,6 +20,7 @@ use syntax::ast::NodeId;
2120
use syntax::codemap::Span;
2221
use syntax::diagnostic;
2322
use syntax::diagnostics;
23+
use syntax::feature_gate;
2424
use syntax::parse;
2525
use syntax::parse::token;
2626
use syntax::parse::ParseSess;
@@ -47,10 +47,9 @@ pub struct Session {
4747
pub working_dir: Path,
4848
pub lint_store: RefCell<lint::LintStore>,
4949
pub lints: RefCell<NodeMap<Vec<(lint::LintId, codemap::Span, String)>>>,
50-
pub node_id: Cell<ast::NodeId>,
5150
pub crate_types: RefCell<Vec<config::CrateType>>,
5251
pub crate_metadata: RefCell<Vec<String>>,
53-
pub features: front::feature_gate::Features,
52+
pub features: RefCell<feature_gate::Features>,
5453

5554
/// The maximum recursion limit for potentially infinitely recursive
5655
/// operations such as auto-dereference and monomorphization.
@@ -129,17 +128,10 @@ impl Session {
129128
lints.insert(id, vec!((lint_id, sp, msg)));
130129
}
131130
pub fn next_node_id(&self) -> ast::NodeId {
132-
self.reserve_node_ids(1)
131+
self.parse_sess.next_node_id()
133132
}
134133
pub fn reserve_node_ids(&self, count: ast::NodeId) -> ast::NodeId {
135-
let v = self.node_id.get();
136-
137-
match v.checked_add(&count) {
138-
Some(next) => { self.node_id.set(next); }
139-
None => self.bug("Input too large, ran out of node ids!")
140-
}
141-
142-
v
134+
self.parse_sess.reserve_node_ids(count)
143135
}
144136
pub fn diagnostic<'a>(&'a self) -> &'a diagnostic::SpanHandler {
145137
&self.parse_sess.span_diagnostic
@@ -251,10 +243,9 @@ pub fn build_session_(sopts: config::Options,
251243
working_dir: os::getcwd(),
252244
lint_store: RefCell::new(lint::LintStore::new()),
253245
lints: RefCell::new(NodeMap::new()),
254-
node_id: Cell::new(1),
255246
crate_types: RefCell::new(Vec::new()),
256247
crate_metadata: RefCell::new(Vec::new()),
257-
features: front::feature_gate::Features::new(),
248+
features: RefCell::new(feature_gate::Features::new()),
258249
recursion_limit: Cell::new(64),
259250
};
260251

src/librustc/lib.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,6 @@ pub mod middle {
116116
pub mod weak_lang_items;
117117
}
118118

119-
pub mod front {
120-
pub mod config;
121-
pub mod test;
122-
pub mod std_inject;
123-
pub mod feature_gate;
124-
pub mod show_span;
125-
}
126-
127119
pub mod metadata;
128120

129121
pub mod driver;

src/librustc/middle/resolve.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2811,7 +2811,7 @@ impl<'a> Resolver<'a> {
28112811
import_span: Span,
28122812
name: Name,
28132813
namespace: Namespace) {
2814-
if self.session.features.import_shadowing.get() {
2814+
if self.session.features.borrow().import_shadowing {
28152815
return
28162816
}
28172817

@@ -2837,7 +2837,7 @@ impl<'a> Resolver<'a> {
28372837
&mut ImportResolution,
28382838
import_span: Span,
28392839
name: Name) {
2840-
if self.session.features.import_shadowing.get() {
2840+
if self.session.features.borrow().import_shadowing {
28412841
return
28422842
}
28432843

@@ -2919,7 +2919,7 @@ impl<'a> Resolver<'a> {
29192919
module: &Module,
29202920
name: Name,
29212921
span: Span) {
2922-
if self.session.features.import_shadowing.get() {
2922+
if self.session.features.borrow().import_shadowing {
29232923
return
29242924
}
29252925

@@ -2937,7 +2937,7 @@ impl<'a> Resolver<'a> {
29372937
module: &Module,
29382938
name: Name,
29392939
span: Span) {
2940-
if self.session.features.import_shadowing.get() {
2940+
if self.session.features.borrow().import_shadowing {
29412941
return
29422942
}
29432943

src/librustc/middle/typeck/astconv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ fn ast_path_substs<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
235235
}
236236

237237
if supplied_ty_param_count > required_ty_param_count
238-
&& !this.tcx().sess.features.default_type_params.get() {
238+
&& !this.tcx().sess.features.borrow().default_type_params {
239239
span_err!(this.tcx().sess, path.span, E0108,
240240
"default type parameters are experimental and possibly buggy");
241241
span_note!(this.tcx().sess, path.span,

src/librustc/middle/typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2131,7 +2131,7 @@ fn try_overloaded_call(fcx: &FnCtxt,
21312131
fcx.inh.method_map.borrow_mut().insert(method_call, method_callee);
21322132
write_call(fcx, call_expression, output_type);
21332133

2134-
if !fcx.tcx().sess.features.overloaded_calls.get() {
2134+
if !fcx.tcx().sess.features.borrow().overloaded_calls {
21352135
span_err!(fcx.tcx().sess, call_expression.span, E0056,
21362136
"overloaded calls are experimental");
21372137
span_note!(fcx.tcx().sess, call_expression.span,

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

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

11-
use syntax::fold::Folder;
12-
use syntax::{ast, fold, attr};
13-
use syntax::codemap::Spanned;
14-
use syntax::ptr::P;
11+
use fold::Folder;
12+
use {ast, fold, attr};
13+
use codemap::Spanned;
14+
use ptr::P;
1515

1616
/// A folder that strips out items that do not belong in the current
1717
/// configuration.

0 commit comments

Comments
 (0)