Skip to content

Commit 219e93d

Browse files
committed
Use impls for intra doc links as well
1 parent 9cf2fa8 commit 219e93d

File tree

3 files changed

+20
-36
lines changed

3 files changed

+20
-36
lines changed

Cargo.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -4106,7 +4106,7 @@ dependencies = [
41064106
"rustc-rayon",
41074107
"serde",
41084108
"serde_json",
4109-
"smallvec 1.4.0",
4109+
"smallvec 1.4.2",
41104110
"tempfile",
41114111
]
41124112

src/librustdoc/clean/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@ impl PrimitiveType {
12671267
}
12681268
}
12691269

1270-
pub fn impls(&self, tcx: TyCtxt<'_>) -> &SmallVec<[DefId; 4]> {
1270+
pub fn impls(&self, tcx: TyCtxt<'_>) -> &'static SmallVec<[DefId; 4]> {
12711271
Self::all_impls(tcx).get(self).expect("missing impl for primitive type")
12721272
}
12731273

src/librustdoc/passes/collect_intra_doc_links.rs

+18-34
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc_span::hygiene::MacroKind;
1616
use rustc_span::symbol::Ident;
1717
use rustc_span::symbol::Symbol;
1818
use rustc_span::DUMMY_SP;
19+
use smallvec::SmallVec;
1920

2021
use std::cell::Cell;
2122
use std::ops::Range;
@@ -270,18 +271,21 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
270271
.ok_or(ErrorKind::ResolutionFailure)?;
271272

272273
if let Some((path, prim)) = is_primitive(&path, TypeNS) {
273-
let did = primitive_impl(cx, &path).ok_or(ErrorKind::ResolutionFailure)?;
274-
return cx
275-
.tcx
276-
.associated_items(did)
277-
.filter_by_name_unhygienic(item_name)
278-
.next()
279-
.and_then(|item| match item.kind {
280-
ty::AssocKind::Fn => Some("method"),
281-
_ => None,
282-
})
283-
.map(|out| (prim, Some(format!("{}#{}.{}", path, out, item_name))))
284-
.ok_or(ErrorKind::ResolutionFailure);
274+
for &impl_ in primitive_impl(cx, &path).ok_or(ErrorKind::ResolutionFailure)? {
275+
let link = cx
276+
.tcx
277+
.associated_items(impl_)
278+
.find_by_name_and_namespace(cx.tcx, Ident::with_dummy_span(item_name), ns, impl_)
279+
.and_then(|item| match item.kind {
280+
ty::AssocKind::Fn => Some("method"),
281+
_ => None,
282+
})
283+
.map(|out| (prim, Some(format!("{}#{}.{}", path, out, item_name))));
284+
if let Some(link) = link {
285+
return Ok(link);
286+
}
287+
}
288+
return Err(ErrorKind::ResolutionFailure);
285289
}
286290

287291
let (_, ty_res) = cx
@@ -1238,26 +1242,6 @@ fn is_primitive(path_str: &str, ns: Namespace) -> Option<(&'static str, Res)> {
12381242
}
12391243
}
12401244

1241-
fn primitive_impl(cx: &DocContext<'_>, path_str: &str) -> Option<DefId> {
1242-
let tcx = cx.tcx;
1243-
match path_str {
1244-
"u8" => tcx.lang_items().u8_impl(),
1245-
"u16" => tcx.lang_items().u16_impl(),
1246-
"u32" => tcx.lang_items().u32_impl(),
1247-
"u64" => tcx.lang_items().u64_impl(),
1248-
"u128" => tcx.lang_items().u128_impl(),
1249-
"usize" => tcx.lang_items().usize_impl(),
1250-
"i8" => tcx.lang_items().i8_impl(),
1251-
"i16" => tcx.lang_items().i16_impl(),
1252-
"i32" => tcx.lang_items().i32_impl(),
1253-
"i64" => tcx.lang_items().i64_impl(),
1254-
"i128" => tcx.lang_items().i128_impl(),
1255-
"isize" => tcx.lang_items().isize_impl(),
1256-
"f32" => tcx.lang_items().f32_impl(),
1257-
"f64" => tcx.lang_items().f64_impl(),
1258-
"str" => tcx.lang_items().str_impl(),
1259-
"bool" => tcx.lang_items().bool_impl(),
1260-
"char" => tcx.lang_items().char_impl(),
1261-
_ => None,
1262-
}
1245+
fn primitive_impl(cx: &DocContext<'_>, path_str: &str) -> Option<&'static SmallVec<[DefId; 4]>> {
1246+
Some(PrimitiveType::from_symbol(Symbol::intern(path_str))?.impls(cx.tcx))
12631247
}

0 commit comments

Comments
 (0)