Skip to content

Commit

Permalink
rustdoc: create helper GenericParamDef::lifetime
Browse files Browse the repository at this point in the history
  • Loading branch information
fmease committed Nov 4, 2022
1 parent 7ec50b6 commit 5ccaed2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 28 deletions.
5 changes: 1 addition & 4 deletions src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,7 @@ where
match br {
// We only care about named late bound regions, as we need to add them
// to the 'for<>' section
ty::BrNamed(_, name) => Some(GenericParamDef {
name,
kind: GenericParamDefKind::Lifetime { outlives: vec![] },
}),
ty::BrNamed(_, name) => Some(GenericParamDef::lifetime(name)),
_ => None,
}
})
Expand Down
5 changes: 1 addition & 4 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,7 @@ fn build_external_function<'tcx>(cx: &mut DocContext<'tcx>, did: DefId) -> Box<c

let late_bound_regions = sig.bound_vars().into_iter().filter_map(|var| match var {
ty::BoundVariableKind::Region(ty::BrNamed(_, name)) if name != kw::UnderscoreLifetime => {
Some(clean::GenericParamDef {
name,
kind: clean::GenericParamDefKind::Lifetime { outlives: Vec::new() },
})
Some(clean::GenericParamDef::lifetime(name))
}
_ => None,
});
Expand Down
22 changes: 6 additions & 16 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,9 @@ fn clean_poly_trait_ref_with_bindings<'tcx>(
.collect_referenced_late_bound_regions(&poly_trait_ref)
.into_iter()
.filter_map(|br| match br {
ty::BrNamed(_, name) if name != kw::UnderscoreLifetime => Some(GenericParamDef {
name,
kind: GenericParamDefKind::Lifetime { outlives: vec![] },
}),
ty::BrNamed(_, name) if name != kw::UnderscoreLifetime => {
Some(GenericParamDef::lifetime(name))
}
_ => None,
})
.collect();
Expand Down Expand Up @@ -741,10 +740,7 @@ fn clean_ty_generics<'tcx>(
p.get_bound_params()
.into_iter()
.flatten()
.map(|param| GenericParamDef {
name: param.0,
kind: GenericParamDefKind::Lifetime { outlives: Vec::new() },
})
.map(|param| GenericParamDef::lifetime(param.0))
.collect(),
));
}
Expand Down Expand Up @@ -1156,10 +1152,7 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
ty::BoundVariableKind::Region(ty::BrNamed(_, name))
if name != kw::UnderscoreLifetime =>
{
Some(GenericParamDef {
name,
kind: GenericParamDefKind::Lifetime { outlives: Vec::new() },
})
Some(GenericParamDef::lifetime(name))
}
_ => None,
});
Expand Down Expand Up @@ -1720,10 +1713,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
ty::BoundVariableKind::Region(ty::BrNamed(_, name))
if name != kw::UnderscoreLifetime =>
{
Some(GenericParamDef {
name,
kind: GenericParamDefKind::Lifetime { outlives: vec![] },
})
Some(GenericParamDef::lifetime(name))
}
_ => None,
})
Expand Down
5 changes: 1 addition & 4 deletions src/librustdoc/clean/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ pub(crate) fn where_clauses(cx: &DocContext<'_>, clauses: Vec<WP>) -> ThinVec<WP
let Some((bounds, _)) = tybounds.get_mut(ty) else { return true };
let bound_params = bound_params
.into_iter()
.map(|param| clean::GenericParamDef {
name: param.0,
kind: clean::GenericParamDefKind::Lifetime { outlives: Vec::new() },
})
.map(|param| clean::GenericParamDef::lifetime(param.0))
.collect();
merge_bounds(cx, bounds, bound_params, trait_did, name, rhs)
});
Expand Down
4 changes: 4 additions & 0 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,10 @@ pub(crate) struct GenericParamDef {
}

impl GenericParamDef {
pub(crate) fn lifetime(name: Symbol) -> Self {
Self { name, kind: GenericParamDefKind::Lifetime { outlives: Vec::new() } }
}

pub(crate) fn is_synthetic_type_param(&self) -> bool {
match self.kind {
GenericParamDefKind::Lifetime { .. } | GenericParamDefKind::Const { .. } => false,
Expand Down

0 comments on commit 5ccaed2

Please sign in to comment.