Skip to content

Commit a86a740

Browse files
committed
Use DiagnosticInfo for report_diagnostic
1 parent 661acbc commit a86a740

File tree

1 file changed

+29
-39
lines changed

1 file changed

+29
-39
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+29-39
Original file line numberDiff line numberDiff line change
@@ -1144,15 +1144,7 @@ impl LinkCollector<'_, '_> {
11441144
diag.note(&note);
11451145
suggest_disambiguator(resolved, diag, path_str, dox, sp, &ori_link.range);
11461146
};
1147-
report_diagnostic(
1148-
self.cx.tcx,
1149-
BROKEN_INTRA_DOC_LINKS,
1150-
&msg,
1151-
&item,
1152-
dox,
1153-
&ori_link.range,
1154-
callback,
1155-
);
1147+
report_diagnostic(self.cx.tcx, BROKEN_INTRA_DOC_LINKS, &msg, &diag_info, callback);
11561148
};
11571149

11581150
let verify = |kind: DefKind, id: DefId| {
@@ -1192,7 +1184,7 @@ impl LinkCollector<'_, '_> {
11921184
if self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_src)
11931185
&& !self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_dst)
11941186
{
1195-
privacy_error(self.cx, diag_info, &path_str);
1187+
privacy_error(self.cx, &diag_info, &path_str);
11961188
}
11971189
}
11981190

