about summary refs log tree commit diff
diff options
context:
space:
mode:
authorvarkor <github@varkor.com>2017-12-19 01:54:00 +0000
committervarkor <github@varkor.com>2017-12-19 01:54:00 +0000
commitb59fbfdbe1c31768ca12a0f899e6db74396e9ba5 (patch)
treee861c566084c7b8a9031069870eec73368d0ff88
parentc76cdce3d953759a53d4990af0f5fb472cbc04de (diff)
downloadrust-b59fbfdbe1c31768ca12a0f899e6db74396e9ba5.tar.gz
rust-b59fbfdbe1c31768ca12a0f899e6db74396e9ba5.zip
Move source-output conflict checking into `compile_input`
-rw-r--r--src/librustc_driver/driver.rs15
-rw-r--r--src/librustc_driver/lib.rs15
-rw-r--r--src/librustdoc/test.rs2
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<PathBuf>,
                      input: &Input,
                      outdir: &Option<PathBuf>,
                      output: &Option<PathBuf>,
@@ -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<String>,
     }
 
     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 {