Skip to content

Commit d84b970

Browse files
committed
Auto merge of rust-lang#17795 - Veykril:library-dep-loading, r=Veykril
feat: Load sysroot library via cargo metadata See rust-lang#128534, fixes rust-lang/rust-analyzer#7637 Requires a toolchain from 176e545 2024-08-04 or later to work.
2 parents 77fe1cb + ef7d2c5 commit d84b970

File tree

16 files changed

+156
-212
lines changed

16 files changed

+156
-212
lines changed

src/tools/rust-analyzer/crates/ide-assists/src/handlers/bind_unused_param.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub(crate) fn bind_unused_param(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
4343

4444
acc.add(
4545
AssistId("bind_unused_param", AssistKind::QuickFix),
46-
&format!("Bind as `let _ = {ident_pat};`"),
46+
format!("Bind as `let _ = {ident_pat};`"),
4747
param.syntax().text_range(),
4848
|builder| {
4949
let line_index = ctx.db().line_index(ctx.file_id().into());

src/tools/rust-analyzer/crates/load-cargo/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use ide_db::{
1616
use itertools::Itertools;
1717
use proc_macro_api::{MacroDylib, ProcMacroServer};
1818
use project_model::{
19-
CargoConfig, ManifestPath, PackageRoot, ProjectManifest, ProjectWorkspace, ProjectWorkspaceKind,
19+
CargoConfig, PackageRoot, ProjectManifest, ProjectWorkspace, ProjectWorkspaceKind,
2020
};
2121
use span::Span;
2222
use vfs::{file_set::FileSetConfig, loader::Handle, AbsPath, AbsPathBuf, VfsPath};
@@ -247,7 +247,7 @@ impl ProjectFolders {
247247
let mut file_set_roots: Vec<VfsPath> = vec![];
248248
let mut entries = vec![];
249249

250-
if let Some(manifest) = ws.manifest().map(ManifestPath::as_ref) {
250+
if let Some(manifest) = ws.manifest().map(|it| it.to_path_buf()) {
251251
file_set_roots.push(VfsPath::from(manifest.to_owned()));
252252
entries.push(manifest.to_owned());
253253
}

src/tools/rust-analyzer/crates/paths/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ impl AbsPathBuf {
141141
pub fn push<P: AsRef<Utf8Path>>(&mut self, suffix: P) {
142142
self.0.push(suffix)
143143
}
144+
145+
pub fn join(&self, path: impl AsRef<Utf8Path>) -> Self {
146+
Self(self.0.join(path))
147+
}
144148
}
145149

146150
impl fmt::Display for AbsPathBuf {

src/tools/rust-analyzer/crates/project-model/src/build_scripts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl WorkspaceBuildScripts {
7373
cmd.args(&config.extra_args);
7474

7575
cmd.arg("--manifest-path");
76-
cmd.arg(manifest_path.as_ref());
76+
cmd.arg(manifest_path);
7777

7878
if let Some(target_dir) = &config.target_dir {
7979
cmd.arg("--target-dir").arg(target_dir);

src/tools/rust-analyzer/crates/project-model/src/cargo_workspace.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ pub struct CargoConfig {
8585
pub target: Option<String>,
8686
/// Sysroot loading behavior
8787
pub sysroot: Option<RustLibSource>,
88-
/// Whether to invoke `cargo metadata` on the sysroot crate.
89-
pub sysroot_query_metadata: bool,
9088
pub sysroot_src: Option<AbsPathBuf>,
9189
/// rustc private crate source
9290
pub rustc_source: Option<RustLibSource>,
@@ -259,6 +257,7 @@ impl CargoWorkspace {
259257
current_dir: &AbsPath,
260258
config: &CargoConfig,
261259
sysroot: &Sysroot,
260+
locked: bool,
262261
progress: &dyn Fn(String),
263262
) -> anyhow::Result<cargo_metadata::Metadata> {
264263
let targets = find_list_of_build_targets(config, cargo_toml, sysroot);
@@ -312,6 +311,9 @@ impl CargoWorkspace {
312311
// opt into it themselves.
313312
other_options.push("-Zscript".to_owned());
314313
}
314+
if locked {
315+
other_options.push("--locked".to_owned());
316+
}
315317
meta.other_options(other_options);
316318

317319
// FIXME: Fetching metadata is a slow process, as it might require

src/tools/rust-analyzer/crates/project-model/src/manifest_path.rs

+12
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ impl AsRef<AbsPath> for ManifestPath {
6464
}
6565
}
6666

67+
impl AsRef<std::path::Path> for ManifestPath {
68+
fn as_ref(&self) -> &std::path::Path {
69+
self.file.as_ref()
70+
}
71+
}
72+
73+
impl AsRef<std::ffi::OsStr> for ManifestPath {
74+
fn as_ref(&self) -> &std::ffi::OsStr {
75+
self.file.as_ref()
76+
}
77+
}
78+
6779
impl Borrow<AbsPath> for ManifestPath {
6880
fn borrow(&self) -> &AbsPath {
6981
self.file.borrow()

0 commit comments

Comments
 (0)