Skip to content

Commit

Permalink
Auto merge of rust-lang#17795 - Veykril:library-dep-loading, r=Veykril
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Aug 5, 2024
2 parents 77fe1cb + ef7d2c5 commit d84b970
Show file tree
Hide file tree
Showing 16 changed files with 156 additions and 212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub(crate) fn bind_unused_param(acc: &mut Assists, ctx: &AssistContext<'_>) -> O

acc.add(
AssistId("bind_unused_param", AssistKind::QuickFix),
&format!("Bind as `let _ = {ident_pat};`"),
format!("Bind as `let _ = {ident_pat};`"),
param.syntax().text_range(),
|builder| {
let line_index = ctx.db().line_index(ctx.file_id().into());
Expand Down
4 changes: 2 additions & 2 deletions src/tools/rust-analyzer/crates/load-cargo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use ide_db::{
use itertools::Itertools;
use proc_macro_api::{MacroDylib, ProcMacroServer};
use project_model::{
CargoConfig, ManifestPath, PackageRoot, ProjectManifest, ProjectWorkspace, ProjectWorkspaceKind,
CargoConfig, PackageRoot, ProjectManifest, ProjectWorkspace, ProjectWorkspaceKind,
};
use span::Span;
use vfs::{file_set::FileSetConfig, loader::Handle, AbsPath, AbsPathBuf, VfsPath};
Expand Down Expand Up @@ -247,7 +247,7 @@ impl ProjectFolders {
let mut file_set_roots: Vec<VfsPath> = vec![];
let mut entries = vec![];

if let Some(manifest) = ws.manifest().map(ManifestPath::as_ref) {
if let Some(manifest) = ws.manifest().map(|it| it.to_path_buf()) {
file_set_roots.push(VfsPath::from(manifest.to_owned()));
entries.push(manifest.to_owned());
}
Expand Down
4 changes: 4 additions & 0 deletions src/tools/rust-analyzer/crates/paths/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ impl AbsPathBuf {
pub fn push<P: AsRef<Utf8Path>>(&mut self, suffix: P) {
self.0.push(suffix)
}

pub fn join(&self, path: impl AsRef<Utf8Path>) -> Self {
Self(self.0.join(path))
}
}

impl fmt::Display for AbsPathBuf {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl WorkspaceBuildScripts {
cmd.args(&config.extra_args);

cmd.arg("--manifest-path");
cmd.arg(manifest_path.as_ref());
cmd.arg(manifest_path);

if let Some(target_dir) = &config.target_dir {
cmd.arg("--target-dir").arg(target_dir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ pub struct CargoConfig {
pub target: Option<String>,
/// Sysroot loading behavior
pub sysroot: Option<RustLibSource>,
/// Whether to invoke `cargo metadata` on the sysroot crate.
pub sysroot_query_metadata: bool,
pub sysroot_src: Option<AbsPathBuf>,
/// rustc private crate source
pub rustc_source: Option<RustLibSource>,
Expand Down Expand Up @@ -259,6 +257,7 @@ impl CargoWorkspace {
current_dir: &AbsPath,
config: &CargoConfig,
sysroot: &Sysroot,
locked: bool,
progress: &dyn Fn(String),
) -> anyhow::Result<cargo_metadata::Metadata> {
let targets = find_list_of_build_targets(config, cargo_toml, sysroot);
Expand Down Expand Up @@ -312,6 +311,9 @@ impl CargoWorkspace {
// opt into it themselves.
other_options.push("-Zscript".to_owned());
}
if locked {
other_options.push("--locked".to_owned());
}
meta.other_options(other_options);

// FIXME: Fetching metadata is a slow process, as it might require
Expand Down
12 changes: 12 additions & 0 deletions src/tools/rust-analyzer/crates/project-model/src/manifest_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ impl AsRef<AbsPath> for ManifestPath {
}
}

impl AsRef<std::path::Path> for ManifestPath {
fn as_ref(&self) -> &std::path::Path {
self.file.as_ref()
}
}

impl AsRef<std::ffi::OsStr> for ManifestPath {
fn as_ref(&self) -> &std::ffi::OsStr {
self.file.as_ref()
}
}

impl Borrow<AbsPath> for ManifestPath {
fn borrow(&self) -> &AbsPath {
self.file.borrow()
Expand Down
Loading

0 comments on commit d84b970

Please sign in to comment.