Skip to content

Commit c8e61c0

Browse files
committed
Make sysroot mandatory for rustdoc
1 parent 7f1719f commit c8e61c0

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

compiler/rustc_interface/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ fn test_search_paths_tracking_hash_different_order() {
310310

311311
let push = |opts: &mut Options, search_path| {
312312
opts.search_paths.push(SearchPath::from_cli_opt(
313-
None,
313+
"not-a-sysroot".as_ref(),
314314
&opts.target_triple,
315315
&early_dcx,
316316
search_path,

compiler/rustc_session/src/config.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -2860,13 +2860,9 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
28602860

28612861
// Try to find a directory containing the Rust `src`, for more details see
28622862
// the doc comment on the `real_rust_source_base_dir` field.
2863-
let tmp_buf;
28642863
let sysroot = match &sysroot_opt {
2865-
Some(s) => s,
2866-
None => {
2867-
tmp_buf = crate::filesearch::get_or_default_sysroot().expect("Failed finding sysroot");
2868-
&tmp_buf
2869-
}
2864+
Some(s) => s.clone(),
2865+
None => crate::filesearch::get_or_default_sysroot().expect("Failed finding sysroot"),
28702866
};
28712867
let real_rust_source_base_dir = {
28722868
// This is the location used by the `rust-src` `rustup` component.
@@ -2888,7 +2884,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
28882884

28892885
let mut search_paths = vec![];
28902886
for s in &matches.opt_strs("L") {
2891-
search_paths.push(SearchPath::from_cli_opt(Some(&sysroot), &target_triple, early_dcx, s));
2887+
search_paths.push(SearchPath::from_cli_opt(&sysroot, &target_triple, early_dcx, s));
28922888
}
28932889

28942890
let working_dir = std::env::current_dir().unwrap_or_else(|e| {

compiler/rustc_session/src/search_paths.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl PathKind {
4848

4949
impl SearchPath {
5050
pub fn from_cli_opt(
51-
sysroot: Option<&Path>,
51+
sysroot: &Path,
5252
triple: &TargetTriple,
5353
early_dcx: &EarlyDiagCtxt,
5454
path: &str,
@@ -64,9 +64,6 @@ impl SearchPath {
6464
} else if let Some(stripped) = path.strip_prefix("all=") {
6565
(PathKind::All, stripped)
6666
} else if let Some(stripped) = path.strip_prefix("builtin:") {
67-
let Some(sysroot) = sysroot else {
68-
early_dcx.early_fatal("`-L builtin:` is not supported without a sysroot present");
69-
};
7067
let triple = match triple {
7168
TargetTriple::TargetTriple(triple) => triple,
7269
TargetTriple::TargetJson { .. } => {

src/librustdoc/config.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -619,10 +619,17 @@ impl Options {
619619
let target = parse_target_triple(early_dcx, matches);
620620
let maybe_sysroot = matches.opt_str("sysroot").map(PathBuf::from);
621621

622+
let sysroot = match &maybe_sysroot {
623+
Some(s) => s.clone(),
624+
None => {
625+
rustc_session::filesearch::get_or_default_sysroot().expect("Failed finding sysroot")
626+
}
627+
};
628+
622629
let libs = matches
623630
.opt_strs("L")
624631
.iter()
625-
.map(|s| SearchPath::from_cli_opt(maybe_sysroot.as_deref(), &target, early_dcx, s))
632+
.map(|s| SearchPath::from_cli_opt(&sysroot, &target, early_dcx, s))
626633
.collect();
627634

628635
let show_coverage = matches.opt_present("show-coverage");

0 commit comments

Comments
 (0)