Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: fix & clean up handling of cross-crate higher-ranked parameters #116388

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
rustdoc: add support for cross-crate higher-ranked types
  • Loading branch information
fmease committed Oct 3, 2023
commit ace85f0ae31052e5928a19797762077444f9e93c
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;
Loading