mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Use workspace cargo to fetch rust source's metadata
Previously the detected cargo is the global one, as it uses the directory of the rust source which doesn't pick up the local override This fixes the case in clippy where the local rust toolchain is a recent nightly that has a 2021 edition Cargo.toml. The global (stable) cargo returns an error attempting to parse it Fixes #10445
This commit is contained in:
parent
a30941e2a5
commit
a6eeb75120
2 changed files with 24 additions and 13 deletions
|
@ -251,6 +251,7 @@ struct PackageMetadata {
|
||||||
impl CargoWorkspace {
|
impl CargoWorkspace {
|
||||||
pub fn fetch_metadata(
|
pub fn fetch_metadata(
|
||||||
cargo_toml: &ManifestPath,
|
cargo_toml: &ManifestPath,
|
||||||
|
current_dir: &AbsPath,
|
||||||
config: &CargoConfig,
|
config: &CargoConfig,
|
||||||
progress: &dyn Fn(String),
|
progress: &dyn Fn(String),
|
||||||
) -> Result<cargo_metadata::Metadata> {
|
) -> Result<cargo_metadata::Metadata> {
|
||||||
|
@ -275,7 +276,7 @@ impl CargoWorkspace {
|
||||||
meta.features(CargoOpt::SomeFeatures(config.features.clone()));
|
meta.features(CargoOpt::SomeFeatures(config.features.clone()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
meta.current_dir(cargo_toml.parent().as_os_str());
|
meta.current_dir(current_dir.as_os_str());
|
||||||
|
|
||||||
if let Some(target) = target {
|
if let Some(target) = target {
|
||||||
meta.other_options(vec![String::from("--filter-platform"), target]);
|
meta.other_options(vec![String::from("--filter-platform"), target]);
|
||||||
|
|
|
@ -160,7 +160,12 @@ impl ProjectWorkspace {
|
||||||
cmd
|
cmd
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let meta = CargoWorkspace::fetch_metadata(&cargo_toml, config, progress)
|
let meta = CargoWorkspace::fetch_metadata(
|
||||||
|
&cargo_toml,
|
||||||
|
cargo_toml.parent(),
|
||||||
|
config,
|
||||||
|
progress,
|
||||||
|
)
|
||||||
.with_context(|| {
|
.with_context(|| {
|
||||||
format!(
|
format!(
|
||||||
"Failed to read Cargo metadata from Cargo.toml file {}, {}",
|
"Failed to read Cargo metadata from Cargo.toml file {}, {}",
|
||||||
|
@ -189,7 +194,12 @@ impl ProjectWorkspace {
|
||||||
|
|
||||||
let rustc = match rustc_dir {
|
let rustc = match rustc_dir {
|
||||||
Some(rustc_dir) => Some({
|
Some(rustc_dir) => Some({
|
||||||
let meta = CargoWorkspace::fetch_metadata(&rustc_dir, config, progress)
|
let meta = CargoWorkspace::fetch_metadata(
|
||||||
|
&rustc_dir,
|
||||||
|
cargo_toml.parent(),
|
||||||
|
config,
|
||||||
|
progress,
|
||||||
|
)
|
||||||
.with_context(|| {
|
.with_context(|| {
|
||||||
"Failed to read Cargo metadata for Rust sources".to_string()
|
"Failed to read Cargo metadata for Rust sources".to_string()
|
||||||
})?;
|
})?;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue