diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-08-13 23:16:31 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-08-13 23:16:31 +0100 |
commit | f1f73649a686dc6e6449afc35e0fa6fed00e225d (patch) | |
tree | a62d88ce37b64507b708f8cdc86c8ff3602a42bc /crates/hir | |
parent | 9930ef253634465e2fe25b47b469e4c3bbcf6df1 (diff) | |
parent | 9664c57e60ec5662b3e8b063324d9ab7879d5570 (diff) |
Merge #5755
5755: Make hygiene private to hir r=davidlattimore a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/hir')
-rw-r--r-- | crates/hir/src/code_model.rs | 7 | ||||
-rw-r--r-- | crates/hir/src/lib.rs | 8 | ||||
-rw-r--r-- | crates/hir/src/semantics.rs | 16 |
3 files changed, 26 insertions, 5 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 8ffb9e99b..5dc3ae3b1 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs | |||
@@ -883,6 +883,13 @@ where | |||
883 | } | 883 | } |
884 | 884 | ||
885 | impl AssocItem { | 885 | impl AssocItem { |
886 | pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { | ||
887 | match self { | ||
888 | AssocItem::Function(it) => Some(it.name(db)), | ||
889 | AssocItem::Const(it) => it.name(db), | ||
890 | AssocItem::TypeAlias(it) => Some(it.name(db)), | ||
891 | } | ||
892 | } | ||
886 | pub fn module(self, db: &dyn HirDatabase) -> Module { | 893 | pub fn module(self, db: &dyn HirDatabase) -> Module { |
887 | match self { | 894 | match self { |
888 | AssocItem::Function(f) => f.module(db), | 895 | AssocItem::Function(f) => f.module(db), |
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 24a0f6b4b..4ae2bd085 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs | |||
@@ -52,8 +52,12 @@ pub use hir_def::{ | |||
52 | type_ref::{Mutability, TypeRef}, | 52 | type_ref::{Mutability, TypeRef}, |
53 | }; | 53 | }; |
54 | pub use hir_expand::{ | 54 | pub use hir_expand::{ |
55 | hygiene::Hygiene, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, | 55 | name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, /* FIXME */ MacroDefId, |
56 | MacroDefId, /* FIXME */ | ||
57 | MacroFile, Origin, | 56 | MacroFile, Origin, |
58 | }; | 57 | }; |
59 | pub use hir_ty::display::HirDisplay; | 58 | pub use hir_ty::display::HirDisplay; |
59 | |||
60 | // These are negative re-exports: pub using these names is forbidden, they | ||
61 | // should remain private to hir internals. | ||
62 | #[allow(unused)] | ||
63 | use hir_expand::hygiene::Hygiene; | ||
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index 1467d825d..d8beac98a 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs | |||
@@ -502,18 +502,19 @@ impl<'db> SemanticsImpl<'db> { | |||
502 | fn scope(&self, node: &SyntaxNode) -> SemanticsScope<'db> { | 502 | fn scope(&self, node: &SyntaxNode) -> SemanticsScope<'db> { |
503 | let node = self.find_file(node.clone()); | 503 | let node = self.find_file(node.clone()); |
504 | let resolver = self.analyze2(node.as_ref(), None).resolver; | 504 | let resolver = self.analyze2(node.as_ref(), None).resolver; |
505 | SemanticsScope { db: self.db, resolver } | 505 | SemanticsScope { db: self.db, file_id: node.file_id, resolver } |
506 | } | 506 | } |
507 | 507 | ||
508 | fn scope_at_offset(&self, node: &SyntaxNode, offset: TextSize) -> SemanticsScope<'db> { | 508 | fn scope_at_offset(&self, node: &SyntaxNode, offset: TextSize) -> SemanticsScope<'db> { |
509 | let node = self.find_file(node.clone()); | 509 | let node = self.find_file(node.clone()); |
510 | let resolver = self.analyze2(node.as_ref(), Some(offset)).resolver; | 510 | let resolver = self.analyze2(node.as_ref(), Some(offset)).resolver; |
511 | SemanticsScope { db: self.db, resolver } | 511 | SemanticsScope { db: self.db, file_id: node.file_id, resolver } |
512 | } | 512 | } |
513 | 513 | ||
514 | fn scope_for_def(&self, def: Trait) -> SemanticsScope<'db> { | 514 | fn scope_for_def(&self, def: Trait) -> SemanticsScope<'db> { |
515 | let file_id = self.db.lookup_intern_trait(def.id).id.file_id; | ||
515 | let resolver = def.id.resolver(self.db.upcast()); | 516 | let resolver = def.id.resolver(self.db.upcast()); |
516 | SemanticsScope { db: self.db, resolver } | 517 | SemanticsScope { db: self.db, file_id, resolver } |
517 | } | 518 | } |
518 | 519 | ||
519 | fn analyze(&self, node: &SyntaxNode) -> SourceAnalyzer { | 520 | fn analyze(&self, node: &SyntaxNode) -> SourceAnalyzer { |
@@ -709,6 +710,7 @@ fn find_root(node: &SyntaxNode) -> SyntaxNode { | |||
709 | #[derive(Debug)] | 710 | #[derive(Debug)] |
710 | pub struct SemanticsScope<'a> { | 711 | pub struct SemanticsScope<'a> { |
711 | pub db: &'a dyn HirDatabase, | 712 | pub db: &'a dyn HirDatabase, |
713 | file_id: HirFileId, | ||
712 | resolver: Resolver, | 714 | resolver: Resolver, |
713 | } | 715 | } |
714 | 716 | ||
@@ -752,6 +754,14 @@ impl<'a> SemanticsScope<'a> { | |||
752 | }) | 754 | }) |
753 | } | 755 | } |
754 | 756 | ||
757 | /// Resolve a path as-if it was written at the given scope. This is | ||
758 | /// necessary a heuristic, as it doesn't take hygiene into account. | ||
759 | pub fn resolve_hypothetical(&self, path: &ast::Path) -> Option<PathResolution> { | ||
760 | let hygiene = Hygiene::new(self.db.upcast(), self.file_id); | ||
761 | let path = Path::from_src(path.clone(), &hygiene)?; | ||
762 | self.resolve_hir_path(&path) | ||
763 | } | ||
764 | |||
755 | pub fn resolve_hir_path(&self, path: &Path) -> Option<PathResolution> { | 765 | pub fn resolve_hir_path(&self, path: &Path) -> Option<PathResolution> { |
756 | resolve_hir_path(self.db, &self.resolver, path) | 766 | resolve_hir_path(self.db, &self.resolver, path) |
757 | } | 767 | } |