Skip to content

Commit 6290f92

Browse files
committed
Rustdoc-Json: Add and use FromWithTcx for Vec
1 parent 625c4d7 commit 6290f92

File tree

1 file changed

+31
-33
lines changed

1 file changed

+31
-33
lines changed

src/librustdoc/json/conversions.rs

+31-33
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ where
119119
}
120120
}
121121

122+
impl<I, T, U> FromWithTcx<I> for Vec<U>
123+
where
124+
I: IntoIterator<Item = T>,
125+
U: FromWithTcx<T>,
126+
{
127+
fn from_tcx(f: I, tcx: TyCtxt<'_>) -> Vec<U> {
128+
f.into_iter().map(|x| x.into_tcx(tcx)).collect()
129+
}
130+
}
131+
122132
pub(crate) fn from_deprecation(deprecation: rustc_attr::Deprecation) -> Deprecation {
123133
#[rustfmt::skip]
124134
let rustc_attr::Deprecation { since, note, is_since_rustc_version: _, suggestion: _ } = deprecation;
@@ -130,11 +140,11 @@ impl FromWithTcx<clean::GenericArgs> for GenericArgs {
130140
use clean::GenericArgs::*;
131141
match args {
132142
AngleBracketed { args, bindings } => GenericArgs::AngleBracketed {
133-
args: args.into_vec().into_iter().map(|a| a.into_tcx(tcx)).collect(),
134-
bindings: bindings.into_iter().map(|a| a.into_tcx(tcx)).collect(),
143+
args: args.into_vec().into_tcx(tcx),
144+
bindings: bindings.into_tcx(tcx),
135145
},
136146
Parenthesized { inputs, output } => GenericArgs::Parenthesized {
137-
inputs: inputs.into_vec().into_iter().map(|a| a.into_tcx(tcx)).collect(),
147+
inputs: inputs.into_vec().into_tcx(tcx),
138148
output: output.map(|a| (*a).into_tcx(tcx)),
139149
},
140150
}
@@ -177,9 +187,7 @@ impl FromWithTcx<clean::TypeBindingKind> for TypeBindingKind {
177187
use clean::TypeBindingKind::*;
178188
match kind {
179189
Equality { term } => TypeBindingKind::Equality(term.into_tcx(tcx)),
180-
Constraint { bounds } => {
181-
TypeBindingKind::Constraint(bounds.into_iter().map(|a| a.into_tcx(tcx)).collect())
182-
}
190+
Constraint { bounds } => TypeBindingKind::Constraint(bounds.into_tcx(tcx)),
183191
}
184192
}
185193
}
@@ -260,12 +268,12 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
260268
}
261269
TyAssocTypeItem(g, b) => ItemEnum::AssocType {
262270
generics: (*g).into_tcx(tcx),
263-
bounds: b.into_iter().map(|x| x.into_tcx(tcx)).collect(),
271+
bounds: b.into_tcx(tcx),
264272
default: None,
265273
},
266274
AssocTypeItem(t, b) => ItemEnum::AssocType {
267275
generics: t.generics.into_tcx(tcx),
268-
bounds: b.into_iter().map(|x| x.into_tcx(tcx)).collect(),
276+
bounds: b.into_tcx(tcx),
269277
default: Some(t.item_type.unwrap_or(t.type_).into_tcx(tcx)),
270278
},
271279
// `convert_item` early returns `None` for stripped items and keywords.
@@ -354,12 +362,8 @@ fn convert_lifetime(l: clean::Lifetime) -> String {
354362
impl FromWithTcx<clean::Generics> for Generics {
355363
fn from_tcx(generics: clean::Generics, tcx: TyCtxt<'_>) -> Self {
356364
Generics {
357-
params: generics.params.into_iter().map(|x| x.into_tcx(tcx)).collect(),
358-
where_predicates: generics
359-
.where_predicates
360-
.into_iter()
361-
.map(|x| x.into_tcx(tcx))
362-
.collect(),
365+
params: generics.params.into_tcx(tcx),
366+
where_predicates: generics.where_predicates.into_tcx(tcx),
363367
}
364368
}
365369
}
@@ -381,7 +385,7 @@ impl FromWithTcx<clean::GenericParamDefKind> for GenericParamDefKind {
381385
outlives: outlives.into_iter().map(convert_lifetime).collect(),
382386
},
383387
Type { did: _, bounds, default, synthetic } => GenericParamDefKind::Type {
384-
bounds: bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),
388+
bounds: bounds.into_tcx(tcx),
385389
default: default.map(|x| (*x).into_tcx(tcx)),
386390
synthetic,
387391
},
@@ -399,7 +403,7 @@ impl FromWithTcx<clean::WherePredicate> for WherePredicate {
399403
match predicate {
400404
BoundPredicate { ty, bounds, bound_params } => WherePredicate::BoundPredicate {
401405
type_: ty.into_tcx(tcx),
402-
bounds: bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),
406+
bounds: bounds.into_tcx(tcx),
403407
generic_params: bound_params
404408
.into_iter()
405409
.map(|x| GenericParamDef {
@@ -409,8 +413,8 @@ impl FromWithTcx<clean::WherePredicate> for WherePredicate {
409413
.collect(),
410414
},
411415
RegionPredicate { lifetime, bounds } => WherePredicate::RegionPredicate {
412-
lifetime: convert_lifetime(lifetime)
413-
bounds: bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),
416+
lifetime: convert_lifetime(lifetime),
417+
bounds: bounds.into_tcx(tcx),
414418
},
415419
EqPredicate { lhs, rhs } => {
416420
WherePredicate::EqPredicate { lhs: lhs.into_tcx(tcx), rhs: rhs.into_tcx(tcx) }
@@ -428,7 +432,7 @@ impl FromWithTcx<clean::GenericBound> for GenericBound {
428432
let trait_ = clean::Type::Path { path: trait_ }.into_tcx(tcx);
429433
GenericBound::TraitBound {
430434
trait_,
431-
generic_params: generic_params.into_iter().map(|x| x.into_tcx(tcx)).collect(),
435+
generic_params: generic_params.into_tcx(tcx),
432436
modifier: from_trait_bound_modifier(modifier),
433437
}
434438
}
@@ -464,15 +468,15 @@ impl FromWithTcx<clean::Type> for Type {
464468
},
465469
clean::Type::DynTrait(bounds, lt) => Type::DynTrait(DynTrait {
466470
lifetime: lt.map(convert_lifetime),
467-
traits: bounds.into_iter().map(|t| t.into_tcx(tcx)).collect(),
471+
traits: bounds.into_tcx(tcx),
468472
}),
469473
Generic(s) => Type::Generic(s.to_string()),
470474
Primitive(p) => Type::Primitive(p.as_sym().to_string()),
471475
BareFunction(f) => Type::FunctionPointer(Box::new((*f).into_tcx(tcx))),
472-
Tuple(t) => Type::Tuple(t.into_iter().map(|x| x.into_tcx(tcx)).collect()),
476+
Tuple(t) => Type::Tuple(t.into_tcx(tcx)),
473477
Slice(t) => Type::Slice(Box::new((*t).into_tcx(tcx))),
474478
Array(t, s) => Type::Array { type_: Box::new((*t).into_tcx(tcx)), len: s },
475-
ImplTrait(g) => Type::ImplTrait(g.into_iter().map(|x| x.into_tcx(tcx)).collect()),
479+
ImplTrait(g) => Type::ImplTrait(g.into_tcx(tcx)),
476480
Infer => Type::Infer,
477481
RawPointer(mutability, type_) => Type::RawPointer {
478482
mutable: mutability == ast::Mutability::Mut,
@@ -516,7 +520,7 @@ impl FromWithTcx<clean::BareFunctionDecl> for FunctionPointer {
516520
async_: false,
517521
abi: convert_abi(abi),
518522
},
519-
generic_params: generic_params.into_iter().map(|x| x.into_tcx(tcx)).collect(),
523+
generic_params: generic_params.into_tcx(tcx),
520524
decl: decl.into_tcx(tcx),
521525
}
522526
}
@@ -550,7 +554,7 @@ impl FromWithTcx<clean::Trait> for Trait {
550554
is_unsafe,
551555
items: ids(items, tcx),
552556
generics: generics.into_tcx(tcx),
553-
bounds: bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),
557+
bounds: bounds.into_tcx(tcx),
554558
implementations: Vec::new(), // Added in JsonRenderer::item
555559
}
556560
}
@@ -563,7 +567,7 @@ impl FromWithTcx<clean::PolyTrait> for PolyTrait {
563567
) -> Self {
564568
PolyTrait {
565569
trait_: clean::Type::Path { path: trait_ }.into_tcx(tcx),
566-
generic_params: generic_params.into_iter().map(|x| x.into_tcx(tcx)).collect(),
570+
generic_params: generic_params.into_tcx(tcx),
567571
}
568572
}
569573
}
@@ -730,10 +734,7 @@ impl FromWithTcx<Box<clean::Typedef>> for Typedef {
730734

731735
impl FromWithTcx<clean::OpaqueTy> for OpaqueTy {
732736
fn from_tcx(opaque: clean::OpaqueTy, tcx: TyCtxt<'_>) -> Self {
733-
OpaqueTy {
734-
bounds: opaque.bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),
735-
generics: opaque.generics.into_tcx(tcx),
736-
}
737+
OpaqueTy { bounds: opaque.bounds.into_tcx(tcx), generics: opaque.generics.into_tcx(tcx) }
737738
}
738739
}
739740

@@ -749,10 +750,7 @@ impl FromWithTcx<clean::Static> for Static {
749750

750751
impl FromWithTcx<clean::TraitAlias> for TraitAlias {
751752
fn from_tcx(alias: clean::TraitAlias, tcx: TyCtxt<'_>) -> Self {
752-
TraitAlias {
753-
generics: alias.generics.into_tcx(tcx),
754-
params: alias.bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),
755-
}
753+
TraitAlias { generics: alias.generics.into_tcx(tcx), params: alias.bounds.into_tcx(tcx) }
756754
}
757755
}
758756

0 commit comments

Comments
 (0)