From aa1788dc717a856a409ec76759783ad59c47bd49 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 28 Dec 2021 15:48:07 +0300 Subject: [PATCH] clarify semantics of doc links --- crates/hir/src/attrs.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/crates/hir/src/attrs.rs b/crates/hir/src/attrs.rs index 54e95cf7c3d..46e9c54dad6 100644 --- a/crates/hir/src/attrs.rs +++ b/crates/hir/src/attrs.rs @@ -11,7 +11,7 @@ use hir_def::{ }; use hir_expand::{hygiene::Hygiene, MacroDefId}; use hir_ty::db::HirDatabase; -use syntax::ast; +use syntax::{ast, AstNode}; use crate::{ Adt, AssocItem, Const, ConstParam, Enum, Field, Function, GenericParam, Impl, LifetimeParam, @@ -147,8 +147,18 @@ fn resolve_doc_path( // FIXME AttrDefId::MacroDefId(_) => return None, }; - let path = ast::Path::parse(link).ok()?; - let modpath = ModPath::from_src(db.upcast(), path, &Hygiene::new_unhygienic())?; + + let modpath = { + let ast_path = ast::SourceFile::parse(&format!("type T = {};", link)) + .syntax_node() + .descendants() + .find_map(ast::Path::cast)?; + if ast_path.to_string() != link { + return None; + } + ModPath::from_src(db.upcast(), ast_path, &Hygiene::new_unhygienic())? + }; + let resolved = resolver.resolve_module_path_in_items(db.upcast(), &modpath); let resolved = if resolved == PerNs::none() { resolver.resolve_module_path_in_trait_assoc_items(db.upcast(), &modpath)?