Skip to content

Commit ace85f0

Browse files
committed
rustdoc: add support for cross-crate higher-ranked types
1 parent 67de150 commit ace85f0

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

src/librustdoc/clean/mod.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -2226,6 +2226,11 @@ pub(crate) fn clean_middle_ty<'tcx>(
22262226
}
22272227
}
22282228

2229+
ty::Bound(_, ref ty) => match ty.kind {
2230+
ty::BoundTyKind::Param(_, name) => Generic(name),
2231+
ty::BoundTyKind::Anon => panic!("unexpected anonymous bound type variable"),
2232+
},
2233+
22292234
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => {
22302235
// If it's already in the same alias, don't get an infinite loop.
22312236
if cx.current_type_aliases.contains_key(&def_id) {
@@ -2254,7 +2259,6 @@ pub(crate) fn clean_middle_ty<'tcx>(
22542259

22552260
ty::Closure(..) => panic!("Closure"),
22562261
ty::Generator(..) => panic!("Generator"),
2257-
ty::Bound(..) => panic!("Bound"),
22582262
ty::Placeholder(..) => panic!("Placeholder"),
22592263
ty::GeneratorWitness(..) => panic!("GeneratorWitness"),
22602264
ty::Infer(..) => panic!("Infer"),
@@ -3097,6 +3101,17 @@ fn clean_bound_vars<'tcx>(
30973101
{
30983102
Some(GenericParamDef::lifetime(name))
30993103
}
3104+
ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(did, name)) => Some(GenericParamDef {
3105+
name,
3106+
kind: GenericParamDefKind::Type {
3107+
did,
3108+
bounds: Vec::new(),
3109+
default: None,
3110+
synthetic: false,
3111+
},
3112+
}),
3113+
// FIXME(non_lifetime_binders): Support higher-ranked const parameters.
3114+
ty::BoundVariableKind::Const => None,
31003115
_ => None,
31013116
})
31023117
.collect()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(non_lifetime_binders)]
2+
3+
pub trait Trait<T> {}
4+
5+
pub fn f(_: impl for<T> Trait<T>) {}
6+
7+
pub fn g<T>(_: T)
8+
where
9+
T: for<U> Trait<U>,
10+
{}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// aux-crate:non_lifetime_binders=non_lifetime_binders.rs
2+
// edition: 2021
3+
#![crate_name = "user"]
4+
5+
// @has user/fn.f.html
6+
// @has - '//pre[@class="rust item-decl"]' "f(_: impl for<T> Trait<T>)"
7+
pub use non_lifetime_binders::f;
8+
9+
// @has user/fn.g.html
10+
// @has - '//pre[@class="rust item-decl"]' "g<T>(_: T)\
11+
// where \
12+
// T: for<U> Trait<U>"
13+
pub use non_lifetime_binders::g;

0 commit comments

Comments
 (0)