Skip to content

Commit 85b084f

Browse files
committed
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
1 parent 00211ec commit 85b084f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/librustc/session/search_paths.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use std::slice;
1212
use std::path::{Path, PathBuf};
13+
use session::early_error;
1314

1415
#[derive(Clone, Debug)]
1516
pub struct SearchPaths {
@@ -50,6 +51,9 @@ impl SearchPaths {
5051
} else {
5152
(PathKind::All, path)
5253
};
54+
if path.is_empty() {
55+
early_error("empty search path given via `-L`");
56+
}
5357
self.paths.push((kind, PathBuf::new(path)));
5458
}
5559

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2015 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+
// compile-flags:-L native=
12+
// error-pattern: empty search path given via `-L`
13+
14+
fn main() {
15+
}

0 commit comments

Comments
 (0)