Skip to content

Commit 654f56e

Browse files
committed
1 parent 0dddad0 commit 654f56e

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/bootstrap/bin/rustc.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ include!("../dylib_util.rs");
1919

2020
use std::env;
2121
use std::path::PathBuf;
22-
use std::process::{Child, Command};
22+
use std::process::{exit, Child, Command};
2323
use std::str::FromStr;
2424
use std::time::Instant;
2525

@@ -47,7 +47,12 @@ fn main() {
4747
} else {
4848
("RUSTC_REAL", "RUSTC_LIBDIR")
4949
};
50-
let stage = env::var("RUSTC_STAGE").expect("RUSTC_STAGE was not set");
50+
let stage = env::var("RUSTC_STAGE").unwrap_or_else(|_| {
51+
// Don't panic here; it's reasonable to try and run these shims directly. Give a helpful error instead.
52+
eprintln!("rustc shim: fatal: RUSTC_STAGE was not set");
53+
eprintln!("rustc shim: note: use `x.py build -vvv` to see all environment variables set by bootstrap");
54+
exit(101);
55+
});
5156
let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set");
5257
let on_fail = env::var_os("RUSTC_ON_FAIL").map(Command::new);
5358

src/bootstrap/bin/rustdoc.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@
55
use std::env;
66
use std::ffi::OsString;
77
use std::path::PathBuf;
8-
use std::process::Command;
8+
use std::process::{exit, Command};
99

1010
include!("../dylib_util.rs");
1111

1212
fn main() {
1313
let args = env::args_os().skip(1).collect::<Vec<_>>();
14-
let stage = env::var("RUSTC_STAGE").expect("RUSTC_STAGE was not set");
14+
let stage = env::var("RUSTC_STAGE").unwrap_or_else(|_| {
15+
// Don't panic here; it's reasonable to try and run these shims directly. Give a helpful error instead.
16+
eprintln!("rustc shim: fatal: RUSTC_STAGE was not set");
17+
eprintln!("rustc shim: note: use `x.py build -vvv` to see all environment variables set by bootstrap");
18+
exit(101);
19+
});
1520
let rustdoc = env::var_os("RUSTDOC_REAL").expect("RUSTDOC_REAL was not set");
1621
let libdir = env::var_os("RUSTDOC_LIBDIR").expect("RUSTDOC_LIBDIR was not set");
1722
let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set");

0 commit comments

Comments
 (0)