Skip to content

Commit f328ab0

Browse files
committed
rustdoc: linking to a local proc macro no longer warns
fixes #91274 tried to keep the fix general in case we ever have any other kind of item that occupies multiple namespaces simultaniously.
1 parent c79bbfa commit f328ab0

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

src/librustdoc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#![feature(test)]
1818
#![feature(type_alias_impl_trait)]
1919
#![feature(type_ascription)]
20+
#![feature(iterator_try_reduce)]
2021
#![recursion_limit = "256"]
2122
#![warn(rustc::internal)]
2223
#![allow(clippy::collapsible_if, clippy::collapsible_else_if)]

src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2219,6 +2219,16 @@ fn report_malformed_generics(
22192219
);
22202220
}
22212221

2222+
fn refer_to_single_item(v: &[Res]) -> bool {
2223+
// proc macros can exist in multiple namespaces at once,
2224+
// so we need to compare DefIds
2225+
v.iter().try_reduce(|l, r| match (l, r) {
2226+
(Res::Def(_, lid), Res::Def(_, rid)) if lid == rid =>
2227+
Some(l),
2228+
_ => None,
2229+
}).is_some()
2230+
}
2231+
22222232
/// Report an ambiguity error, where there were multiple possible resolutions.
22232233
///
22242234
/// If all `candidates` have the same kind, it's not possible to disambiguate so in this case,
@@ -2241,7 +2251,7 @@ fn ambiguity_error(
22412251
)
22422252
.filter(|res| descrs.insert(res.descr()))
22432253
.collect::<Vec<_>>();
2244-
if descrs.len() == 1 {
2254+
if descrs.len() == 1 || refer_to_single_item(&kinds) {
22452255
// There is no way for users to disambiguate at this point, so better return the first
22462256
// candidate and not show a warning.
22472257
return false;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ compile-flags: --crate-type=proc-macro
2+
//@ has 'foo/index.html' '//a[@href="macro.my_macro.html"]' 'my_macro'
3+
//! Link to [`my_macro`].
4+
#![crate_name = "foo"]
5+
6+
// regression test for https://github.com/rust-lang/rust/issues/91274
7+
8+
extern crate proc_macro;
9+
10+
#[proc_macro]
11+
pub fn my_macro(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
12+
input
13+
}

0 commit comments

Comments
 (0)