Skip to content

Commit a6eeb75

Browse files
committed
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
1 parent a30941e commit a6eeb75

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

crates/project_model/src/cargo_workspace.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ struct PackageMetadata {
251251
impl CargoWorkspace {
252252
pub fn fetch_metadata(
253253
cargo_toml: &ManifestPath,
254+
current_dir: &AbsPath,
254255
config: &CargoConfig,
255256
progress: &dyn Fn(String),
256257
) -> Result<cargo_metadata::Metadata> {
@@ -275,7 +276,7 @@ impl CargoWorkspace {
275276
meta.features(CargoOpt::SomeFeatures(config.features.clone()));
276277
}
277278
}
278-
meta.current_dir(cargo_toml.parent().as_os_str());
279+
meta.current_dir(current_dir.as_os_str());
279280

280281
if let Some(target) = target {
281282
meta.other_options(vec![String::from("--filter-platform"), target]);

crates/project_model/src/workspace.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,19 @@ impl ProjectWorkspace {
160160
cmd
161161
})?;
162162

163-
let meta = CargoWorkspace::fetch_metadata(&cargo_toml, config, progress)
164-
.with_context(|| {
165-
format!(
166-
"Failed to read Cargo metadata from Cargo.toml file {}, {}",
167-
cargo_toml.display(),
168-
cargo_version
169-
)
170-
})?;
163+
let meta = CargoWorkspace::fetch_metadata(
164+
&cargo_toml,
165+
cargo_toml.parent(),
166+
config,
167+
progress,
168+
)
169+
.with_context(|| {
170+
format!(
171+
"Failed to read Cargo metadata from Cargo.toml file {}, {}",
172+
cargo_toml.display(),
173+
cargo_version
174+
)
175+
})?;
171176
let cargo = CargoWorkspace::new(meta);
172177

173178
let sysroot = if config.no_sysroot {
@@ -189,10 +194,15 @@ impl ProjectWorkspace {
189194

190195
let rustc = match rustc_dir {
191196
Some(rustc_dir) => Some({
192-
let meta = CargoWorkspace::fetch_metadata(&rustc_dir, config, progress)
193-
.with_context(|| {
194-
"Failed to read Cargo metadata for Rust sources".to_string()
195-
})?;
197+
let meta = CargoWorkspace::fetch_metadata(
198+
&rustc_dir,
199+
cargo_toml.parent(),
200+
config,
201+
progress,
202+
)
203+
.with_context(|| {
204+
"Failed to read Cargo metadata for Rust sources".to_string()
205+
})?;
196206
CargoWorkspace::new(meta)
197207
}),
198208
None => None,

0 commit comments

Comments
 (0)