Skip to content

Commit 7ec50b6

Browse files
committed
rustdoc: add test for cross-crate trait-object types
as well as some FIXMEs
1 parent 71561f8 commit 7ec50b6

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

Diff for: src/librustdoc/clean/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,9 @@ pub(crate) fn clean_middle_ty<'tcx>(
16831683

16841684
inline::record_extern_fqn(cx, did, ItemType::Trait);
16851685

1686+
// FIXME(fmease): Hide the trait-object lifetime bound if it coincides with its default
1687+
// to partially address #44306. Follow the rules outlined at
1688+
// https://doc.rust-lang.org/reference/lifetime-elision.html#default-trait-object-lifetimes
16861689
let lifetime = clean_middle_region(*reg);
16871690
let mut bounds = dids
16881691
.map(|did| {

Diff for: src/test/rustdoc/assoc-consts.rs

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub fn f(_: &(ToString + 'static)) {}
4646
impl Bar {
4747
// @has assoc_consts/struct.Bar.html '//*[@id="associatedconstant.F"]' \
4848
// "const F: fn(_: &(dyn ToString + 'static))"
49+
// FIXME(fmease): Hide default lifetime, render "const F: fn(_: &dyn ToString)"
4950
pub const F: fn(_: &(ToString + 'static)) = f;
5051
}
5152

Diff for: src/test/rustdoc/inline_cross/auxiliary/dyn_trait.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
pub type Ty0 = dyn for<'any> FnOnce(&'any str) -> bool;
2+
3+
pub type Ty1<'obj> = dyn std::fmt::Display + 'obj;
4+
5+
pub type Ty2 = dyn for<'a, 'r> Container<'r, Item<'a, 'static> = ()>;
6+
7+
pub type Ty3<'s> = &'s dyn ToString;
8+
9+
pub fn func0(_: &(dyn Fn() + '_)) {}
10+
11+
pub fn func1<'func>(_: &(dyn Fn() + 'func)) {}
12+
13+
pub trait Container<'r> {
14+
type Item<'a, 'ctx>;
15+
}
16+
17+
pub trait Shape<'a> {}

Diff for: src/test/rustdoc/inline_cross/dyn_trait.rs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#![crate_name = "user"]
2+
3+
// aux-crate:dyn_trait=dyn_trait.rs
4+
// edition:2021
5+
6+
// @has user/type.Ty0.html
7+
// @has - '//*[@class="item-decl"]//code' "dyn for<'any> FnOnce(&'any str) -> bool + 'static"
8+
// FIXME(fmease): Hide default lifetime bound `'static`
9+
pub use dyn_trait::Ty0;
10+
11+
// @has user/type.Ty1.html
12+
// @has - '//*[@class="item-decl"]//code' "dyn Display + 'obj"
13+
pub use dyn_trait::Ty1;
14+
15+
// @has user/type.Ty2.html
16+
// @has - '//*[@class="item-decl"]//code' "dyn for<'a, 'r> Container<'r, Item<'a, 'static> = ()>"
17+
pub use dyn_trait::Ty2;
18+
19+
// @has user/type.Ty3.html
20+
// @has - '//*[@class="item-decl"]//code' "&'s (dyn ToString + 's)"
21+
// FIXME(fmease): Hide default lifetime bound, render "&'s dyn ToString"
22+
pub use dyn_trait::Ty3;
23+
24+
// @has user/fn.func0.html
25+
// @has - '//pre[@class="rust fn"]' "func0(_: &dyn Fn())"
26+
// FIXME(fmease): Show placeholder-lifetime bound, render "func0(_: &(dyn Fn() + '_))"
27+
pub use dyn_trait::func0;
28+
29+
// @has user/fn.func1.html
30+
// @has - '//pre[@class="rust fn"]' "func1<'func>(_: &(dyn Fn() + 'func))"
31+
pub use dyn_trait::func1;

0 commit comments

Comments
 (0)