Skip to content

only return used dependencies in crate_dependencies_in_postorder #125493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ impl CStore {
pub(crate) fn crate_dependencies_in_postorder(&self, cnum: CrateNum) -> Vec<CrateNum> {
let mut deps = Vec::new();
if cnum == LOCAL_CRATE {
for (cnum, _) in self.iter_crate_data() {
for cnum in
self.iter_crate_data().filter_map(|(cnum, data)| data.used().then_some(cnum))
{
self.push_dependencies_in_postorder(&mut deps, cnum);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Empty
9 changes: 9 additions & 0 deletions tests/run-make/issue-125484-used-dependencies/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pub type Foo = something::same::Thing;

mod something {
pub mod same {
pub struct Thing;
}
}

fn main() {}
18 changes: 18 additions & 0 deletions tests/run-make/issue-125484-used-dependencies/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Non-regression test for issues #125474, #125484, #125646, with the repro taken from #125484. Some
// queries use "used dependencies" while others use "speculatively loaded dependencies", and an
// indexing ICE appeared in some cases when these were unexpectedly used in the same context.

// FIXME: this should probably be a UI test instead of a run-make test, but I *cannot* find a way to
// make compiletest annotations reproduce the ICE with the minimizations from issues #125474 and
// #125484.

use run_make_support::{rustc, tmp_dir};

fn main() {
// The dependency is not itself significant, apart from sharing a name with one of main's
// modules.
rustc().crate_name("same").crate_type("rlib").input("dependency.rs").run();

// Here, an ICE would happen when building the linker command.
rustc().input("main.rs").extern_("same", tmp_dir().join("libsame.rlib")).run();
}
Loading