7391: Fix error when using "extern crate self as" r=kazatsuyu a=kazatsuyu

Fix #6957

Co-authored-by: kazatsuyu <shirayama.kazatsuyu@gmail.com>
This commit is contained in:
bors[bot] 2021-01-23 04:04:09 +00:00 committed by GitHub
commit eab5db20ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View file

@ -13,6 +13,7 @@
use std::iter::successors;
use base_db::Edition;
use hir_expand::name;
use hir_expand::name::Name;
use test_utils::mark;
@ -63,6 +64,13 @@ impl ResolvePathResult {
impl DefMap {
pub(super) fn resolve_name_in_extern_prelude(&self, name: &Name) -> PerNs {
if name == &name!(self) {
mark::hit!(extern_crate_self_as);
return PerNs::types(
ModuleId { krate: self.krate, local_id: self.root }.into(),
Visibility::Public,
);
}
self.extern_prelude
.get(name)
.map_or(PerNs::none(), |&it| PerNs::types(it, Visibility::Public))

View file

@ -61,6 +61,22 @@ fn unresolved_extern_crate() {
);
}
#[test]
fn extern_crate_self_as() {
mark::check!(extern_crate_self_as);
check_diagnostics(
r"
//- /lib.rs
extern crate doesnotexist;
//^^^^^^^^^^^^^^^^^^^^^^^^^^ unresolved extern crate
// Should not error.
extern crate self as foo;
struct Foo;
use foo::Foo as Bar;
",
);
}
#[test]
fn dedup_unresolved_import_from_unresolved_crate() {
check_diagnostics(