@@ -1665,9 +1657,7 @@ fn report_diagnostic(
16651657
tcx: TyCtxt<'_>,
16661658
lint: &'static Lint,
16671659
msg: &str,
1668-
item: &Item,
1669-
dox: &str,
1670-
link_range: &Range<usize>,
1660+
DiagnosticInfo { item, ori_link: _, dox, link_range }: &DiagnosticInfo<'_>,
16711661
decorate: impl FnOnce(&mut DiagnosticBuilder<'_>, Option<rustc_span::Span>),
16721662
) {
16731663
let hir_id = match DocContext::as_local_hir_id(tcx, item.def_id) {
@@ -1721,7 +1711,7 @@ fn report_diagnostic(
17211711
/// `std::io::Error::x`, this will resolve `std::io::Error`.
17221712
fn resolution_failure(
17231713
collector: &mut LinkCollector<'_, '_>,
1724-
DiagnosticInfo { item, ori_link: _, dox, link_range }: DiagnosticInfo<'_>,
1714+
diag_info: DiagnosticInfo<'_>,
17251715
path_str: &str,
17261716
disambiguator: Option<Disambiguator>,
17271717
kinds: SmallVec<[ResolutionFailure<'_>; 3]>,
@@ -1731,9 +1721,7 @@ fn resolution_failure(
17311721
tcx,
17321722
BROKEN_INTRA_DOC_LINKS,
17331723
&format!("unresolved link to `{}`", path_str),
1734-
item,
1735-
dox,
1736-
&link_range,
1724+
&diag_info,
17371725
|diag, sp| {
17381726
let item = |res: Res| format!("the {} `{}`", res.descr(), res.name(tcx),);
17391727
let assoc_item_not_allowed = |res: Res| {
@@ -1893,9 +1881,9 @@ fn resolution_failure(
18931881
disambiguator,
18941882
diag,
18951883
path_str,
1896-
dox,
1884+
diag_info.dox,
18971885
sp,
1898-
&link_range,
1886+
&diag_info.link_range,
18991887
)
19001888
}
19011889

@@ -1942,21 +1930,19 @@ fn resolution_failure(
19421930
}
19431931

19441932
/// Report an anchor failure.
1945-
fn anchor_failure(
1946-
cx: &DocContext<'_>,
1947-
DiagnosticInfo { item, ori_link, dox, link_range }: DiagnosticInfo<'_>,
1948-
failure: AnchorFailure,
1949-
) {
1933+
fn anchor_failure(cx: &DocContext<'_>, diag_info: DiagnosticInfo<'_>, failure: AnchorFailure) {
19501934
let msg = match failure {
1951-
AnchorFailure::MultipleAnchors => format!("`{}` contains multiple anchors", ori_link),
1935+
AnchorFailure::MultipleAnchors => {
1936+
format!("`{}` contains multiple anchors", diag_info.ori_link)
1937+
}
19521938
AnchorFailure::RustdocAnchorConflict(res) => format!(
19531939
"`{}` contains an anchor, but links to {kind}s are already anchored",
1954-
ori_link,
1940+
diag_info.ori_link,
19551941
kind = res.descr(),
19561942
),
19571943
};
19581944

1959-
report_diagnostic(cx.tcx, BROKEN_INTRA_DOC_LINKS, &msg, item, dox, &link_range, |diag, sp| {
1945+
report_diagnostic(cx.tcx, BROKEN_INTRA_DOC_LINKS, &msg, &diag_info, |diag, sp| {
19601946
if let Some(sp) = sp {
19611947
diag.span_label(sp, "contains invalid anchor");
19621948
}
@@ -1966,17 +1952,18 @@ fn anchor_failure(
19661952
/// Report an error in the link disambiguator.
19671953
fn disambiguator_error(
19681954
cx: &DocContext<'_>,
1969-
DiagnosticInfo { item, ori_link: _, dox, link_range: _ }: DiagnosticInfo<'_>,
1955+
mut diag_info: DiagnosticInfo<'_>,
19701956
disambiguator_range: Range<usize>,
19711957
msg: &str,
19721958
) {
1973-
report_diagnostic(cx.tcx, BROKEN_INTRA_DOC_LINKS, msg, item, dox, &disambiguator_range, |_diag, _sp| {});
1959+
diag_info.link_range = disambiguator_range;
1960+
report_diagnostic(cx.tcx, BROKEN_INTRA_DOC_LINKS, msg, &diag_info, |_diag, _sp| {});
19741961
}
19751962

19761963
/// Report an ambiguity error, where there were multiple possible resolutions.
19771964
fn ambiguity_error(
19781965
cx: &DocContext<'_>,
1979-
DiagnosticInfo { item, ori_link: _, dox, link_range }: DiagnosticInfo<'_>,
1966+
diag_info: DiagnosticInfo<'_>,
19801967
path_str: &str,
19811968
candidates: Vec<Res>,
19821969
) {
@@ -2004,7 +1991,7 @@ fn ambiguity_error(
20041991
}
20051992
}
20061993

2007-
report_diagnostic(cx.tcx, BROKEN_INTRA_DOC_LINKS, &msg, item, dox, &link_range, |diag, sp| {
1994+
report_diagnostic(cx.tcx, BROKEN_INTRA_DOC_LINKS, &msg, &diag_info, |diag, sp| {
20081995
if let Some(sp) = sp {
20091996
diag.span_label(sp, "ambiguous link");
20101997
} else {
@@ -2013,7 +2000,14 @@ fn ambiguity_error(
20132000

20142001
for res in candidates {
20152002
let disambiguator = Disambiguator::from_res(res);
2016-
suggest_disambiguator(disambiguator, diag, path_str, dox, sp, &link_range);
2003+
suggest_disambiguator(
2004+
disambiguator,
2005+
diag,
2006+
path_str,
2007+
diag_info.dox,
2008+
sp,
2009+
&diag_info.link_range,
2010+
);
20172011
}
20182012
});
20192013
}
@@ -2045,13 +2039,9 @@ fn suggest_disambiguator(
20452039
}
20462040

20472041
/// Report a link from a public item to a private one.
2048-
fn privacy_error(
2049-
cx: &DocContext<'_>,
2050-
DiagnosticInfo { item, ori_link: _, dox, link_range }: DiagnosticInfo<'_>,
2051-
path_str: &str,
2052-
) {
2042+
fn privacy_error(cx: &DocContext<'_>, diag_info: &DiagnosticInfo<'_>, path_str: &str) {
20532043
let sym;
2054-
let item_name = match item.name {
2044+
let item_name = match diag_info.item.name {
20552045
Some(name) => {
20562046
sym = name.as_str();
20572047
&*sym
@@ -2061,7 +2051,7 @@ fn privacy_error(
20612051
let msg =
20622052
format!("public documentation for `{}` links to private item `{}`", item_name, path_str);
20632053

2064-
report_diagnostic(cx.tcx, PRIVATE_INTRA_DOC_LINKS, &msg, item, dox, &link_range, |diag, sp| {
2054+
report_diagnostic(cx.tcx, PRIVATE_INTRA_DOC_LINKS, &msg, diag_info, |diag, sp| {
20652055
if let Some(sp) = sp {
20662056
diag.span_label(sp, "this item is private");
20672057
}

0 commit comments

Comments
 (0)