From b59fbfdbe1c31768ca12a0f899e6db74396e9ba5 Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 19 Dec 2017 01:54:00 +0000 Subject: [PATCH] Move source-output conflict checking into `compile_input` --- src/librustc_driver/driver.rs | 15 +++++++++++++++ src/librustc_driver/lib.rs | 15 +-------------- src/librustdoc/test.rs | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 9e5de8d54e9..a288ff6316f 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -71,6 +71,7 @@ use profile; pub fn compile_input(sess: &Session, cstore: &CStore, + input_path: &Option, input: &Input, outdir: &Option, output: &Option, @@ -142,6 +143,20 @@ pub fn compile_input(sess: &Session, }; let outputs = build_output_filenames(input, outdir, output, &krate.attrs, sess); + + // Ensure the source file isn't accidentally overwritten during compilation. + match *input_path { + Some(ref input_path) => { + if outputs.contains_path(input_path) && sess.opts.will_create_output_file() { + sess.err(&format!( + "the input file \"{}\" would be overwritten by the generated executable", + input_path.display())); + return Err(CompileIncomplete::Stopped); + } + }, + None => {} + } + let crate_name = ::rustc_trans_utils::link::find_crate_name(Some(sess), &krate.attrs, input); let ExpansionResult { expanded_crate, defs, analysis, resolutions, mut hir_forest } = { diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 2bc0b39dd0d..60857505c7a 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -237,20 +237,6 @@ pub fn run_compiler<'a>(args: &[String], rustc_trans::init(&sess); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); - // Ensure the source file isn't accidentally overwritten during compilation. - match input_file_path { - Some(input_file_path) => { - if driver::build_output_filenames(&input, &odir, &ofile, &[], &sess) - .contains_path(&input_file_path) && sess.opts.will_create_output_file() { - sess.err(&format!( - "the input file \"{}\" would be overwritten by the generated executable", - input_file_path.display())); - return (Err(CompileIncomplete::Stopped), Some(sess)); - } - }, - None => {} - } - let mut cfg = config::build_configuration(&sess, cfg); target_features::add_configuration(&mut cfg, &sess); sess.parse_sess.config = cfg; @@ -266,6 +252,7 @@ pub fn run_compiler<'a>(args: &[String], let control = callbacks.build_controller(&sess, &matches); (driver::compile_input(&sess, &cstore, + &input_file_path, &input, &odir, &ofile, diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index abb90200370..06d00dec626 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -263,7 +263,7 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, cfgs: Vec, } let res = panic::catch_unwind(AssertUnwindSafe(|| { - driver::compile_input(&sess, &cstore, &input, &out, &None, None, &control) + driver::compile_input(&sess, &cstore, &None, &input, &out, &None, None, &control) })); let compile_result = match res {