From e52589e3a72ed57d47956d16d90f4b15fc7408f0 Mon Sep 17 00:00:00 2001 From: kazatsuyu Date: Fri, 22 Jan 2021 22:28:45 +0900 Subject: Fix error when using "extern crate self as" --- crates/hir_def/src/nameres/path_resolution.rs | 6 ++++++ crates/hir_def/src/nameres/tests/diagnostics.rs | 15 +++++++++++++++ 2 files changed, 21 insertions(+) (limited to 'crates') diff --git a/crates/hir_def/src/nameres/path_resolution.rs b/crates/hir_def/src/nameres/path_resolution.rs index ec90f4e65..a6e0f64fc 100644 --- a/crates/hir_def/src/nameres/path_resolution.rs +++ b/crates/hir_def/src/nameres/path_resolution.rs @@ -14,6 +14,7 @@ use std::iter::successors; use base_db::Edition; use hir_expand::name::Name; +use hir_expand::name; use test_utils::mark; use crate::{ @@ -63,6 +64,11 @@ impl ResolvePathResult { impl DefMap { pub(super) fn resolve_name_in_extern_prelude(&self, name: &Name) -> PerNs { + if name == &name!(self) { + 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)) diff --git a/crates/hir_def/src/nameres/tests/diagnostics.rs b/crates/hir_def/src/nameres/tests/diagnostics.rs index 58d69d3c6..679a505dc 100644 --- a/crates/hir_def/src/nameres/tests/diagnostics.rs +++ b/crates/hir_def/src/nameres/tests/diagnostics.rs @@ -61,6 +61,21 @@ fn unresolved_extern_crate() { ); } +#[test] +fn 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( -- cgit v1.2.3 From 0fb4544403f67fd4f9046532cff70f776d5ba562 Mon Sep 17 00:00:00 2001 From: kazatsuyu Date: Fri, 22 Jan 2021 22:52:04 +0900 Subject: cargo fmt --- crates/hir_def/src/nameres/path_resolution.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/hir_def/src/nameres/path_resolution.rs b/crates/hir_def/src/nameres/path_resolution.rs index a6e0f64fc..bb8ccaa9d 100644 --- a/crates/hir_def/src/nameres/path_resolution.rs +++ b/crates/hir_def/src/nameres/path_resolution.rs @@ -13,8 +13,8 @@ use std::iter::successors; use base_db::Edition; -use hir_expand::name::Name; use hir_expand::name; +use hir_expand::name::Name; use test_utils::mark; use crate::{ @@ -65,7 +65,8 @@ impl ResolvePathResult { impl DefMap { pub(super) fn resolve_name_in_extern_prelude(&self, name: &Name) -> PerNs { if name == &name!(self) { - return PerNs::types(ModuleId { krate: self.krate, local_id: self.root }.into(), + return PerNs::types( + ModuleId { krate: self.krate, local_id: self.root }.into(), Visibility::Public, ); } -- cgit v1.2.3 From 90d6740e3237e396f437619d115b8595d2242392 Mon Sep 17 00:00:00 2001 From: kazatsuyu Date: Sat, 23 Jan 2021 00:11:37 +0900 Subject: Add mark::check! and mark::hit! --- crates/hir_def/src/nameres/path_resolution.rs | 1 + crates/hir_def/src/nameres/tests/diagnostics.rs | 1 + 2 files changed, 2 insertions(+) (limited to 'crates') diff --git a/crates/hir_def/src/nameres/path_resolution.rs b/crates/hir_def/src/nameres/path_resolution.rs index bb8ccaa9d..7588e0088 100644 --- a/crates/hir_def/src/nameres/path_resolution.rs +++ b/crates/hir_def/src/nameres/path_resolution.rs @@ -65,6 +65,7 @@ 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, diff --git a/crates/hir_def/src/nameres/tests/diagnostics.rs b/crates/hir_def/src/nameres/tests/diagnostics.rs index 679a505dc..e8e72e5ef 100644 --- a/crates/hir_def/src/nameres/tests/diagnostics.rs +++ b/crates/hir_def/src/nameres/tests/diagnostics.rs @@ -63,6 +63,7 @@ fn unresolved_extern_crate() { #[test] fn extern_crate_self_as() { + mark::check!(extern_crate_self_as); check_diagnostics( r" //- /lib.rs -- cgit v1.2.3