Skip to content

Commit a672968

Browse files
committed
Auto merge of rust-lang#18242 - Veykril:veykril/push-tnynzqsmtnqw, r=Veykril
internal: Don't resolve extern crates in import fix point resolution The fix point loop won't progress them given the potential extern crate candidates are set up at build time.
2 parents 1ef2712 + 96b3402 commit a672968

File tree

7 files changed

+174
-185
lines changed

7 files changed

+174
-185
lines changed

src/tools/rust-analyzer/crates/base-db/src/input.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@ pub struct CrateData {
288288
/// The cfg options that could be used by the crate
289289
pub potential_cfg_options: Option<Arc<CfgOptions>>,
290290
pub env: Env,
291+
/// The dependencies of this crate.
292+
///
293+
/// Note that this may contain more dependencies than the crate actually uses.
294+
/// A common example is the test crate which is included but only actually is active when
295+
/// declared in source via `extern crate test`.
291296
pub dependencies: Vec<Dependency>,
292297
pub origin: CrateOrigin,
293298
pub is_proc_macro: bool,

src/tools/rust-analyzer/crates/hir-def/src/data.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -506,14 +506,17 @@ impl ExternCrateDeclData {
506506
let crate_id = if name == sym::self_.clone() {
507507
Some(krate)
508508
} else {
509-
db.crate_def_map(krate)
510-
.extern_prelude()
511-
.find(|&(prelude_name, ..)| *prelude_name == name)
512-
.map(|(_, (root, _))| root.krate())
509+
db.crate_graph()[krate].dependencies.iter().find_map(|dep| {
510+
if dep.name.symbol() == name.symbol() {
511+
Some(dep.crate_id)
512+
} else {
513+
None
514+
}
515+
})
513516
};
514517

515518
Arc::new(Self {
516-
name: extern_crate.name.clone(),
519+
name,
517520
visibility: item_tree[extern_crate.visibility].clone(),
518521
alias: extern_crate.alias.clone(),
519522
crate_id,

0 commit comments

Comments
 (0)