Skip to content

Commit 2779d74

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

File tree

4 files changed

+15
-21
lines changed

4 files changed

+15
-21
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

+3-12
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,21 +64,12 @@ 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-
};
70-
let triple = match triple {
71-
TargetTriple::TargetTriple(triple) => triple,
72-
TargetTriple::TargetJson { .. } => {
73-
early_dcx.early_fatal("`-L builtin:` is not supported with custom targets");
74-
}
75-
};
76-
7767
if stripped.contains(std::path::is_separator) {
7868
early_dcx.early_fatal("`-L builtin:` does not accept paths");
7969
}
8070

81-
let path = make_target_lib_path(sysroot, triple).join("builtin").join(stripped);
71+
let path =
72+
make_target_lib_path(sysroot, triple.triple()).join("builtin").join(stripped);
8273
if !path.is_dir() {
8374
early_dcx.early_fatal(format!("builtin:{stripped} does not exist"));
8475
}

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)