Fix extern crate self having self unresolved

This commit is contained in:
Lukas Wirth 2022-03-06 00:17:40 +01:00
parent e5bb661b7a
commit d460b7c9d1
2 changed files with 13 additions and 9 deletions

View File

@ -10,7 +10,10 @@ use hir_def::{
resolver::{self, HasResolver, Resolver, TypeNs},
AsMacroCall, FunctionId, TraitId, VariantId,
};
use hir_expand::{name::AsName, ExpansionInfo, MacroCallId};
use hir_expand::{
name::{known, AsName},
ExpansionInfo, MacroCallId,
};
use hir_ty::Interner;
use itertools::Itertools;
use rustc_hash::{FxHashMap, FxHashSet};
@ -910,13 +913,14 @@ impl<'db> SemanticsImpl<'db> {
fn resolve_extern_crate(&self, extern_crate: &ast::ExternCrate) -> Option<Crate> {
let krate = self.scope(extern_crate.syntax()).krate()?;
krate.dependencies(self.db).into_iter().find_map(|dep| {
if dep.name == extern_crate.name_ref()?.as_name() {
Some(dep.krate)
} else {
None
}
})
let name = extern_crate.name_ref()?.as_name();
if name == known::SELF_PARAM {
return Some(krate);
}
krate
.dependencies(self.db)
.into_iter()
.find_map(|dep| (dep.name == name).then(|| dep.krate))
}
fn resolve_variant(&self, record_lit: ast::RecordExpr) -> Option<VariantId> {

View File

@ -41,7 +41,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
</style>
<pre><code><span class="keyword">extern</span> <span class="keyword">crate</span> <span class="unresolved_reference">self</span><span class="semicolon">;</span>
<pre><code><span class="keyword">extern</span> <span class="keyword">crate</span> <span class="self_keyword crate_root">self</span><span class="semicolon">;</span>
<span class="keyword">use</span> <span class="keyword crate_root">crate</span><span class="semicolon">;</span>
<span class="keyword">use</span> <span class="self_keyword crate_root">self</span><span class="semicolon">;</span>