Use impls
for intra doc links as well
This commit is contained in:
parent
9cf2fa84e8
commit
219e93d91e
3 changed files with 20 additions and 36 deletions
|
@ -4106,7 +4106,7 @@ dependencies = [
|
||||||
"rustc-rayon",
|
"rustc-rayon",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"smallvec 1.4.0",
|
"smallvec 1.4.2",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -1267,7 +1267,7 @@ impl PrimitiveType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn impls(&self, tcx: TyCtxt<'_>) -> &SmallVec<[DefId; 4]> {
|
pub fn impls(&self, tcx: TyCtxt<'_>) -> &'static SmallVec<[DefId; 4]> {
|
||||||
Self::all_impls(tcx).get(self).expect("missing impl for primitive type")
|
Self::all_impls(tcx).get(self).expect("missing impl for primitive type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ use rustc_span::hygiene::MacroKind;
|
||||||
use rustc_span::symbol::Ident;
|
use rustc_span::symbol::Ident;
|
||||||
use rustc_span::symbol::Symbol;
|
use rustc_span::symbol::Symbol;
|
||||||
use rustc_span::DUMMY_SP;
|
use rustc_span::DUMMY_SP;
|
||||||
|
use smallvec::SmallVec;
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
|
@ -270,18 +271,21 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
|
||||||
.ok_or(ErrorKind::ResolutionFailure)?;
|
.ok_or(ErrorKind::ResolutionFailure)?;
|
||||||
|
|
||||||
if let Some((path, prim)) = is_primitive(&path, TypeNS) {
|
if let Some((path, prim)) = is_primitive(&path, TypeNS) {
|
||||||
let did = primitive_impl(cx, &path).ok_or(ErrorKind::ResolutionFailure)?;
|
for &impl_ in primitive_impl(cx, &path).ok_or(ErrorKind::ResolutionFailure)? {
|
||||||
return cx
|
let link = cx
|
||||||
.tcx
|
.tcx
|
||||||
.associated_items(did)
|
.associated_items(impl_)
|
||||||
.filter_by_name_unhygienic(item_name)
|
.find_by_name_and_namespace(cx.tcx, Ident::with_dummy_span(item_name), ns, impl_)
|
||||||
.next()
|
|
||||||
.and_then(|item| match item.kind {
|
.and_then(|item| match item.kind {
|
||||||
ty::AssocKind::Fn => Some("method"),
|
ty::AssocKind::Fn => Some("method"),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.map(|out| (prim, Some(format!("{}#{}.{}", path, out, item_name))))
|
.map(|out| (prim, Some(format!("{}#{}.{}", path, out, item_name))));
|
||||||
.ok_or(ErrorKind::ResolutionFailure);
|
if let Some(link) = link {
|
||||||
|
return Ok(link);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Err(ErrorKind::ResolutionFailure);
|
||||||
}
|
}
|
||||||
|
|
||||||
let (_, ty_res) = cx
|
let (_, ty_res) = cx
|
||||||
|
@ -1238,26 +1242,6 @@ fn is_primitive(path_str: &str, ns: Namespace) -> Option<(&'static str, Res)> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn primitive_impl(cx: &DocContext<'_>, path_str: &str) -> Option<DefId> {
|
fn primitive_impl(cx: &DocContext<'_>, path_str: &str) -> Option<&'static SmallVec<[DefId; 4]>> {
|
||||||
let tcx = cx.tcx;
|
Some(PrimitiveType::from_symbol(Symbol::intern(path_str))?.impls(cx.tcx))
|
||||||
match path_str {
|
|
||||||
"u8" => tcx.lang_items().u8_impl(),
|
|
||||||
"u16" => tcx.lang_items().u16_impl(),
|
|
||||||
"u32" => tcx.lang_items().u32_impl(),
|
|
||||||
"u64" => tcx.lang_items().u64_impl(),
|
|
||||||
"u128" => tcx.lang_items().u128_impl(),
|
|
||||||
"usize" => tcx.lang_items().usize_impl(),
|
|
||||||
"i8" => tcx.lang_items().i8_impl(),
|
|
||||||
"i16" => tcx.lang_items().i16_impl(),
|
|
||||||
"i32" => tcx.lang_items().i32_impl(),
|
|
||||||
"i64" => tcx.lang_items().i64_impl(),
|
|
||||||
"i128" => tcx.lang_items().i128_impl(),
|
|
||||||
"isize" => tcx.lang_items().isize_impl(),
|
|
||||||
"f32" => tcx.lang_items().f32_impl(),
|
|
||||||
"f64" => tcx.lang_items().f64_impl(),
|
|
||||||
"str" => tcx.lang_items().str_impl(),
|
|
||||||
"bool" => tcx.lang_items().bool_impl(),
|
|
||||||
"char" => tcx.lang_items().char_impl(),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue