X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Ftools%2Frust-analyzer%2Fcrates%2Fhir%2Fsrc%2Fsemantics.rs;h=c84318b2fb8774123dbe91b69df2aae53da34547;hb=30a370678603ce8cdc47c91a09f335533119d4dd;hp=fc8f23f19ab9112839303e2f33c022e056567891;hpb=110777b60c0c02a9bb62c6ffc081dc276de81210;p=rust.git diff --git a/src/tools/rust-analyzer/crates/hir/src/semantics.rs b/src/tools/rust-analyzer/crates/hir/src/semantics.rs index fc8f23f19ab..c84318b2fb8 100644 --- a/src/tools/rust-analyzer/crates/hir/src/semantics.rs +++ b/src/tools/rust-analyzer/crates/hir/src/semantics.rs @@ -324,6 +324,10 @@ pub fn resolve_type(&self, ty: &ast::Type) -> Option { self.imp.resolve_type(ty) } + pub fn resolve_trait(&self, trait_: &ast::Path) -> Option { + self.imp.resolve_trait(trait_) + } + // FIXME: Figure out a nice interface to inspect adjustments pub fn is_implicit_reborrow(&self, expr: &ast::Expr) -> Option { self.imp.is_implicit_reborrow(expr) @@ -924,7 +928,12 @@ fn original_range_opt(&self, node: &SyntaxNode) -> Option { } fn original_ast_node(&self, node: N) -> Option { - self.wrap_node_infile(node).original_ast_node(self.db.upcast()).map(|it| it.value) + self.wrap_node_infile(node).original_ast_node(self.db.upcast()).map( + |InFile { file_id, value }| { + self.cache(find_root(value.syntax()), file_id); + value + }, + ) } fn diagnostics_display_range(&self, src: InFile) -> FileRange { @@ -1009,6 +1018,20 @@ fn resolve_type(&self, ty: &ast::Type) -> Option { Some(Type::new_with_resolver(self.db, &analyze.resolver, ty)) } + fn resolve_trait(&self, path: &ast::Path) -> Option { + let analyze = self.analyze(path.syntax())?; + let hygiene = hir_expand::hygiene::Hygiene::new(self.db.upcast(), analyze.file_id); + let ctx = body::LowerCtx::with_hygiene(self.db.upcast(), &hygiene); + let hir_path = Path::from_src(path.clone(), &ctx)?; + match analyze + .resolver + .resolve_path_in_type_ns_fully(self.db.upcast(), hir_path.mod_path())? + { + TypeNs::TraitId(id) => Some(Trait { id }), + _ => None, + } + } + fn is_implicit_reborrow(&self, expr: &ast::Expr) -> Option { self.analyze(expr.syntax())?.is_implicit_reborrow(self.db, expr) }