@@ -119,6 +119,16 @@ where
119
119
}
120
120
}
121
121
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
+
122
132
pub ( crate ) fn from_deprecation ( deprecation : rustc_attr:: Deprecation ) -> Deprecation {
123
133
#[ rustfmt:: skip]
124
134
let rustc_attr:: Deprecation { since, note, is_since_rustc_version : _, suggestion : _ } = deprecation;
@@ -130,11 +140,11 @@ impl FromWithTcx<clean::GenericArgs> for GenericArgs {
130
140
use clean:: GenericArgs :: * ;
131
141
match args {
132
142
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) ,
135
145
} ,
136
146
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) ,
138
148
output : output. map ( |a| ( * a) . into_tcx ( tcx) ) ,
139
149
} ,
140
150
}
@@ -145,7 +155,7 @@ impl FromWithTcx<clean::GenericArg> for GenericArg {
145
155
fn from_tcx ( arg : clean:: GenericArg , tcx : TyCtxt < ' _ > ) -> Self {
146
156
use clean:: GenericArg :: * ;
147
157
match arg {
148
- Lifetime ( l) => GenericArg :: Lifetime ( l . 0 . to_string ( ) ) ,
158
+ Lifetime ( l) => GenericArg :: Lifetime ( convert_lifetime ( l ) ) ,
149
159
Type ( t) => GenericArg :: Type ( t. into_tcx ( tcx) ) ,
150
160
Const ( box c) => GenericArg :: Const ( c. into_tcx ( tcx) ) ,
151
161
Infer => GenericArg :: Infer ,
@@ -177,9 +187,7 @@ impl FromWithTcx<clean::TypeBindingKind> for TypeBindingKind {
177
187
use clean:: TypeBindingKind :: * ;
178
188
match kind {
179
189
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) ) ,
183
191
}
184
192
}
185
193
}
@@ -244,7 +252,7 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
244
252
TraitAliasItem ( t) => ItemEnum :: TraitAlias ( t. into_tcx ( tcx) ) ,
245
253
MethodItem ( m, _) => ItemEnum :: Method ( from_function_method ( m, true , header. unwrap ( ) , tcx) ) ,
246
254
TyMethodItem ( m) => ItemEnum :: Method ( from_function_method ( m, false , header. unwrap ( ) , tcx) ) ,
247
- ImplItem ( i) => ItemEnum :: Impl ( i . into_tcx ( tcx) ) ,
255
+ ImplItem ( i) => ItemEnum :: Impl ( ( * i ) . into_tcx ( tcx) ) ,
248
256
StaticItem ( s) => ItemEnum :: Static ( s. into_tcx ( tcx) ) ,
249
257
ForeignStaticItem ( s) => ItemEnum :: Static ( s. into_tcx ( tcx) ) ,
250
258
ForeignTypeItem => ItemEnum :: ForeignType ,
@@ -260,12 +268,12 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
260
268
}
261
269
TyAssocTypeItem ( g, b) => ItemEnum :: AssocType {
262
270
generics : ( * g) . into_tcx ( tcx) ,
263
- bounds : b. into_iter ( ) . map ( |x| x . into_tcx ( tcx) ) . collect ( ) ,
271
+ bounds : b. into_tcx ( tcx) ,
264
272
default : None ,
265
273
} ,
266
274
AssocTypeItem ( t, b) => ItemEnum :: AssocType {
267
275
generics : t. generics . into_tcx ( tcx) ,
268
- bounds : b. into_iter ( ) . map ( |x| x . into_tcx ( tcx) ) . collect ( ) ,
276
+ bounds : b. into_tcx ( tcx) ,
269
277
default : Some ( t. item_type . unwrap_or ( t. type_ ) . into_tcx ( tcx) ) ,
270
278
} ,
271
279
// `convert_item` early returns `None` for stripped items and keywords.
@@ -347,15 +355,15 @@ fn convert_abi(a: RustcAbi) -> Abi {
347
355
}
348
356
}
349
357
358
+ fn convert_lifetime ( l : clean:: Lifetime ) -> String {
359
+ l. 0 . to_string ( )
360
+ }
361
+
350
362
impl FromWithTcx < clean:: Generics > for Generics {
351
363
fn from_tcx ( generics : clean:: Generics , tcx : TyCtxt < ' _ > ) -> Self {
352
364
Generics {
353
- params : generics. params . into_iter ( ) . map ( |x| x. into_tcx ( tcx) ) . collect ( ) ,
354
- where_predicates : generics
355
- . where_predicates
356
- . into_iter ( )
357
- . map ( |x| x. into_tcx ( tcx) )
358
- . collect ( ) ,
365
+ params : generics. params . into_tcx ( tcx) ,
366
+ where_predicates : generics. where_predicates . into_tcx ( tcx) ,
359
367
}
360
368
}
361
369
}
@@ -374,10 +382,10 @@ impl FromWithTcx<clean::GenericParamDefKind> for GenericParamDefKind {
374
382
use clean:: GenericParamDefKind :: * ;
375
383
match kind {
376
384
Lifetime { outlives } => GenericParamDefKind :: Lifetime {
377
- outlives : outlives. into_iter ( ) . map ( |lt| lt . 0 . to_string ( ) ) . collect ( ) ,
385
+ outlives : outlives. into_iter ( ) . map ( convert_lifetime ) . collect ( ) ,
378
386
} ,
379
387
Type { did : _, bounds, default, synthetic } => GenericParamDefKind :: Type {
380
- bounds : bounds. into_iter ( ) . map ( |x| x . into_tcx ( tcx) ) . collect ( ) ,
388
+ bounds : bounds. into_tcx ( tcx) ,
381
389
default : default. map ( |x| ( * x) . into_tcx ( tcx) ) ,
382
390
synthetic,
383
391
} ,
@@ -395,7 +403,7 @@ impl FromWithTcx<clean::WherePredicate> for WherePredicate {
395
403
match predicate {
396
404
BoundPredicate { ty, bounds, bound_params } => WherePredicate :: BoundPredicate {
397
405
type_ : ty. into_tcx ( tcx) ,
398
- bounds : bounds. into_iter ( ) . map ( |x| x . into_tcx ( tcx) ) . collect ( ) ,
406
+ bounds : bounds. into_tcx ( tcx) ,
399
407
generic_params : bound_params
400
408
. into_iter ( )
401
409
. map ( |x| GenericParamDef {
@@ -405,8 +413,8 @@ impl FromWithTcx<clean::WherePredicate> for WherePredicate {
405
413
. collect ( ) ,
406
414
} ,
407
415
RegionPredicate { lifetime, bounds } => WherePredicate :: RegionPredicate {
408
- lifetime : lifetime . 0 . to_string ( ) ,
409
- bounds : bounds. into_iter ( ) . map ( |x| x . into_tcx ( tcx) ) . collect ( ) ,
416
+ lifetime : convert_lifetime ( lifetime ) ,
417
+ bounds : bounds. into_tcx ( tcx) ,
410
418
} ,
411
419
EqPredicate { lhs, rhs } => {
412
420
WherePredicate :: EqPredicate { lhs : lhs. into_tcx ( tcx) , rhs : rhs. into_tcx ( tcx) }
@@ -424,11 +432,11 @@ impl FromWithTcx<clean::GenericBound> for GenericBound {
424
432
let trait_ = clean:: Type :: Path { path : trait_ } . into_tcx ( tcx) ;
425
433
GenericBound :: TraitBound {
426
434
trait_,
427
- generic_params : generic_params. into_iter ( ) . map ( |x| x . into_tcx ( tcx) ) . collect ( ) ,
435
+ generic_params : generic_params. into_tcx ( tcx) ,
428
436
modifier : from_trait_bound_modifier ( modifier) ,
429
437
}
430
438
}
431
- Outlives ( lifetime) => GenericBound :: Outlives ( lifetime . 0 . to_string ( ) ) ,
439
+ Outlives ( lifetime) => GenericBound :: Outlives ( convert_lifetime ( lifetime ) ) ,
432
440
}
433
441
}
434
442
}
@@ -447,8 +455,8 @@ pub(crate) fn from_trait_bound_modifier(
447
455
impl FromWithTcx < clean:: Type > for Type {
448
456
fn from_tcx ( ty : clean:: Type , tcx : TyCtxt < ' _ > ) -> Self {
449
457
use clean:: Type :: {
450
- Array , BareFunction , BorrowedRef , DynTrait , Generic , ImplTrait , Infer , Primitive ,
451
- QPath , RawPointer , Slice , Tuple ,
458
+ Array , BareFunction , BorrowedRef , Generic , ImplTrait , Infer , Primitive , QPath ,
459
+ RawPointer , Slice , Tuple ,
452
460
} ;
453
461
454
462
match ty {
@@ -458,40 +466,24 @@ impl FromWithTcx<clean::Type> for Type {
458
466
args : path. segments . last ( ) . map ( |args| Box :: new ( args. clone ( ) . args . into_tcx ( tcx) ) ) ,
459
467
param_names : Vec :: new ( ) ,
460
468
} ,
461
- DynTrait ( mut bounds, lt) => {
462
- let first_trait = bounds. remove ( 0 ) . trait_ ;
463
-
464
- Type :: ResolvedPath {
465
- name : first_trait. whole_name ( ) ,
466
- id : from_item_id ( first_trait. def_id ( ) . into ( ) , tcx) ,
467
- args : first_trait
468
- . segments
469
- . last ( )
470
- . map ( |args| Box :: new ( args. clone ( ) . args . into_tcx ( tcx) ) ) ,
471
- param_names : bounds
472
- . into_iter ( )
473
- . map ( |t| {
474
- clean:: GenericBound :: TraitBound ( t, rustc_hir:: TraitBoundModifier :: None )
475
- } )
476
- . chain ( lt. map ( clean:: GenericBound :: Outlives ) )
477
- . map ( |bound| bound. into_tcx ( tcx) )
478
- . collect ( ) ,
479
- }
480
- }
469
+ clean:: Type :: DynTrait ( bounds, lt) => Type :: DynTrait ( DynTrait {
470
+ lifetime : lt. map ( convert_lifetime) ,
471
+ traits : bounds. into_tcx ( tcx) ,
472
+ } ) ,
481
473
Generic ( s) => Type :: Generic ( s. to_string ( ) ) ,
482
474
Primitive ( p) => Type :: Primitive ( p. as_sym ( ) . to_string ( ) ) ,
483
475
BareFunction ( f) => Type :: FunctionPointer ( Box :: new ( ( * f) . into_tcx ( tcx) ) ) ,
484
- Tuple ( t) => Type :: Tuple ( t. into_iter ( ) . map ( |x| x . into_tcx ( tcx) ) . collect ( ) ) ,
476
+ Tuple ( t) => Type :: Tuple ( t. into_tcx ( tcx) ) ,
485
477
Slice ( t) => Type :: Slice ( Box :: new ( ( * t) . into_tcx ( tcx) ) ) ,
486
478
Array ( t, s) => Type :: Array { type_ : Box :: new ( ( * t) . into_tcx ( tcx) ) , len : s } ,
487
- ImplTrait ( g) => Type :: ImplTrait ( g. into_iter ( ) . map ( |x| x . into_tcx ( tcx) ) . collect ( ) ) ,
479
+ ImplTrait ( g) => Type :: ImplTrait ( g. into_tcx ( tcx) ) ,
488
480
Infer => Type :: Infer ,
489
481
RawPointer ( mutability, type_) => Type :: RawPointer {
490
482
mutable : mutability == ast:: Mutability :: Mut ,
491
483
type_ : Box :: new ( ( * type_) . into_tcx ( tcx) ) ,
492
484
} ,
493
485
BorrowedRef { lifetime, mutability, type_ } => Type :: BorrowedRef {
494
- lifetime : lifetime. map ( |l| l . 0 . to_string ( ) ) ,
486
+ lifetime : lifetime. map ( convert_lifetime ) ,
495
487
mutable : mutability == ast:: Mutability :: Mut ,
496
488
type_ : Box :: new ( ( * type_) . into_tcx ( tcx) ) ,
497
489
} ,
@@ -528,7 +520,7 @@ impl FromWithTcx<clean::BareFunctionDecl> for FunctionPointer {
528
520
async_ : false ,
529
521
abi : convert_abi ( abi) ,
530
522
} ,
531
- generic_params : generic_params. into_iter ( ) . map ( |x| x . into_tcx ( tcx) ) . collect ( ) ,
523
+ generic_params : generic_params. into_tcx ( tcx) ,
532
524
decl : decl. into_tcx ( tcx) ,
533
525
}
534
526
}
@@ -562,16 +554,28 @@ impl FromWithTcx<clean::Trait> for Trait {
562
554
is_unsafe,
563
555
items : ids ( items, tcx) ,
564
556
generics : generics. into_tcx ( tcx) ,
565
- bounds : bounds. into_iter ( ) . map ( |x| x . into_tcx ( tcx) ) . collect ( ) ,
557
+ bounds : bounds. into_tcx ( tcx) ,
566
558
implementations : Vec :: new ( ) , // Added in JsonRenderer::item
567
559
}
568
560
}
569
561
}
570
562
571
- impl FromWithTcx < Box < clean:: Impl > > for Impl {
572
- fn from_tcx ( impl_ : Box < clean:: Impl > , tcx : TyCtxt < ' _ > ) -> Self {
563
+ impl FromWithTcx < clean:: PolyTrait > for PolyTrait {
564
+ fn from_tcx (
565
+ clean:: PolyTrait { trait_, generic_params } : clean:: PolyTrait ,
566
+ tcx : TyCtxt < ' _ > ,
567
+ ) -> Self {
568
+ PolyTrait {
569
+ trait_ : clean:: Type :: Path { path : trait_ } . into_tcx ( tcx) ,
570
+ generic_params : generic_params. into_tcx ( tcx) ,
571
+ }
572
+ }
573
+ }
574
+
575
+ impl FromWithTcx < clean:: Impl > for Impl {
576
+ fn from_tcx ( impl_ : clean:: Impl , tcx : TyCtxt < ' _ > ) -> Self {
573
577
let provided_trait_methods = impl_. provided_trait_methods ( tcx) ;
574
- let clean:: Impl { unsafety, generics, trait_, for_, items, polarity, kind } = * impl_;
578
+ let clean:: Impl { unsafety, generics, trait_, for_, items, polarity, kind } = impl_;
575
579
// FIXME: should `trait_` be a clean::Path equivalent in JSON?
576
580
let trait_ = trait_. map ( |path| clean:: Type :: Path { path } . into_tcx ( tcx) ) ;
577
581
// FIXME: use something like ImplKind in JSON?
@@ -730,10 +734,7 @@ impl FromWithTcx<Box<clean::Typedef>> for Typedef {
730
734
731
735
impl FromWithTcx < clean:: OpaqueTy > for OpaqueTy {
732
736
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) }
737
738
}
738
739
}
739
740
@@ -749,10 +750,7 @@ impl FromWithTcx<clean::Static> for Static {
749
750
750
751
impl FromWithTcx < clean:: TraitAlias > for TraitAlias {
751
752
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) }
756
754
}
757
755
}
758
756
0 commit comments