mozilla/rust — pull request #13110 by derwolfe (2014-03-24 00:26:42+00:00)
Title: Check if out-dir exists before compiling / issue #12865

Compilation can fail if the supplied `out-dir` or `-o` contain paths that do not exist.
The error provided from rust is currently unclear:

```bash
$ echo 'fn main() {}' | rustc - -o foo/bar/baz
error: error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug.
note: we would appreciate a bug report: http://static.rust-lang.org/doc/master/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
task 'rustc' failed at 'called `Option::unwrap()` on a `None` value', /Users/acrichton/code/rust2/src/libstd/option.rs:264
```

The solution is to check if the paths exist before compilation occurs. If a supplied path contains non-existent directories, then compilation will fail with one of two errors:

if `out-dir` contains a non-existent path:
```bash
$ echo 'fn main() {}' | ./rustc - --out-dir foo/
error: output directory does not exist
```

if `-o` contains a non-existent path
```bash
$ echo 'fn main() {}' | ./rustc - -o foo/bar/baz
error: output directory does not exist, file cannot be created
```