From 63c0d9ca51bb471189a0d5529c8ee5491fb4e102 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Fri, 7 Aug 2020 00:48:24 +0100 Subject: Display elided lifetime for non-reference type in doc --- src/test/rustdoc/elided-lifetime.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/test/rustdoc/elided-lifetime.rs (limited to 'src/test/rustdoc') diff --git a/src/test/rustdoc/elided-lifetime.rs b/src/test/rustdoc/elided-lifetime.rs new file mode 100644 index 00000000000..641866aaf3c --- /dev/null +++ b/src/test/rustdoc/elided-lifetime.rs @@ -0,0 +1,33 @@ +#![crate_name = "foo"] + +// rust-lang/rust#75225 +// +// Since Rust 2018 we encourage writing out <'_> explicitly to make it clear +// that borrowing is occuring. Make sure rustdoc is following the same idiom. + +pub struct Ref<'a>(&'a u32); +type ARef<'a> = Ref<'a>; + +// @has foo/fn.test1.html +// @matches - "Ref<'_>" +pub fn test1(a: &u32) -> Ref { + Ref(a) +} + +// @has foo/fn.test2.html +// @matches - "Ref<'_>" +pub fn test2(a: &u32) -> Ref<'_> { + Ref(a) +} + +// @has foo/fn.test3.html +// @matches - "Ref<'_>" +pub fn test3(a: &u32) -> ARef { + Ref(a) +} + +// @has foo/fn.test4.html +// @matches - "Ref<'_>" +pub fn test4(a: &u32) -> ARef<'_> { + Ref(a) +} -- cgit 1.4.1-3-g733a5 From 505d157814ba4e7d3ee0d036832008c3221b3df4 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Fri, 7 Aug 2020 23:34:44 +0100 Subject: Display elided lifetime for external paths --- src/librustdoc/clean/utils.rs | 11 +++++++---- src/test/rustdoc/elided-lifetime.rs | 13 +++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) (limited to 'src/test/rustdoc') diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 52c30668826..adef4c83224 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -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; @@ -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 diff --git a/src/test/rustdoc/elided-lifetime.rs b/src/test/rustdoc/elided-lifetime.rs index 641866aaf3c..6ba58380ed5 100644 --- a/src/test/rustdoc/elided-lifetime.rs +++ b/src/test/rustdoc/elided-lifetime.rs @@ -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<'_" +pub fn test5(a: &Option) -> std::option::Iter { + a.iter() +} + +// @has foo/fn.test6.html +// @matches - "Iter<'_" +pub fn test6(a: &Option) -> std::option::Iter<'_, u32> { + a.iter() +} -- cgit 1.4.1-3-g733a5 From 541fbbb6fab4afdeea48fdb9e94cee48991b3333 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Sat, 8 Aug 2020 01:07:43 +0100 Subject: Cross-crate doc inlining test case for elided lifetime --- src/test/rustdoc/auxiliary/elided-lifetime.rs | 11 +++++++++++ src/test/rustdoc/elided-lifetime.rs | 25 +++++++++++-------------- 2 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 src/test/rustdoc/auxiliary/elided-lifetime.rs (limited to 'src/test/rustdoc') diff --git a/src/test/rustdoc/auxiliary/elided-lifetime.rs b/src/test/rustdoc/auxiliary/elided-lifetime.rs new file mode 100644 index 00000000000..4f2c93379d8 --- /dev/null +++ b/src/test/rustdoc/auxiliary/elided-lifetime.rs @@ -0,0 +1,11 @@ +#![crate_name = "bar"] + +pub struct Ref<'a>(&'a u32); + +pub fn test5(a: &u32) -> Ref { + Ref(a) +} + +pub fn test6(a: &u32) -> Ref<'_> { + Ref(a) +} diff --git a/src/test/rustdoc/elided-lifetime.rs b/src/test/rustdoc/elided-lifetime.rs index 6ba58380ed5..5a32554f972 100644 --- a/src/test/rustdoc/elided-lifetime.rs +++ b/src/test/rustdoc/elided-lifetime.rs @@ -1,10 +1,12 @@ -#![crate_name = "foo"] - +// aux-build:elided-lifetime.rs +// // rust-lang/rust#75225 // // Since Rust 2018 we encourage writing out <'_> explicitly to make it clear // that borrowing is occuring. Make sure rustdoc is following the same idiom. +#![crate_name = "foo"] + pub struct Ref<'a>(&'a u32); type ARef<'a> = Ref<'a>; @@ -32,15 +34,10 @@ pub fn test4(a: &u32) -> ARef<'_> { Ref(a) } -// Ensure external paths also display elided lifetime -// @has foo/fn.test5.html -// @matches - "Iter<'_" -pub fn test5(a: &Option) -> std::option::Iter { - a.iter() -} - -// @has foo/fn.test6.html -// @matches - "Iter<'_" -pub fn test6(a: &Option) -> std::option::Iter<'_, u32> { - a.iter() -} +// Ensure external paths in inlined docs also display elided lifetime +// @has foo/bar/fn.test5.html +// @matches - "Ref<'_>" +// @has foo/bar/fn.test6.html +// @matches - "Ref<'_>" +#[doc(inline)] +pub extern crate bar; -- cgit 1.4.1-3-g733a5