Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir/src/semantics.rs')
-rw-r--r--crates/hir/src/semantics.rs24
1 files changed, 14 insertions, 10 deletions
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs
index a03ff22074..fdc604a006 100644
--- a/crates/hir/src/semantics.rs
+++ b/crates/hir/src/semantics.rs
@@ -13,7 +13,6 @@ use either::Either;
use hir_def::{
hir::Expr,
lower::LowerCtx,
- macro_id_to_def_id,
nameres::MacroSubNs,
resolver::{self, HasResolver, Resolver, TypeNs},
type_ref::Mutability,
@@ -40,8 +39,8 @@ use crate::{
source_analyzer::{resolve_hir_path, SourceAnalyzer},
Access, Adjust, Adjustment, AutoBorrow, BindingMode, BuiltinAttr, Callable, ConstParam, Crate,
DeriveHelper, Field, Function, HasSource, HirFileId, Impl, InFile, Label, LifetimeParam, Local,
- Macro, Module, ModuleDef, Name, OverloadedDeref, Path, ScopeDef, ToolModule, Trait, Type,
- TypeAlias, TypeParam, VariantDef,
+ Macro, Module, ModuleDef, Name, OverloadedDeref, Path, ScopeDef, Struct, ToolModule, Trait,
+ Type, TypeAlias, TypeParam, VariantDef,
};
pub enum DescendPreference {
@@ -229,6 +228,14 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
pub fn to_module_defs(&self, file: FileId) -> impl Iterator<Item = Module> {
self.imp.to_module_def(file)
}
+
+ pub fn to_struct_def(&self, s: &ast::Struct) -> Option<Struct> {
+ self.imp.to_def(s).map(Struct::from)
+ }
+
+ pub fn to_impl_def(&self, i: &ast::Impl) -> Option<Impl> {
+ self.imp.to_def(i).map(Impl::from)
+ }
}
impl<'db> SemanticsImpl<'db> {
@@ -341,9 +348,7 @@ impl<'db> SemanticsImpl<'db> {
let macro_call = InFile::new(file_id, actual_macro_call);
let krate = resolver.krate();
let macro_call_id = macro_call.as_call_id(self.db.upcast(), krate, |path| {
- resolver
- .resolve_path_as_macro(self.db.upcast(), &path, Some(MacroSubNs::Bang))
- .map(|(it, _)| macro_id_to_def_id(self.db.upcast(), it))
+ resolver.resolve_path_as_macro_def(self.db.upcast(), &path, Some(MacroSubNs::Bang))
})?;
hir_expand::db::expand_speculative(
self.db.upcast(),
@@ -512,8 +517,7 @@ impl<'db> SemanticsImpl<'db> {
}
/// Descend the token into its macro call if it is part of one, returning the tokens in the
- /// expansion that it is associated with. If `offset` points into the token's range, it will
- /// be considered for the mapping in case of inline format args.
+ /// expansion that it is associated with.
pub fn descend_into_macros(
&self,
mode: DescendPreference,
@@ -674,7 +678,7 @@ impl<'db> SemanticsImpl<'db> {
_ => 0,
};
// FIXME: here, the attribute's text range is used to strip away all
- // entries from the start of the attribute "list" up the the invoking
+ // entries from the start of the attribute "list" up the invoking
// attribute. But in
// ```
// mod foo {
@@ -850,7 +854,7 @@ impl<'db> SemanticsImpl<'db> {
/// Attempts to map the node out of macro expanded files.
/// This only work for attribute expansions, as other ones do not have nodes as input.
pub fn original_ast_node<N: AstNode>(&self, node: N) -> Option<N> {
- self.wrap_node_infile(node).original_ast_node(self.db.upcast()).map(
+ self.wrap_node_infile(node).original_ast_node_rooted(self.db.upcast()).map(
|InRealFile { file_id, value }| {
self.cache(find_root(value.syntax()), file_id.into());
value