Skip to content

Commit 06d6d3d

Browse files
committed
impl_for_type -> PrimitiveType::impls
1 parent 3ddd8b2 commit 06d6d3d

File tree

2 files changed

+59
-57
lines changed

2 files changed

+59
-57
lines changed

src/librustdoc/clean/types.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ use rustc_hir::lang_items;
1919
use rustc_hir::Mutability;
2020
use rustc_index::vec::IndexVec;
2121
use rustc_middle::middle::stability;
22+
use rustc_middle::ty::TyCtxt;
2223
use rustc_span::hygiene::MacroKind;
2324
use rustc_span::source_map::DUMMY_SP;
2425
use rustc_span::symbol::{kw, sym, Ident, Symbol};
2526
use rustc_span::{self, FileName};
2627
use rustc_target::abi::VariantIdx;
2728
use rustc_target::spec::abi::Abi;
29+
use smallvec::SmallVec;
2830

2931
use crate::clean::cfg::Cfg;
3032
use crate::clean::external_path;
@@ -1264,6 +1266,61 @@ impl PrimitiveType {
12641266
}
12651267
}
12661268

1269+
pub fn impls(&self, tcx: TyCtxt<'_>) -> SmallVec<[DefId; 4]> {
1270+
use self::PrimitiveType::*;
1271+
1272+
let both =
1273+
|a: Option<DefId>, b: Option<DefId>| -> SmallVec<_> { a.into_iter().chain(b).collect() };
1274+
1275+
let lang_items = tcx.lang_items();
1276+
let primary_impl = match self {
1277+
Isize => lang_items.isize_impl(),
1278+
I8 => lang_items.i8_impl(),
1279+
I16 => lang_items.i16_impl(),
1280+
I32 => lang_items.i32_impl(),
1281+
I64 => lang_items.i64_impl(),
1282+
I128 => lang_items.i128_impl(),
1283+
Usize => lang_items.usize_impl(),
1284+
U8 => lang_items.u8_impl(),
1285+
U16 => lang_items.u16_impl(),
1286+
U32 => lang_items.u32_impl(),
1287+
U64 => lang_items.u64_impl(),
1288+
U128 => lang_items.u128_impl(),
1289+
F32 => return both(lang_items.f32_impl(), lang_items.f32_runtime_impl()),
1290+
F64 => return both(lang_items.f64_impl(), lang_items.f64_runtime_impl()),
1291+
Char => lang_items.char_impl(),
1292+
Bool => lang_items.bool_impl(),
1293+
Str => return both(lang_items.str_impl(), lang_items.str_alloc_impl()),
1294+
Slice => {
1295+
return lang_items
1296+
.slice_impl()
1297+
.into_iter()
1298+
.chain(lang_items.slice_u8_impl())
1299+
.chain(lang_items.slice_alloc_impl())
1300+
.chain(lang_items.slice_u8_alloc_impl())
1301+
.collect();
1302+
}
1303+
Array => lang_items.array_impl(),
1304+
Tuple => None,
1305+
Unit => None,
1306+
RawPointer => {
1307+
return lang_items
1308+
.const_ptr_impl()
1309+
.into_iter()
1310+
.chain(lang_items.mut_ptr_impl())
1311+
.chain(lang_items.const_slice_ptr_impl())
1312+
.chain(lang_items.mut_slice_ptr_impl())
1313+
.collect();
1314+
}
1315+
Reference => None,
1316+
Fn => None,
1317+
Never => None,
1318+
};
1319+
1320+
primary_impl.into_iter().collect()
1321+
}
1322+
1323+
12671324
pub fn to_url_str(&self) -> &'static str {
12681325
self.as_str()
12691326
}

src/librustdoc/clean/utils.rs

Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ use rustc_hir::def::{DefKind, Res};
1515
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
1616
use rustc_middle::mir::interpret::{sign_extend, ConstValue, Scalar};
1717
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
18-
use rustc_middle::ty::{self, DefIdTree, Ty, TyCtxt};
18+
use rustc_middle::ty::{self, DefIdTree, Ty};
1919
use rustc_span::symbol::{kw, sym, Symbol};
20-
use smallvec::SmallVec;
2120
use std::mem;
2221

2322
pub fn krate(mut cx: &mut DocContext<'_>) -> Crate {
@@ -351,60 +350,6 @@ pub fn qpath_to_string(p: &hir::QPath<'_>) -> String {
351350
s
352351
}
353352

354-
pub fn impl_for_type(tcx: TyCtxt<'_>, primitive: PrimitiveType) -> SmallVec<[DefId; 4]> {
355-
use self::PrimitiveType::*;
356-
357-
let both =
358-
|a: Option<DefId>, b: Option<DefId>| -> SmallVec<_> { a.into_iter().chain(b).collect() };
359-
360-
let lang_items = tcx.lang_items();
361-
let primary_impl = match primitive {
362-
Isize => lang_items.isize_impl(),
363-
I8 => lang_items.i8_impl(),
364-
I16 => lang_items.i16_impl(),
365-
I32 => lang_items.i32_impl(),
366-
I64 => lang_items.i64_impl(),
367-
I128 => lang_items.i128_impl(),
368-
Usize => lang_items.usize_impl(),
369-
U8 => lang_items.u8_impl(),
370-
U16 => lang_items.u16_impl(),
371-
U32 => lang_items.u32_impl(),
372-
U64 => lang_items.u64_impl(),
373-
U128 => lang_items.u128_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()),
376-
Char => lang_items.char_impl(),
377-
Bool => lang_items.bool_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-
}
388-
Array => lang_items.array_impl(),
389-
Tuple => None,
390-
Unit => None,
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-
}
400-
Reference => None,
401-
Fn => None,
402-
Never => None,
403-
};
404-
405-
primary_impl.into_iter().collect()
406-
}
407-
408353
pub fn build_deref_target_impls(cx: &DocContext<'_>, items: &[Item], ret: &mut Vec<Item>) {
409354
let tcx = cx.tcx;
410355

@@ -424,7 +369,7 @@ pub fn build_deref_target_impls(cx: &DocContext<'_>, items: &[Item], ret: &mut V
424369
None => continue,
425370
},
426371
};
427-
for did in impl_for_type(tcx, primitive) {
372+
for did in primitive.impls(tcx) {
428373
if !did.is_local() {
429374
inline::build_impl(cx, did, None, ret);
430375
}

0 commit comments

Comments
 (0)