Skip to content

Commit 5d29039

Browse files
committed
Set rustcSource to "discover" to be able to automatically detect rustc-dev;
1 parent bab0647 commit 5d29039

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

crates/project_model/src/cargo_workspace.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ pub struct CargoConfig {
6363
/// when debugging isolated issues.
6464
pub no_sysroot: bool,
6565

66-
/// rustc private crate source
67-
pub rustc_source: Option<AbsPathBuf>,
66+
/// Text-form path to the rustc's private crates source, or "discover" to find them
67+
/// automatically.
68+
/// Keep the root path around so we can reference relative paths to the private crates source.
69+
pub rustc_source: Option<(AbsPathBuf, String)>,
6870
}
6971

7072
pub type Package = Idx<PackageData>;

crates/project_model/src/workspace.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,12 @@ impl ProjectWorkspace {
126126
})?
127127
};
128128

129-
let rustc_dir = if let Some(rustc_dir) = &config.rustc_source {
130-
Some(rustc_dir)
131-
} else if let Some(rustc_dir) = &sysroot.rustc_src_dir {
132-
Some(rustc_dir)
129+
let rustc_dir = if let Some((root_dir, path_to_rustc_src)) = &config.rustc_source {
130+
if path_to_rustc_src == "discover" {
131+
sysroot.rustc_src_dir.clone()
132+
} else {
133+
Some(root_dir.join(path_to_rustc_src))
134+
}
133135
} else {
134136
None
135137
};

crates/rust-analyzer/src/config.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,9 @@ config_data! {
177177
/// tests or binaries.\nFor example, it may be `--release`.
178178
runnables_cargoExtraArgs: Vec<String> = "[]",
179179

180-
/// Path to the rust compiler sources, for usage in rustc_private projects.
181-
rustcSource : Option<PathBuf> = "null",
180+
/// Path to the rust compiler sources, for usage in rustc_private projects, or "discover"
181+
/// to try to automatically find it.
182+
rustcSource : Option<String> = "null",
182183

183184
/// Additional arguments to `rustfmt`.
184185
rustfmt_extraArgs: Vec<String> = "[]",
@@ -473,7 +474,8 @@ impl Config {
473474
self.data.cargo_loadOutDirsFromCheck
474475
}
475476
pub fn cargo(&self) -> CargoConfig {
476-
let rustc_source = self.data.rustcSource.as_ref().map(|it| self.root_path.join(&it));
477+
let rustc_source =
478+
self.data.rustcSource.as_ref().map(|path| (self.root_path.clone(), path.clone()));
477479

478480
CargoConfig {
479481
no_default_features: self.data.cargo_noDefaultFeatures,

docs/user/generated_config.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
[[rust-analyzer.runnables.cargoExtraArgs]]rust-analyzer.runnables.cargoExtraArgs (default: `[]`)::
106106
Additional arguments to be passed to cargo for runnables such as tests or binaries.\nFor example, it may be `--release`.
107107
[[rust-analyzer.rustcSource]]rust-analyzer.rustcSource (default: `null`)::
108-
Path to the rust compiler sources, for usage in rustc_private projects.
108+
Path to the rust compiler sources, for usage in rustc_private projects, or "discover" to try to automatically find it.
109109
[[rust-analyzer.rustfmt.extraArgs]]rust-analyzer.rustfmt.extraArgs (default: `[]`)::
110110
Additional arguments to `rustfmt`.
111111
[[rust-analyzer.rustfmt.overrideCommand]]rust-analyzer.rustfmt.overrideCommand (default: `null`)::

editors/code/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@
707707
}
708708
},
709709
"rust-analyzer.rustcSource": {
710-
"markdownDescription": "Path to the rust compiler sources, for usage in rustc_private projects.",
710+
"markdownDescription": "Path to the rust compiler sources, for usage in rustc_private projects, or \"discover\" to try to automatically find it.",
711711
"default": null,
712712
"type": [
713713
"null",

0 commit comments

Comments
 (0)