Skip to content

Commit 4a80b51

Browse files
committed
BinTarget avoids attaching --bin when the package is one other than the one we were looking for
1 parent 65c60e1 commit 4a80b51

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

crates/rust-analyzer/src/handlers/notification.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,6 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
359359
}
360360
};
361361

362-
let bin_target = match scope {
363-
FlycheckScope::Binary { ref bin_target, .. } => Some(bin_target.clone()),
364-
_ => None,
365-
};
366-
367362
let crate_root_paths: Vec<_> = crate_ids
368363
.iter()
369364
.filter_map(|&crate_id| {
@@ -401,7 +396,22 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
401396
let pkg = cargo[target].package;
402397
let pkg_name = cargo[pkg].name.clone();
403398
Some(flycheck::PackageSpecifier::Cargo {
404-
bin_target: bin_target.clone(),
399+
// This is very hacky. But we are iterating through a lot of
400+
// crates, many of which are reverse deps, and it doesn't make
401+
// sense to attach --bin XXX to some random downstream dep in a
402+
// different workspace.
403+
bin_target: match &scope {
404+
FlycheckScope::Binary {
405+
package_name: bin_pkg_name,
406+
bin_target,
407+
..
408+
} if bin_pkg_name.as_ref() == Some(&pkg_name)
409+
&& bin_target.name() == &cargo[target].name =>
410+
{
411+
Some(bin_target.clone())
412+
}
413+
_ => None,
414+
},
405415
cargo_canonical_name: pkg_name,
406416
})
407417
})

0 commit comments

Comments
 (0)