Skip to content

Commit aa1788d

Browse files
committed
clarify semantics of doc links
1 parent f9e06e6 commit aa1788d

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

crates/hir/src/attrs.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use hir_def::{
1111
};
1212
use hir_expand::{hygiene::Hygiene, MacroDefId};
1313
use hir_ty::db::HirDatabase;
14-
use syntax::ast;
14+
use syntax::{ast, AstNode};
1515

1616
use crate::{
1717
Adt, AssocItem, Const, ConstParam, Enum, Field, Function, GenericParam, Impl, LifetimeParam,
@@ -147,8 +147,18 @@ fn resolve_doc_path(
147147
// FIXME
148148
AttrDefId::MacroDefId(_) => return None,
149149
};
150-
let path = ast::Path::parse(link).ok()?;
151-
let modpath = ModPath::from_src(db.upcast(), path, &Hygiene::new_unhygienic())?;
150+
151+
let modpath = {
152+
let ast_path = ast::SourceFile::parse(&format!("type T = {};", link))
153+
.syntax_node()
154+
.descendants()
155+
.find_map(ast::Path::cast)?;
156+
if ast_path.to_string() != link {
157+
return None;
158+
}
159+
ModPath::from_src(db.upcast(), ast_path, &Hygiene::new_unhygienic())?
160+
};
161+
152162
let resolved = resolver.resolve_module_path_in_items(db.upcast(), &modpath);
153163
let resolved = if resolved == PerNs::none() {
154164
resolver.resolve_module_path_in_trait_assoc_items(db.upcast(), &modpath)?

0 commit comments

Comments
 (0)