Move source-output conflict checking into compile_input

This commit is contained in:
varkor 2017-12-19 01:54:00 +00:00
parent c76cdce3d9
commit b59fbfdbe1
3 changed files with 17 additions and 15 deletions

View File

@ -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 } = {

View File

@ -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,

View File

@ -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 {