Skip to content

Commit b59fbfd

Browse files
committed
Move source-output conflict checking into compile_input
1 parent c76cdce commit b59fbfd

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

src/librustc_driver/driver.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ use profile;
7171

7272
pub fn compile_input(sess: &Session,
7373
cstore: &CStore,
74+
input_path: &Option<PathBuf>,
7475
input: &Input,
7576
outdir: &Option<PathBuf>,
7677
output: &Option<PathBuf>,
@@ -142,6 +143,20 @@ pub fn compile_input(sess: &Session,
142143
};
143144

144145
let outputs = build_output_filenames(input, outdir, output, &krate.attrs, sess);
146+
147+
// Ensure the source file isn't accidentally overwritten during compilation.
148+
match *input_path {
149+
Some(ref input_path) => {
150+
if outputs.contains_path(input_path) && sess.opts.will_create_output_file() {
151+
sess.err(&format!(
152+
"the input file \"{}\" would be overwritten by the generated executable",
153+
input_path.display()));
154+
return Err(CompileIncomplete::Stopped);
155+
}
156+
},
157+
None => {}
158+
}
159+
145160
let crate_name =
146161
::rustc_trans_utils::link::find_crate_name(Some(sess), &krate.attrs, input);
147162
let ExpansionResult { expanded_crate, defs, analysis, resolutions, mut hir_forest } = {

src/librustc_driver/lib.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -237,20 +237,6 @@ pub fn run_compiler<'a>(args: &[String],
237237
rustc_trans::init(&sess);
238238
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
239239

240-
// Ensure the source file isn't accidentally overwritten during compilation.
241-
match input_file_path {
242-
Some(input_file_path) => {
243-
if driver::build_output_filenames(&input, &odir, &ofile, &[], &sess)
244-
.contains_path(&input_file_path) && sess.opts.will_create_output_file() {
245-
sess.err(&format!(
246-
"the input file \"{}\" would be overwritten by the generated executable",
247-
input_file_path.display()));
248-
return (Err(CompileIncomplete::Stopped), Some(sess));
249-
}
250-
},
251-
None => {}
252-
}
253-
254240
let mut cfg = config::build_configuration(&sess, cfg);
255241
target_features::add_configuration(&mut cfg, &sess);
256242
sess.parse_sess.config = cfg;
@@ -266,6 +252,7 @@ pub fn run_compiler<'a>(args: &[String],
266252
let control = callbacks.build_controller(&sess, &matches);
267253
(driver::compile_input(&sess,
268254
&cstore,
255+
&input_file_path,
269256
&input,
270257
&odir,
271258
&ofile,

src/librustdoc/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, cfgs: Vec<String>,
263263
}
264264

265265
let res = panic::catch_unwind(AssertUnwindSafe(|| {
266-
driver::compile_input(&sess, &cstore, &input, &out, &None, None, &control)
266+
driver::compile_input(&sess, &cstore, &None, &input, &out, &None, None, &control)
267267
}));
268268

269269
let compile_result = match res {

0 commit comments

Comments
 (0)