diff options
| author | León Orell Valerian Liehr <me@fmease.dev> | 2023-10-03 17:41:25 +0200 |
|---|---|---|
| committer | León Orell Valerian Liehr <me@fmease.dev> | 2023-10-03 17:41:25 +0200 |
| commit | ace85f0ae31052e5928a19797762077444f9e93c (patch) | |
| tree | 1425e06d7402a22d8801274c4d9fc612ceb811b6 | |
| parent | 67de1509f394414c2987af32a952a6fe66ad815a (diff) | |
| download | rust-ace85f0ae31052e5928a19797762077444f9e93c.tar.gz rust-ace85f0ae31052e5928a19797762077444f9e93c.zip | |
rustdoc: add support for cross-crate higher-ranked types
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 17 | ||||
| -rw-r--r-- | tests/rustdoc/inline_cross/auxiliary/non_lifetime_binders.rs | 10 | ||||
| -rw-r--r-- | tests/rustdoc/inline_cross/non_lifetime_binders.rs | 13 |
3 files changed, 39 insertions, 1 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 00d5a254627..84749a77fa7 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -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) { @@ -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"), @@ -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() diff --git a/tests/rustdoc/inline_cross/auxiliary/non_lifetime_binders.rs b/tests/rustdoc/inline_cross/auxiliary/non_lifetime_binders.rs new file mode 100644 index 00000000000..9170be16892 --- /dev/null +++ b/tests/rustdoc/inline_cross/auxiliary/non_lifetime_binders.rs @@ -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>, +{} diff --git a/tests/rustdoc/inline_cross/non_lifetime_binders.rs b/tests/rustdoc/inline_cross/non_lifetime_binders.rs new file mode 100644 index 00000000000..9d3085c3ef2 --- /dev/null +++ b/tests/rustdoc/inline_cross/non_lifetime_binders.rs @@ -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; |
