Skip to content

Commit 625c4d7

Browse files
committed
Rustdoc-Json: Extract convert_lifetime to function
1 parent a856e57 commit 625c4d7

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/librustdoc/json/conversions.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl FromWithTcx<clean::GenericArg> for GenericArg {
145145
fn from_tcx(arg: clean::GenericArg, tcx: TyCtxt<'_>) -> Self {
146146
use clean::GenericArg::*;
147147
match arg {
148-
Lifetime(l) => GenericArg::Lifetime(l.0.to_string()),
148+
Lifetime(l) => GenericArg::Lifetime(convert_lifetime(l)),
149149
Type(t) => GenericArg::Type(t.into_tcx(tcx)),
150150
Const(box c) => GenericArg::Const(c.into_tcx(tcx)),
151151
Infer => GenericArg::Infer,
@@ -347,6 +347,10 @@ fn convert_abi(a: RustcAbi) -> Abi {
347347
}
348348
}
349349

350+
fn convert_lifetime(l: clean::Lifetime) -> String {
351+
l.0.to_string()
352+
}
353+
350354
impl FromWithTcx<clean::Generics> for Generics {
351355
fn from_tcx(generics: clean::Generics, tcx: TyCtxt<'_>) -> Self {
352356
Generics {
@@ -374,7 +378,7 @@ impl FromWithTcx<clean::GenericParamDefKind> for GenericParamDefKind {
374378
use clean::GenericParamDefKind::*;
375379
match kind {
376380
Lifetime { outlives } => GenericParamDefKind::Lifetime {
377-
outlives: outlives.into_iter().map(|lt| lt.0.to_string()).collect(),
381+
outlives: outlives.into_iter().map(convert_lifetime).collect(),
378382
},
379383
Type { did: _, bounds, default, synthetic } => GenericParamDefKind::Type {
380384
bounds: bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),
@@ -405,7 +409,7 @@ impl FromWithTcx<clean::WherePredicate> for WherePredicate {
405409
.collect(),
406410
},
407411
RegionPredicate { lifetime, bounds } => WherePredicate::RegionPredicate {
408-
lifetime: lifetime.0.to_string(),
412+
lifetime: convert_lifetime(lifetime)
409413
bounds: bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),
410414
},
411415
EqPredicate { lhs, rhs } => {
@@ -428,7 +432,7 @@ impl FromWithTcx<clean::GenericBound> for GenericBound {
428432
modifier: from_trait_bound_modifier(modifier),
429433
}
430434
}
431-
Outlives(lifetime) => GenericBound::Outlives(lifetime.0.to_string()),
435+
Outlives(lifetime) => GenericBound::Outlives(convert_lifetime(lifetime)),
432436
}
433437
}
434438
}
@@ -459,7 +463,7 @@ impl FromWithTcx<clean::Type> for Type {
459463
param_names: Vec::new(),
460464
},
461465
clean::Type::DynTrait(bounds, lt) => Type::DynTrait(DynTrait {
462-
lifetime: lt.map(|lt| lt.0.to_string()),
466+
lifetime: lt.map(convert_lifetime),
463467
traits: bounds.into_iter().map(|t| t.into_tcx(tcx)).collect(),
464468
}),
465469
Generic(s) => Type::Generic(s.to_string()),
@@ -475,7 +479,7 @@ impl FromWithTcx<clean::Type> for Type {
475479
type_: Box::new((*type_).into_tcx(tcx)),
476480
},
477481
BorrowedRef { lifetime, mutability, type_ } => Type::BorrowedRef {
478-
lifetime: lifetime.map(|l| l.0.to_string()),
482+
lifetime: lifetime.map(convert_lifetime),
479483
mutable: mutability == ast::Mutability::Mut,
480484
type_: Box::new((*type_).into_tcx(tcx)),
481485
},

0 commit comments

Comments
 (0)