Require opt in to rustc_private

This gives the advantage that

A future extension would be to check for `feature(rustc_private)` instead
This commit is contained in:
Daniel McNab 2021-03-07 12:24:20 +00:00
parent 71a254c1a1
commit 9246df669a
2 changed files with 76 additions and 76 deletions

View File

@ -112,7 +112,7 @@ pub struct PackageData {
#[derive(Deserialize, Default, Debug, Clone, Eq, PartialEq)]
pub struct RustAnalyzerPackageMetaData {
pub rustc_private: Option<bool>,
pub rustc_private: bool,
}
#[derive(Debug, Clone, Eq, PartialEq)]

View File

@ -376,9 +376,10 @@ fn cargo_to_crate_graph(
cfg_options.insert_atom("debug_assertions".into());
let mut pkg_crates = FxHashMap::default();
let mut has_private = false;
// Next, create crates for each package, target pair
for pkg in cargo.packages() {
has_private |= cargo[pkg].metadata.rustc_private;
let mut lib_tgt = None;
for &tgt in cargo[pkg].targets.iter() {
if let Some(file_id) = load(&cargo[tgt].root) {
@ -441,11 +442,12 @@ fn cargo_to_crate_graph(
let mut rustc_pkg_crates = FxHashMap::default();
if has_private {
// If the user provided a path to rustc sources, we add all the rustc_private crates
// and create dependencies on them for the crates which opt-in to that
if let Some(rustc_workspace) = rustc {
// rustc-dev crates start from 'rustc_driver'
// Therefore, we collect all crates which are transitive dependencies of rustc_driver
// We want to collect all crates which are transitive dependencies of rustc_driver
if let Some(root_pkg) = rustc_workspace
.packages()
.find(|package| rustc_workspace[*package].name == "rustc_driver")
@ -453,6 +455,7 @@ fn cargo_to_crate_graph(
let mut queue = VecDeque::new();
queue.push_back(root_pkg);
while let Some(pkg) = queue.pop_front() {
// Don't duplicate packages
if rustc_pkg_crates.contains_key(&pkg) {
continue;
}
@ -467,7 +470,8 @@ fn cargo_to_crate_graph(
let crate_id = add_target_crate_root(
&mut crate_graph,
&rustc_workspace[pkg],
rustc_build_data_map.and_then(|it| it.get(&rustc_workspace[pkg].id)),
rustc_build_data_map
.and_then(|it| it.get(&rustc_workspace[pkg].id)),
&cfg_options,
proc_macro_loader,
file_id,
@ -502,10 +506,7 @@ fn cargo_to_crate_graph(
if let Some(&to) = pkg_to_lib_crate.get(&dep) {
for pkg in cargo.packages() {
let package = &cargo[pkg];
if matches!(
(package.is_member, package.metadata.rustc_private),
(true, Some(false)) | (false, Some(false)) | (false, None)
) {
if !package.metadata.rustc_private {
continue;
}
for &from in pkg_crates.get(&pkg).into_iter().flatten() {
@ -522,8 +523,7 @@ fn cargo_to_crate_graph(
}
}
}
} else {
eprintln!("No cargo workspace");
}
}
crate_graph
}