Skip to content

Commit 8f488ac

Browse files
committed
Add more info to an ICE message.
The new ICE message will look like $ rustc -O /tmp/nodakai/ice.rs error: internal compiler error: unexpected panic note: the compiler unexpectedly panicked. this is a bug. note: we would appreciate a bug report: note: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports note: version: 1.9.0-dev (1437edb98 2016-03-22) note: host: x86_64-unknown-linux-gnu note: arguments: ["rustc", "-O", "/tmp/nodakai/ice.rs"] note: run with `RUST_BACKTRACE=1` for a backtrace thread 'rustc' panicked at 'impossible range in AST', src/librustc_front/lowering.rs:1292 note: Run with `RUST_BACKTRACE=1` for a backtrace. Signed-off-by: NODA, Kai <[email protected]>
1 parent 98f0a91 commit 8f488ac

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

src/librustc_driver/lib.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ pub fn abort_on_err<T>(result: Result<T, usize>, sess: &Session) -> T {
127127
}
128128

129129
pub fn run(args: Vec<String>) -> isize {
130-
monitor(move || {
130+
// args is moved to a child thread (cfg.spawn()) whose lifetime is unknown to Rust
131+
monitor(&args.clone(), move || {
131132
let (result, session) = run_compiler(&args, &mut RustcDefaultCalls);
132133
if let Err(err_count) = result {
133134
if err_count > 0 {
@@ -614,7 +615,11 @@ impl RustcDefaultCalls {
614615
}
615616
}
616617

617-
/// Returns a version string such as "0.12.0-dev".
618+
// These three functions were originally intended to provide some reflectional
619+
// information on the compiler version, but they are no longer very useful since
620+
// librustc_driver was market as "private",
621+
622+
/// Returns a version string such as "1.9.0-dev".
618623
pub fn release_str() -> Option<&'static str> {
619624
option_env!("CFG_RELEASE")
620625
}
@@ -1010,7 +1015,7 @@ fn parse_crate_attrs<'a>(sess: &'a Session, input: &Input) -> PResult<'a, Vec<as
10101015
///
10111016
/// The diagnostic emitter yielded to the procedure should be used for reporting
10121017
/// errors of the compiler.
1013-
pub fn monitor<F: FnOnce() + Send + 'static>(f: F) {
1018+
pub fn monitor<F: FnOnce() + Send + 'static>(args: &[String], f: F) {
10141019
const STACK_SIZE: usize = 8 * 1024 * 1024; // 8MB
10151020

10161021
struct Sink(Arc<Mutex<Vec<u8>>>);
@@ -1050,8 +1055,12 @@ pub fn monitor<F: FnOnce() + Send + 'static>(f: F) {
10501055
emitter.emit(None, "unexpected panic", None, errors::Level::Bug);
10511056
}
10521057

1053-
let xs = ["the compiler unexpectedly panicked. this is a bug.".to_string(),
1054-
format!("we would appreciate a bug report: {}", BUG_REPORT_URL)];
1058+
let xs = [format!("the compiler unexpectedly panicked. this is a bug."),
1059+
format!("we would appreciate a bug report:"),
1060+
format!(" {}", BUG_REPORT_URL),
1061+
format!("version: {}", option_env!("CFG_VERSION").unwrap_or("unknown")),
1062+
format!("host: {}", config::host_triple()),
1063+
format!("arguments: {:?}", args)];
10551064
for note in &xs {
10561065
emitter.emit(None, &note[..], None, errors::Level::Note)
10571066
}

src/librustdoc/lib.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ pub fn main_args(args: &[String]) -> isize {
277277
!matches.opt_present("markdown-no-toc")),
278278
(false, false) => {}
279279
}
280-
let out = match acquire_input(input, externs, &matches) {
280+
let out = match acquire_input(input, externs, &matches, args) {
281281
Ok(out) => out,
282282
Err(s) => {
283283
println!("input error: {}", s);
@@ -311,16 +311,17 @@ pub fn main_args(args: &[String]) -> isize {
311311
/// and files and then generates the necessary rustdoc output for formatting.
312312
fn acquire_input(input: &str,
313313
externs: core::Externs,
314-
matches: &getopts::Matches) -> Result<Output, String> {
314+
matches: &getopts::Matches,
315+
cmdline_args: &[String]) -> Result<Output, String> {
315316
match matches.opt_str("r").as_ref().map(|s| &**s) {
316-
Some("rust") => Ok(rust_input(input, externs, matches)),
317+
Some("rust") => Ok(rust_input(input, externs, matches, cmdline_args)),
317318
Some("json") => json_input(input),
318319
Some(s) => Err(format!("unknown input format: {}", s)),
319320
None => {
320321
if input.ends_with(".json") {
321322
json_input(input)
322323
} else {
323-
Ok(rust_input(input, externs, matches))
324+
Ok(rust_input(input, externs, matches, cmdline_args))
324325
}
325326
}
326327
}
@@ -348,7 +349,8 @@ fn parse_externs(matches: &getopts::Matches) -> Result<core::Externs, String> {
348349
/// generated from the cleaned AST of the crate.
349350
///
350351
/// This form of input will run all of the plug/cleaning passes
351-
fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matches) -> Output {
352+
fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matches,
353+
cmdline_args: &[String]) -> Output {
352354
let mut default_passes = !matches.opt_present("no-defaults");
353355
let mut passes = matches.opt_strs("passes");
354356
let mut plugins = matches.opt_strs("plugins");
@@ -365,7 +367,7 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche
365367
info!("starting to run rustc");
366368

367369
let (tx, rx) = channel();
368-
rustc_driver::monitor(move || {
370+
rustc_driver::monitor(cmdline_args, move || {
369371
use rustc::session::config::Input;
370372

371373
tx.send(core::run_core(paths, cfgs, externs, Input::File(cr),

src/tools/rustbook/build.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> {
137137

138138
fs::create_dir_all(&out_path)?;
139139

140-
let rustdoc_args: &[String] = &[
140+
let rustdoc_args = vec![
141141
"".to_string(),
142142
preprocessed_path.display().to_string(),
143143
format!("-o{}", out_path.display()),
@@ -147,7 +147,7 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> {
147147
format!("--markdown-css={}", item.path_to_root.join("rustbook.css").display()),
148148
"--markdown-no-toc".to_string(),
149149
];
150-
let output_result = rustdoc::main_args(rustdoc_args);
150+
let output_result = rustdoc::main_args(&rustdoc_args);
151151
if output_result != 0 {
152152
let message = format!("Could not execute `rustdoc` with {:?}: {}",
153153
rustdoc_args, output_result);

0 commit comments

Comments
 (0)