Skip to content

Commit c62daa6

Browse files
committed
rustc: Give a friendlier error when writing deps
When an error is encountered when writing dependencies, this presents a nicer error rather than an ICE. Closes #13517
1 parent de7845a commit c62daa6

File tree

3 files changed

+44
-19
lines changed

3 files changed

+44
-19
lines changed

src/librustc/driver/driver.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ pub fn stop_after_phase_5(sess: &Session) -> bool {
495495
fn write_out_deps(sess: &Session,
496496
input: &Input,
497497
outputs: &OutputFilenames,
498-
krate: &ast::Crate) -> io::IoResult<()> {
498+
krate: &ast::Crate) {
499499
let id = link::find_crate_id(krate.attrs.as_slice(), outputs.out_filestem);
500500

501501
let mut out_filenames = Vec::new();
@@ -524,28 +524,34 @@ fn write_out_deps(sess: &Session,
524524
StrInput(..) => {
525525
sess.warn("can not write --dep-info without a filename \
526526
when compiling stdin.");
527-
return Ok(());
527+
return
528528
},
529529
},
530-
_ => return Ok(()),
530+
_ => return,
531531
};
532532

533-
// Build a list of files used to compile the output and
534-
// write Makefile-compatible dependency rules
535-
let files: Vec<~str> = sess.codemap().files.borrow()
536-
.iter().filter_map(|fmap| {
537-
if fmap.is_real_file() {
538-
Some(fmap.name.clone())
539-
} else {
540-
None
541-
}
542-
}).collect();
543-
let mut file = try!(io::File::create(&deps_filename));
544-
for path in out_filenames.iter() {
545-
try!(write!(&mut file as &mut Writer,
546-
"{}: {}\n\n", path.display(), files.connect(" ")));
533+
let result = (|| {
534+
// Build a list of files used to compile the output and
535+
// write Makefile-compatible dependency rules
536+
let files: Vec<~str> = sess.codemap().files.borrow()
537+
.iter().filter(|fmap| fmap.is_real_file())
538+
.map(|fmap| fmap.name.clone())
539+
.collect();
540+
let mut file = try!(io::File::create(&deps_filename));
541+
for path in out_filenames.iter() {
542+
try!(write!(&mut file as &mut Writer,
543+
"{}: {}\n\n", path.display(), files.connect(" ")));
544+
}
545+
Ok(())
546+
})();
547+
548+
match result {
549+
Ok(()) => {}
550+
Err(e) => {
551+
sess.fatal(format!("error writing dependencies to `{}`: {}",
552+
deps_filename.display(), e));
553+
}
547554
}
548-
Ok(())
549555
}
550556

551557
pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &Input,
@@ -569,7 +575,7 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &Input,
569575
krate, &id);
570576
(outputs, expanded_crate, ast_map)
571577
};
572-
write_out_deps(&sess, input, &outputs, &expanded_crate).unwrap();
578+
write_out_deps(&sess, input, &outputs, &expanded_crate);
573579

574580
if stop_after_phase_2(&sess) { return; }
575581

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-include ../tools.mk
2+
3+
all:
4+
# Let's get a nice error message
5+
$(RUSTC) foo.rs --dep-info foo/bar/baz 2>&1 | \
6+
grep "error writing dependencies"
7+
# Make sure the filename shows up
8+
$(RUSTC) foo.rs --dep-info foo/bar/baz 2>&1 | grep "baz"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {}

0 commit comments

Comments
 (0)