Skip to content
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

refactor(docs): remove macro resolution fallback #110881

Merged
merged 2 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
30 changes: 16 additions & 14 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,8 @@ impl LinkCollector<'_, '_> {
}
}
}
resolution_failure(self, diag, path_str, disambiguator, smallvec![err])
resolution_failure(self, diag, path_str, disambiguator, smallvec![err]);
return vec![];
}
}
}
Expand Down Expand Up @@ -1331,13 +1332,14 @@ impl LinkCollector<'_, '_> {
.fold(0, |acc, res| if let Ok(res) = res { acc + res.len() } else { acc });

if len == 0 {
return resolution_failure(
resolution_failure(
self,
diag,
path_str,
disambiguator,
candidates.into_iter().filter_map(|res| res.err()).collect(),
);
return vec![];
} else if len == 1 {
candidates.into_iter().filter_map(|res| res.ok()).flatten().collect::<Vec<_>>()
} else {
Expand Down Expand Up @@ -1642,9 +1644,8 @@ fn resolution_failure(
path_str: &str,
disambiguator: Option<Disambiguator>,
kinds: SmallVec<[ResolutionFailure<'_>; 3]>,
) -> Vec<(Res, Option<DefId>)> {
) {
let tcx = collector.cx.tcx;
let mut recovered_res = None;
report_diagnostic(
tcx,
BROKEN_INTRA_DOC_LINKS,
Expand Down Expand Up @@ -1736,19 +1737,25 @@ fn resolution_failure(

if !path_str.contains("::") {
if disambiguator.map_or(true, |d| d.ns() == MacroNS)
&& let Some(&res) = collector.cx.tcx.resolutions(()).all_macro_rules
.get(&Symbol::intern(path_str))
&& collector
.cx
.tcx
.resolutions(())
.all_macro_rules
.get(&Symbol::intern(path_str))
.is_some()
{
diag.note(format!(
"`macro_rules` named `{path_str}` exists in this crate, \
but it is not in scope at this link's location"
bvanjoi marked this conversation as resolved.
Show resolved Hide resolved
));
recovered_res = res.try_into().ok().map(|res| (res, None));
} else {
// If the link has `::` in it, assume it was meant to be an
// intra-doc link. Otherwise, the `[]` might be unrelated.
diag.help("to escape `[` and `]` characters, \
add '\\' before them like `\\[` or `\\]`");
diag.help(
"to escape `[` and `]` characters, \
add '\\' before them like `\\[` or `\\]`",
);
}
}

Expand Down Expand Up @@ -1854,11 +1861,6 @@ fn resolution_failure(
}
},
);

match recovered_res {
Some(r) => vec![r],
None => Vec::new(),
}
}

fn report_multiple_anchors(cx: &DocContext<'_>, diag_info: DiagnosticInfo<'_>) {
Expand Down
14 changes: 14 additions & 0 deletions tests/rustdoc/issue-106142.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @has 'issue_106142/a/index.html'
// @count 'issue_106142/a/index.html' '//ul[@class="item-table"]//li//a' 1

#![allow(rustdoc::broken_intra_doc_links)]

pub mod a {
/// [`m`]
pub fn f() {}

#[macro_export]
macro_rules! m {
() => {};
}
}