Skip to content

Commit

Permalink
rustdoc: add support for cross-crate higher-ranked types
Browse files Browse the repository at this point in the history
  • Loading branch information
fmease committed Oct 3, 2023
1 parent 67de150 commit ace85f0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2226,6 +2226,11 @@ pub(crate) fn clean_middle_ty<'tcx>(
}
}

ty::Bound(_, ref ty) => match ty.kind {
ty::BoundTyKind::Param(_, name) => Generic(name),
ty::BoundTyKind::Anon => panic!("unexpected anonymous bound type variable"),
},

ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => {
// If it's already in the same alias, don't get an infinite loop.
if cx.current_type_aliases.contains_key(&def_id) {
Expand Down Expand Up @@ -2254,7 +2259,6 @@ pub(crate) fn clean_middle_ty<'tcx>(

ty::Closure(..) => panic!("Closure"),
ty::Generator(..) => panic!("Generator"),
ty::Bound(..) => panic!("Bound"),
ty::Placeholder(..) => panic!("Placeholder"),
ty::GeneratorWitness(..) => panic!("GeneratorWitness"),
ty::Infer(..) => panic!("Infer"),
Expand Down Expand Up @@ -3097,6 +3101,17 @@ fn clean_bound_vars<'tcx>(
{
Some(GenericParamDef::lifetime(name))
}
ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(did, name)) => Some(GenericParamDef {
name,
kind: GenericParamDefKind::Type {
did,
bounds: Vec::new(),
default: None,
synthetic: false,
},
}),
// FIXME(non_lifetime_binders): Support higher-ranked const parameters.
ty::BoundVariableKind::Const => None,
_ => None,
})
.collect()
Expand Down
10 changes: 10 additions & 0 deletions tests/rustdoc/inline_cross/auxiliary/non_lifetime_binders.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![feature(non_lifetime_binders)]

pub trait Trait<T> {}

pub fn f(_: impl for<T> Trait<T>) {}

pub fn g<T>(_: T)
where
T: for<U> Trait<U>,
{}
13 changes: 13 additions & 0 deletions tests/rustdoc/inline_cross/non_lifetime_binders.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// aux-crate:non_lifetime_binders=non_lifetime_binders.rs
// edition: 2021
#![crate_name = "user"]

// @has user/fn.f.html
// @has - '//pre[@class="rust item-decl"]' "f(_: impl for<T> Trait<T>)"
pub use non_lifetime_binders::f;

// @has user/fn.g.html
// @has - '//pre[@class="rust item-decl"]' "g<T>(_: T)\
// where \
// T: for<U> Trait<U>"
pub use non_lifetime_binders::g;

0 comments on commit ace85f0

Please sign in to comment.