Skip to content

Commit 505d157

Browse files
committed
Display elided lifetime for external paths
1 parent 63c0d9c commit 505d157

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/librustdoc/clean/utils.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use crate::clean::auto_trait::AutoTraitFinder;
22
use crate::clean::blanket_impl::BlanketImplFinder;
33
use crate::clean::{
44
inline, Clean, Crate, Deprecation, ExternalCrate, FnDecl, FnRetTy, Generic, GenericArg,
5-
GenericArgs, GenericBound, Generics, GetDefId, ImportSource, Item, ItemEnum, MacroKind, Path,
6-
PathSegment, Primitive, PrimitiveType, ResolvedPath, Span, Stability, Type, TypeBinding,
7-
TypeKind, Visibility, WherePredicate,
5+
GenericArgs, GenericBound, Generics, GetDefId, ImportSource, Item, ItemEnum, Lifetime,
6+
MacroKind, Path, PathSegment, Primitive, PrimitiveType, ResolvedPath, Span, Stability, Type,
7+
TypeBinding, TypeKind, Visibility, WherePredicate,
88
};
99
use crate::core::DocContext;
1010

@@ -121,7 +121,10 @@ pub fn external_generic_args(
121121
let args: Vec<_> = substs
122122
.iter()
123123
.filter_map(|kind| match kind.unpack() {
124-
GenericArgKind::Lifetime(lt) => lt.clean(cx).map(GenericArg::Lifetime),
124+
GenericArgKind::Lifetime(lt) => match lt {
125+
ty::ReLateBound(_, ty::BrAnon(_)) => Some(GenericArg::Lifetime(Lifetime::elided())),
126+
_ => lt.clean(cx).map(GenericArg::Lifetime),
127+
},
125128
GenericArgKind::Type(_) if skip_self => {
126129
skip_self = false;
127130
None

src/test/rustdoc/elided-lifetime.rs

+13
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,16 @@ pub fn test3(a: &u32) -> ARef {
3131
pub fn test4(a: &u32) -> ARef<'_> {
3232
Ref(a)
3333
}
34+
35+
// Ensure external paths also display elided lifetime
36+
// @has foo/fn.test5.html
37+
// @matches - "Iter</a>&lt;'_"
38+
pub fn test5(a: &Option<u32>) -> std::option::Iter<u32> {
39+
a.iter()
40+
}
41+
42+
// @has foo/fn.test6.html
43+
// @matches - "Iter</a>&lt;'_"
44+
pub fn test6(a: &Option<u32>) -> std::option::Iter<'_, u32> {
45+
a.iter()
46+
}

0 commit comments

Comments
 (0)