@@ -48,8 +48,6 @@ crate use self::types::Type::*;
48
48
crate use self::types::Visibility::{Inherited, Public};
49
49
crate use self::types::*;
50
50
51
- const FN_OUTPUT_NAME: &str = "Output";
52
-
53
51
crate trait Clean<T> {
54
52
fn clean(&self, cx: &DocContext<'_>) -> T;
55
53
}
@@ -329,10 +327,9 @@ impl Clean<GenericBound> for (ty::PolyTraitRef<'_>, &[TypeBinding]) {
329
327
.collect_referenced_late_bound_regions(&poly_trait_ref)
330
328
.into_iter()
331
329
.filter_map(|br| match br {
332
- ty::BrNamed(_, name) => Some(GenericParamDef {
333
- name: name.to_string(),
334
- kind: GenericParamDefKind::Lifetime,
335
- }),
330
+ ty::BrNamed(_, name) => {
331
+ Some(GenericParamDef { name, kind: GenericParamDefKind::Lifetime })
332
+ }
336
333
_ => None,
337
334
})
338
335
.collect();
@@ -546,7 +543,7 @@ impl<'tcx> Clean<Type> for ty::ProjectionTy<'tcx> {
546
543
GenericBound::Outlives(_) => panic!("cleaning a trait got a lifetime"),
547
544
};
548
545
Type::QPath {
549
- name: cx.tcx.associated_item(self.item_def_id).ident.name.clean(cx) ,
546
+ name: cx.tcx.associated_item(self.item_def_id).ident.name,
550
547
self_type: box self.self_ty().clean(cx),
551
548
trait_: box trait_,
552
549
}
@@ -556,14 +553,12 @@ impl<'tcx> Clean<Type> for ty::ProjectionTy<'tcx> {
556
553
impl Clean<GenericParamDef> for ty::GenericParamDef {
557
554
fn clean(&self, cx: &DocContext<'_>) -> GenericParamDef {
558
555
let (name, kind) = match self.kind {
559
- ty::GenericParamDefKind::Lifetime => {
560
- (self.name.to_string(), GenericParamDefKind::Lifetime)
561
- }
556
+ ty::GenericParamDefKind::Lifetime => (self.name, GenericParamDefKind::Lifetime),
562
557
ty::GenericParamDefKind::Type { has_default, synthetic, .. } => {
563
558
let default =
564
559
if has_default { Some(cx.tcx.type_of(self.def_id).clean(cx)) } else { None };
565
560
(
566
- self.name.clean(cx) ,
561
+ self.name,
567
562
GenericParamDefKind::Type {
568
563
did: self.def_id,
569
564
bounds: vec![], // These are filled in from the where-clauses.
@@ -573,7 +568,7 @@ impl Clean<GenericParamDef> for ty::GenericParamDef {
573
568
)
574
569
}
575
570
ty::GenericParamDefKind::Const { .. } => (
576
- self.name.clean(cx) ,
571
+ self.name,
577
572
GenericParamDefKind::Const {
578
573
did: self.def_id,
579
574
ty: cx.tcx.type_of(self.def_id).clean(cx),
@@ -599,14 +594,14 @@ impl Clean<GenericParamDef> for hir::GenericParam<'_> {
599
594
for bound in bounds {
600
595
s.push_str(&format!(" + {}", bound.name.ident()));
601
596
}
602
- s
597
+ Symbol::intern(&s)
603
598
} else {
604
- self.name.ident().to_string()
599
+ self.name.ident().name
605
600
};
606
601
(name, GenericParamDefKind::Lifetime)
607
602
}
608
603
hir::GenericParamKind::Type { ref default, synthetic } => (
609
- self.name.ident().name.clean(cx) ,
604
+ self.name.ident().name,
610
605
GenericParamDefKind::Type {
611
606
did: cx.tcx.hir().local_def_id(self.hir_id).to_def_id(),
612
607
bounds: self.bounds.clean(cx),
@@ -615,7 +610,7 @@ impl Clean<GenericParamDef> for hir::GenericParam<'_> {
615
610
},
616
611
),
617
612
hir::GenericParamKind::Const { ref ty } => (
618
- self.name.ident().name.clean(cx) ,
613
+ self.name.ident().name,
619
614
GenericParamDefKind::Const {
620
615
did: cx.tcx.hir().local_def_id(self.hir_id).to_def_id(),
621
616
ty: ty.clean(cx),
@@ -730,7 +725,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
730
725
.collect::<Vec<GenericParamDef>>();
731
726
732
727
// param index -> [(DefId of trait, associated type name, type)]
733
- let mut impl_trait_proj = FxHashMap::<u32, Vec<(DefId, String , Ty<'tcx>)>>::default();
728
+ let mut impl_trait_proj = FxHashMap::<u32, Vec<(DefId, Symbol , Ty<'tcx>)>>::default();
734
729
735
730
let where_predicates = preds
736
731
.predicates
@@ -778,11 +773,10 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
778
773
if let Some(((_, trait_did, name), rhs)) =
779
774
proj.as_ref().and_then(|(lhs, rhs)| Some((lhs.projection()?, rhs)))
780
775
{
781
- impl_trait_proj.entry(param_idx).or_default().push((
782
- trait_did,
783
- name.to_string(),
784
- rhs,
785
- ));
776
+ impl_trait_proj
777
+ .entry(param_idx)
778
+ .or_default()
779
+ .push((trait_did, name, rhs));
786
780
}
787
781
788
782
return None;
@@ -800,7 +794,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
800
794
if let crate::core::ImplTraitParam::ParamIndex(idx) = param {
801
795
if let Some(proj) = impl_trait_proj.remove(&idx) {
802
796
for (trait_did, name, rhs) in proj {
803
- simplify::merge_bounds(cx, &mut bounds, trait_did, & name, &rhs.clean(cx));
797
+ simplify::merge_bounds(cx, &mut bounds, trait_did, name, &rhs.clean(cx));
804
798
}
805
799
}
806
800
} else {
@@ -936,9 +930,9 @@ impl<'a> Clean<Arguments> for (&'a [hir::Ty<'a>], &'a [Ident]) {
936
930
.iter()
937
931
.enumerate()
938
932
.map(|(i, ty)| {
939
- let mut name = self.1.get(i).map(|ident| ident.to_string()).unwrap_or_default( );
933
+ let mut name = self.1.get(i).map(|ident| ident.name).unwrap_or(kw::Invalid );
940
934
if name.is_empty() {
941
- name = "_".to_string() ;
935
+ name = kw::Underscore ;
942
936
}
943
937
Argument { name, type_: ty.clean(cx) }
944
938
})
@@ -995,7 +989,7 @@ impl<'tcx> Clean<FnDecl> for (DefId, ty::PolyFnSig<'tcx>) {
995
989
.iter()
996
990
.map(|t| Argument {
997
991
type_: t.clean(cx),
998
- name: names.next().map_or_else(|| String::new(), | name| name.to_string() ),
992
+ name: names.next().map(|i| i. name).unwrap_or(kw::Invalid ),
999
993
})
1000
994
.collect(),
1001
995
},
@@ -1150,12 +1144,12 @@ impl Clean<Item> for ty::AssocItem {
1150
1144
};
1151
1145
let self_arg_ty = sig.input(0).skip_binder();
1152
1146
if self_arg_ty == self_ty {
1153
- decl.inputs.values[0].type_ = Generic(String::from("Self") );
1147
+ decl.inputs.values[0].type_ = Generic(kw::SelfUpper );
1154
1148
} else if let ty::Ref(_, ty, _) = *self_arg_ty.kind() {
1155
1149
if ty == self_ty {
1156
1150
match decl.inputs.values[0].type_ {
1157
1151
BorrowedRef { ref mut type_, .. } => {
1158
- **type_ = Generic(String::from("Self") )
1152
+ **type_ = Generic(kw::SelfUpper )
1159
1153
}
1160
1154
_ => unreachable!(),
1161
1155
}
@@ -1210,7 +1204,7 @@ impl Clean<Item> for ty::AssocItem {
1210
1204
}
1211
1205
}
1212
1206
ty::AssocKind::Type => {
1213
- let my_name = self.ident.name.clean(cx) ;
1207
+ let my_name = self.ident.name;
1214
1208
1215
1209
if let ty::TraitContainer(_) = self.container {
1216
1210
let bounds = cx.tcx.explicit_item_bounds(self.def_id);
@@ -1235,7 +1229,7 @@ impl Clean<Item> for ty::AssocItem {
1235
1229
_ => return None,
1236
1230
}
1237
1231
match **self_type {
1238
- Generic(ref s) if *s == "Self" => {}
1232
+ Generic(ref s) if *s == kw::SelfUpper => {}
1239
1233
_ => return None,
1240
1234
}
1241
1235
Some(bounds)
@@ -1408,7 +1402,7 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &DocContext<'_>) -> Type {
1408
1402
segments: trait_segments.clean(cx),
1409
1403
};
1410
1404
Type::QPath {
1411
- name: p.segments.last().expect("segments were empty").ident.name.clean(cx) ,
1405
+ name: p.segments.last().expect("segments were empty").ident.name,
1412
1406
self_type: box qself.clean(cx),
1413
1407
trait_: box resolve_type(cx, trait_path, hir_id),
1414
1408
}
@@ -1422,7 +1416,7 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &DocContext<'_>) -> Type {
1422
1416
};
1423
1417
let trait_path = hir::Path { span, res, segments: &[] };
1424
1418
Type::QPath {
1425
- name: segment.ident.name.clean(cx) ,
1419
+ name: segment.ident.name,
1426
1420
self_type: box qself.clean(cx),
1427
1421
trait_: box resolve_type(cx, trait_path.clean(cx), hir_id),
1428
1422
}
@@ -1625,7 +1619,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
1625
1619
let mut bindings = vec![];
1626
1620
for pb in obj.projection_bounds() {
1627
1621
bindings.push(TypeBinding {
1628
- name: cx.tcx.associated_item(pb.item_def_id()).ident.name.clean(cx) ,
1622
+ name: cx.tcx.associated_item(pb.item_def_id()).ident.name,
1629
1623
kind: TypeBindingKind::Equality { ty: pb.skip_binder().ty.clean(cx) },
1630
1624
});
1631
1625
}
@@ -1644,7 +1638,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
1644
1638
if let Some(bounds) = cx.impl_trait_bounds.borrow_mut().remove(&p.index.into()) {
1645
1639
ImplTrait(bounds)
1646
1640
} else {
1647
- Generic(p.name.to_string() )
1641
+ Generic(p.name)
1648
1642
}
1649
1643
}
1650
1644
@@ -1702,8 +1696,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
1702
1696
.tcx
1703
1697
.associated_item(proj.projection_ty.item_def_id)
1704
1698
.ident
1705
- .name
1706
- .clean(cx),
1699
+ .name,
1707
1700
kind: TypeBindingKind::Equality {
1708
1701
ty: proj.ty.clean(cx),
1709
1702
},
@@ -2339,7 +2332,7 @@ impl Clean<Item> for (&hir::MacroDef<'_>, Option<Symbol>) {
2339
2332
2340
2333
impl Clean<TypeBinding> for hir::TypeBinding<'_> {
2341
2334
fn clean(&self, cx: &DocContext<'_>) -> TypeBinding {
2342
- TypeBinding { name: self.ident.name.clean(cx) , kind: self.kind.clean(cx) }
2335
+ TypeBinding { name: self.ident.name, kind: self.kind.clean(cx) }
2343
2336
}
2344
2337
}
2345
2338
0 commit comments