Skip to content

Use real Spans when resolving intra-doc links #78797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
module_id: DefId,
item_name: Symbol,
item_str: &'path str,
span: rustc_span::Span,
) -> Result<(Res, Option<String>), ErrorKind<'path>> {
let cx = self.cx;

Expand All @@ -303,12 +304,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
.find_map(|&impl_| {
cx.tcx
.associated_items(impl_)
.find_by_name_and_namespace(
cx.tcx,
Ident::with_dummy_span(item_name),
ns,
impl_,
)
.find_by_name_and_namespace(cx.tcx, Ident::new(item_name, span), ns, impl_)
.map(|item| match item.kind {
ty::AssocKind::Fn => "method",
ty::AssocKind::Const => "associatedconstant",
Expand Down Expand Up @@ -347,7 +343,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
module_id: DefId,
) -> Result<Res, ResolutionFailure<'a>> {
let cx = self.cx;
let path = ast::Path::from_ident(Ident::from_str(path_str));
let path = ast::Path::from_ident(Ident::from_str_and_span(path_str, span));
cx.enter_resolver(|resolver| {
// FIXME(jynelson): does this really need 3 separate lookups?
if let Ok((Some(ext), res)) = resolver.resolve_macro_path(
Expand Down Expand Up @@ -497,9 +493,11 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
};

let res = match ty_res {
Res::PrimTy(prim) => Some(
self.resolve_primitive_associated_item(prim, ns, module_id, item_name, item_str),
),
Res::PrimTy(prim) => {
Some(self.resolve_primitive_associated_item(
prim, ns, module_id, item_name, item_str, span,
))
}
Res::Def(DefKind::Struct | DefKind::Union | DefKind::Enum | DefKind::TyAlias, did) => {
debug!("looking for associated item named {} for item {:?}", item_name, did);
// Checks if item_name belongs to `impl SomeItem`
Expand All @@ -510,7 +508,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
.flat_map(|&imp| {
cx.tcx.associated_items(imp).find_by_name_and_namespace(
cx.tcx,
Ident::with_dummy_span(item_name),
Ident::new(item_name, span),
ns,
imp,
)
Expand All @@ -524,8 +522,9 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
// To handle that properly resolve() would have to support
// something like [`ambi_fn`](<SomeStruct as SomeTrait>::ambi_fn)
.or_else(|| {
let kind =
resolve_associated_trait_item(did, module_id, item_name, ns, &self.cx);
let kind = resolve_associated_trait_item(
did, module_id, item_name, span, ns, &self.cx,
);
debug!("got associated item kind {:?}", kind);
kind
});
Expand Down Expand Up @@ -593,7 +592,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
Res::Def(DefKind::Trait, did) => cx
.tcx
.associated_items(did)
.find_by_name_and_namespace(cx.tcx, Ident::with_dummy_span(item_name), ns, did)
.find_by_name_and_namespace(cx.tcx, Ident::new(item_name, span), ns, did)
.map(|item| {
let kind = match item.kind {
ty::AssocKind::Const => "associatedconstant",
Expand Down Expand Up @@ -674,6 +673,7 @@ fn resolve_associated_trait_item(
did: DefId,
module: DefId,
item_name: Symbol,
span: rustc_span::Span,
ns: Namespace,
cx: &DocContext<'_>,
) -> Option<(ty::AssocKind, DefId)> {
Expand Down Expand Up @@ -722,7 +722,7 @@ fn resolve_associated_trait_item(
.associated_items(trait_)
.find_by_name_and_namespace(
cx.tcx,
Ident::with_dummy_span(item_name),
Ident::new(item_name, span),
ns,
trait_,
)
Expand All @@ -742,7 +742,7 @@ fn resolve_associated_trait_item(
candidates.extend(traits.iter().filter_map(|&trait_| {
cx.tcx
.associated_items(trait_)
.find_by_name_and_namespace(cx.tcx, Ident::with_dummy_span(item_name), ns, trait_)
.find_by_name_and_namespace(cx.tcx, Ident::new(item_name, span), ns, trait_)
.map(|assoc| (assoc.kind, assoc.def_id))
}));
}
Expand Down