Skip to content

Commit a9a181d

Browse files
committed
driver: factor out continue_parse_after_error so it can be controlled via driver API
1 parent 8d8876c commit a9a181d

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

src/librustc_driver/driver.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub fn compile_input(sess: &Session,
8989
// large chunks of memory alive and we want to free them as soon as
9090
// possible to keep the peak memory usage low
9191
let (outputs, trans) = {
92-
let krate = match phase_1_parse_input(sess, input) {
92+
let krate = match phase_1_parse_input(control, sess, input) {
9393
Ok(krate) => krate,
9494
Err(mut parse_error) => {
9595
parse_error.emit();
@@ -296,9 +296,13 @@ pub struct CompileController<'a> {
296296
pub after_llvm: PhaseController<'a>,
297297
pub compilation_done: PhaseController<'a>,
298298

299+
// FIXME we probably want to group the below options together and offer a
300+
// better API, rather than this ad-hoc approach.
299301
pub make_glob_map: MakeGlobMap,
300302
// Whether the compiler should keep the ast beyond parsing.
301303
pub keep_ast: bool,
304+
// -Zcontinue-parse-after-error
305+
pub continue_parse_after_error: bool,
302306
}
303307

304308
impl<'a> CompileController<'a> {
@@ -312,6 +316,7 @@ impl<'a> CompileController<'a> {
312316
compilation_done: PhaseController::basic(),
313317
make_glob_map: MakeGlobMap::No,
314318
keep_ast: false,
319+
continue_parse_after_error: false,
315320
}
316321
}
317322
}
@@ -484,20 +489,22 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
484489
}
485490

486491
fn state_when_compilation_done(input: &'a Input,
487-
session: &'tcx Session,
488-
out_dir: &'a Option<PathBuf>,
489-
out_file: &'a Option<PathBuf>)
490-
-> Self {
492+
session: &'tcx Session,
493+
out_dir: &'a Option<PathBuf>,
494+
out_file: &'a Option<PathBuf>)
495+
-> Self {
491496
CompileState {
492497
out_file: out_file.as_ref().map(|s| &**s),
493498
..CompileState::empty(input, session, out_dir)
494499
}
495500
}
496501
}
497502

498-
pub fn phase_1_parse_input<'a>(sess: &'a Session, input: &Input) -> PResult<'a, ast::Crate> {
499-
let continue_after_error = sess.opts.debugging_opts.continue_parse_after_error;
500-
sess.diagnostic().set_continue_after_error(continue_after_error);
503+
pub fn phase_1_parse_input<'a>(control: &CompileController,
504+
sess: &'a Session,
505+
input: &Input)
506+
-> PResult<'a, ast::Crate> {
507+
sess.diagnostic().set_continue_after_error(control.continue_parse_after_error);
501508

502509
let krate = time(sess.time_passes(), "parsing", || {
503510
match *input {

src/librustc_driver/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
519519
let mut control = CompileController::basic();
520520

521521
control.keep_ast = sess.opts.debugging_opts.keep_ast;
522+
control.continue_parse_after_error = sess.opts.debugging_opts.continue_parse_after_error;
522523

523524
if let Some((ppm, opt_uii)) = parse_pretty(sess, matches) {
524525
if ppm.needs_ast_map(&opt_uii) {

src/librustc_driver/test.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ fn test_env<F>(source_string: &str,
119119
name: driver::anon_src(),
120120
input: source_string.to_string(),
121121
};
122-
let krate = driver::phase_1_parse_input(&sess, &input).unwrap();
122+
let krate = driver::phase_1_parse_input(&driver::CompileController::basic(),
123+
&sess,
124+
&input).unwrap();
123125
let driver::ExpansionResult { defs, resolutions, mut hir_forest, .. } = {
124126
driver::phase_2_configure_and_expand(&sess,
125127
&cstore,

src/librustdoc/core.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ pub fn run_core(search_paths: SearchPaths,
155155
target_features::add_configuration(&mut cfg, &sess);
156156
sess.parse_sess.config = cfg;
157157

158-
let krate = panictry!(driver::phase_1_parse_input(&sess, &input));
158+
let krate = panictry!(driver::phase_1_parse_input(&driver::CompileController::basic(),
159+
&sess,
160+
&input));
159161

160162
let name = link::find_crate_name(Some(&sess), &krate.attrs, &input);
161163

src/librustdoc/test.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ pub fn run(input: &str,
9191
sess.parse_sess.config =
9292
config::build_configuration(&sess, config::parse_cfgspecs(cfgs.clone()));
9393

94-
let krate = panictry!(driver::phase_1_parse_input(&sess, &input));
94+
let krate = panictry!(driver::phase_1_parse_input(&driver::CompileController::basic(),
95+
&sess,
96+
&input));
9597
let driver::ExpansionResult { defs, mut hir_forest, .. } = {
9698
phase_2_configure_and_expand(
9799
&sess, &cstore, krate, None, "rustdoc-test", None, MakeGlobMap::No, |_| Ok(())

0 commit comments

Comments
 (0)