X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=crates%2Fhir%2Fsrc%2Fsemantics.rs;h=75f6b025779587ec935b97b721005d16a043ba8f;hb=749eeef3e75a3acc993fdd454ebadaa7e319509a;hp=281e6c65dc448b17c63b1eec17728cefc4253db3;hpb=366499c3be15a7bbf7914d6825e4d92fdfbddb1e;p=rust.git diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index 281e6c65dc4..75f6b025779 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -25,9 +25,9 @@ db::HirDatabase, semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx}, source_analyzer::{resolve_hir_path, resolve_hir_path_as_macro, SourceAnalyzer}, - Access, AssocItem, Callable, ConstParam, Crate, Field, Function, HasSource, HirFileId, Impl, - InFile, Label, LifetimeParam, Local, MacroDef, Module, ModuleDef, Name, Path, ScopeDef, Trait, - Type, TypeAlias, TypeParam, VariantDef, + Access, AssocItem, BuiltinAttr, Callable, ConstParam, Crate, Field, Function, HasSource, + HirFileId, Impl, InFile, Label, LifetimeParam, Local, MacroDef, Module, ModuleDef, Name, Path, + ScopeDef, ToolModule, Trait, Type, TypeAlias, TypeParam, VariantDef, }; #[derive(Debug, Clone, PartialEq, Eq)] @@ -43,6 +43,8 @@ pub enum PathResolution { SelfType(Impl), Macro(MacroDef), AssocItem(AssocItem), + BuiltinAttr(BuiltinAttr), + ToolModule(ToolModule), } impl PathResolution { @@ -63,9 +65,11 @@ fn in_type_ns(&self) -> Option { PathResolution::Def(ModuleDef::TypeAlias(alias)) => { Some(TypeNs::TypeAliasId((*alias).into())) } - PathResolution::Local(_) | PathResolution::Macro(_) | PathResolution::ConstParam(_) => { - None - } + PathResolution::BuiltinAttr(_) + | PathResolution::ToolModule(_) + | PathResolution::Local(_) + | PathResolution::Macro(_) + | PathResolution::ConstParam(_) => None, PathResolution::TypeParam(param) => Some(TypeNs::GenericParam((*param).into())), PathResolution::SelfType(impl_def) => Some(TypeNs::SelfType((*impl_def).into())), PathResolution::AssocItem(AssocItem::Const(_) | AssocItem::Function(_)) => None, @@ -143,6 +147,10 @@ pub fn parse(&self, file_id: FileId) -> ast::SourceFile { self.imp.parse(file_id) } + pub fn parse_or_expand(&self, file_id: HirFileId) -> Option { + self.imp.parse_or_expand(file_id) + } + pub fn expand(&self, macro_call: &ast::MacroCall) -> Option { self.imp.expand(macro_call) } @@ -330,10 +338,6 @@ pub fn resolve_path(&self, path: &ast::Path) -> Option { self.imp.resolve_path(path) } - pub fn resolve_path_as_macro(&self, path: &ast::Path) -> Option { - self.imp.resolve_path_as_macro(path) - } - pub fn resolve_extern_crate(&self, extern_crate: &ast::ExternCrate) -> Option { self.imp.resolve_extern_crate(extern_crate) } @@ -416,6 +420,12 @@ fn parse(&self, file_id: FileId) -> ast::SourceFile { tree } + fn parse_or_expand(&self, file_id: HirFileId) -> Option { + let node = self.db.parse_or_expand(file_id)?; + self.cache(node.clone(), file_id); + Some(node) + } + fn expand(&self, macro_call: &ast::MacroCall) -> Option { let sa = self.analyze(macro_call.syntax()); let file_id = sa.expand(self.db, InFile::new(sa.file_id, macro_call))?; @@ -850,12 +860,6 @@ fn resolve_path(&self, path: &ast::Path) -> Option { self.analyze(path.syntax()).resolve_path(self.db, path) } - // FIXME: This shouldn't exist, but is currently required to always resolve attribute paths in - // the IDE layer due to namespace collisions - fn resolve_path_as_macro(&self, path: &ast::Path) -> Option { - self.analyze(path.syntax()).resolve_path_as_macro(self.db, path) - } - fn resolve_extern_crate(&self, extern_crate: &ast::ExternCrate) -> Option { let krate = self.scope(extern_crate.syntax()).krate()?; krate.dependencies(self.db).into_iter().find_map(|dep| { @@ -1160,8 +1164,7 @@ pub fn krate(&self) -> Option { } /// Note: `FxHashSet` should be treated as an opaque type, passed into `Type - // FIXME: rename to visible_traits to not repeat scope? - pub fn traits_in_scope(&self) -> FxHashSet { + pub fn visible_traits(&self) -> FxHashSet { let resolver = &self.resolver; resolver.traits_in_scope(self.db.upcast()) }