Skip to content

Commit

Permalink
Display elided lifetime for external paths
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdd0121 committed Aug 7, 2020
1 parent 63c0d9c commit 505d157
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use crate::clean::auto_trait::AutoTraitFinder;
use crate::clean::blanket_impl::BlanketImplFinder;
use crate::clean::{
inline, Clean, Crate, Deprecation, ExternalCrate, FnDecl, FnRetTy, Generic, GenericArg,
GenericArgs, GenericBound, Generics, GetDefId, ImportSource, Item, ItemEnum, MacroKind, Path,
PathSegment, Primitive, PrimitiveType, ResolvedPath, Span, Stability, Type, TypeBinding,
TypeKind, Visibility, WherePredicate,
GenericArgs, GenericBound, Generics, GetDefId, ImportSource, Item, ItemEnum, Lifetime,
MacroKind, Path, PathSegment, Primitive, PrimitiveType, ResolvedPath, Span, Stability, Type,
TypeBinding, TypeKind, Visibility, WherePredicate,
};
use crate::core::DocContext;

Expand Down Expand Up @@ -121,7 +121,10 @@ pub fn external_generic_args(
let args: Vec<_> = substs
.iter()
.filter_map(|kind| match kind.unpack() {
GenericArgKind::Lifetime(lt) => lt.clean(cx).map(GenericArg::Lifetime),
GenericArgKind::Lifetime(lt) => match lt {
ty::ReLateBound(_, ty::BrAnon(_)) => Some(GenericArg::Lifetime(Lifetime::elided())),
_ => lt.clean(cx).map(GenericArg::Lifetime),
},
GenericArgKind::Type(_) if skip_self => {
skip_self = false;
None
Expand Down
13 changes: 13 additions & 0 deletions src/test/rustdoc/elided-lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,16 @@ pub fn test3(a: &u32) -> ARef {
pub fn test4(a: &u32) -> ARef<'_> {
Ref(a)
}

// Ensure external paths also display elided lifetime
// @has foo/fn.test5.html
// @matches - "Iter</a>&lt;'_"
pub fn test5(a: &Option<u32>) -> std::option::Iter<u32> {
a.iter()
}

// @has foo/fn.test6.html
// @matches - "Iter</a>&lt;'_"
pub fn test6(a: &Option<u32>) -> std::option::Iter<'_, u32> {
a.iter()
}

0 comments on commit 505d157

Please sign in to comment.