Skip to content

Commit 2fae4ee

Browse files
committed
Make sysroot mandatory for rustdoc
1 parent 9ae4e3e commit 2fae4ee

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

compiler/rustc_interface/src/tests.rs

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

318318
let push = |opts: &mut Options, search_path| {
319319
opts.search_paths.push(SearchPath::from_cli_opt(
320-
None,
320+
"not-a-sysroot".as_ref(),
321321
&opts.target_triple,
322322
&early_dcx,
323323
search_path,

compiler/rustc_session/src/config.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2824,7 +2824,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
28242824
let logical_env = parse_logical_env(early_dcx, matches);
28252825

28262826
let sysroot = filesearch::materialize_sysroot(sysroot_opt);
2827-
28282827
let real_rust_source_base_dir = {
28292828
// This is the location used by the `rust-src` `rustup` component.
28302829
let mut candidate = sysroot.join("lib/rustlib/src/rust");
@@ -2845,7 +2844,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
28452844

28462845
let mut search_paths = vec![];
28472846
for s in &matches.opt_strs("L") {
2848-
search_paths.push(SearchPath::from_cli_opt(Some(&sysroot), &target_triple, early_dcx, s));
2847+
search_paths.push(SearchPath::from_cli_opt(&sysroot, &target_triple, early_dcx, s));
28492848
}
28502849

28512850
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
@@ -625,10 +625,17 @@ impl Options {
625625
let target = parse_target_triple(early_dcx, matches);
626626
let maybe_sysroot = matches.opt_str("sysroot").map(PathBuf::from);
627627

628+
let sysroot = match &maybe_sysroot {
629+
Some(s) => s.clone(),
630+
None => {
631+
rustc_session::filesearch::get_or_default_sysroot().expect("Failed finding sysroot")
632+
}
633+
};
634+
628635
let libs = matches
629636
.opt_strs("L")
630637
.iter()
631-
.map(|s| SearchPath::from_cli_opt(maybe_sysroot.as_deref(), &target, early_dcx, s))
638+
.map(|s| SearchPath::from_cli_opt(&sysroot, &target, early_dcx, s))
632639
.collect();
633640

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

0 commit comments

Comments
 (0)