Reject -L "", -L native=, and other empty search paths.

It wasn't clear to me that early_error was correct here, but it seems to
work. This code is reachable from `rustdoc`, which is problematic, because
early_error panics. rustc handles the panics gracefully (without ICEing or
crashing), but rustdoc does not. It's not the first such rustdoc problem,
though:

    $ rustdoc hello.rs --extern std=bad-std
    error: extern location for std does not exist: bad-std
    hello.rs:1:1: 1:1 error: can't find crate for `std`
    hello.rs:1
           ^
    error: aborting due to 2 previous errors
    thread '<unnamed>' panicked at 'Box<Any>', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libsyntax/diagnostic.rs:151
    thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: "rustc failed"', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libcore/result.rs:744
    thread '<main>' panicked at 'child thread None panicked', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/thread.rs:661
This commit is contained in:
Ryan Prichard 2015-03-13 23:49:44 -07:00
parent 00211ecfda
commit 85b084f4bd
2 changed files with 19 additions and 0 deletions

View File

@ -10,6 +10,7 @@
use std::slice;
use std::path::{Path, PathBuf};
use session::early_error;
#[derive(Clone, Debug)]
pub struct SearchPaths {
@ -50,6 +51,9 @@ pub fn add_path(&mut self, path: &str) {
} else {
(PathKind::All, path)
};
if path.is_empty() {
early_error("empty search path given via `-L`");
}
self.paths.push((kind, PathBuf::new(path)));
}

View File

@ -0,0 +1,15 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-flags:-L native=
// error-pattern: empty search path given via `-L`
fn main() {
}