Skip to content

Commit 3ddd8b2

Browse files
committed
Return all impls, not just the primary one
1 parent 8a0aa7b commit 3ddd8b2

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4106,6 +4106,7 @@ dependencies = [
41064106
"rustc-rayon",
41074107
"serde",
41084108
"serde_json",
4109+
"smallvec 1.4.0",
41094110
"tempfile",
41104111
]
41114112

src/librustdoc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ minifier = "0.0.33"
1414
rayon = { version = "0.3.0", package = "rustc-rayon" }
1515
serde = { version = "1.0", features = ["derive"] }
1616
serde_json = "1.0"
17+
smallvec = "1.0"
1718
tempfile = "3"
1819
itertools = "0.8"

src/librustdoc/clean/utils.rs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc_middle::mir::interpret::{sign_extend, ConstValue, Scalar};
1717
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
1818
use rustc_middle::ty::{self, DefIdTree, Ty, TyCtxt};
1919
use rustc_span::symbol::{kw, sym, Symbol};
20+
use smallvec::SmallVec;
2021
use std::mem;
2122

2223
pub fn krate(mut cx: &mut DocContext<'_>) -> Crate {
@@ -350,11 +351,14 @@ pub fn qpath_to_string(p: &hir::QPath<'_>) -> String {
350351
s
351352
}
352353

353-
pub fn impl_for_type(tcx: TyCtxt<'_>, primitive: PrimitiveType) -> Option<DefId> {
354+
pub fn impl_for_type(tcx: TyCtxt<'_>, primitive: PrimitiveType) -> SmallVec<[DefId; 4]> {
354355
use self::PrimitiveType::*;
355356

357+
let both =
358+
|a: Option<DefId>, b: Option<DefId>| -> SmallVec<_> { a.into_iter().chain(b).collect() };
359+
356360
let lang_items = tcx.lang_items();
357-
match primitive {
361+
let primary_impl = match primitive {
358362
Isize => lang_items.isize_impl(),
359363
I8 => lang_items.i8_impl(),
360364
I16 => lang_items.i16_impl(),
@@ -367,20 +371,38 @@ pub fn impl_for_type(tcx: TyCtxt<'_>, primitive: PrimitiveType) -> Option<DefId>
367371
U32 => lang_items.u32_impl(),
368372
U64 => lang_items.u64_impl(),
369373
U128 => lang_items.u128_impl(),
370-
F32 => lang_items.f32_impl(),
371-
F64 => lang_items.f64_impl(),
374+
F32 => return both(lang_items.f32_impl(), lang_items.f32_runtime_impl()),
375+
F64 => return both(lang_items.f64_impl(), lang_items.f64_runtime_impl()),
372376
Char => lang_items.char_impl(),
373377
Bool => lang_items.bool_impl(),
374-
Str => lang_items.str_impl(),
375-
Slice => lang_items.slice_impl(),
378+
Str => return both(lang_items.str_impl(), lang_items.str_alloc_impl()),
379+
Slice => {
380+
return lang_items
381+
.slice_impl()
382+
.into_iter()
383+
.chain(lang_items.slice_u8_impl())
384+
.chain(lang_items.slice_alloc_impl())
385+
.chain(lang_items.slice_u8_alloc_impl())
386+
.collect();
387+
}
376388
Array => lang_items.array_impl(),
377389
Tuple => None,
378390
Unit => None,
379-
RawPointer => lang_items.const_ptr_impl(),
391+
RawPointer => {
392+
return lang_items
393+
.const_ptr_impl()
394+
.into_iter()
395+
.chain(lang_items.mut_ptr_impl())
396+
.chain(lang_items.const_slice_ptr_impl())
397+
.chain(lang_items.mut_slice_ptr_impl())
398+
.collect();
399+
}
380400
Reference => None,
381401
Fn => None,
382402
Never => None,
383-
}
403+
};
404+
405+
primary_impl.into_iter().collect()
384406
}
385407

386408
pub fn build_deref_target_impls(cx: &DocContext<'_>, items: &[Item], ret: &mut Vec<Item>) {
@@ -402,8 +424,7 @@ pub fn build_deref_target_impls(cx: &DocContext<'_>, items: &[Item], ret: &mut V
402424
None => continue,
403425
},
404426
};
405-
let did = impl_for_type(tcx, primitive);
406-
if let Some(did) = did {
427+
for did in impl_for_type(tcx, primitive) {
407428
if !did.is_local() {
408429
inline::build_impl(cx, did, None, ret);
409430
}

0 commit comments

Comments
 (0)