mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Rollup merge of #96647 - Enselic:fix-hrtb-for-wherepredicate, r=CraftSpider
rustdoc-json: Fix HRTBs for WherePredicate::BoundPredicate Information about HRTBs are already present for `GenericBound:: TraitBound` and `FunctionPointer`. This PR adds HRTB info also to `WherePredicate::BoundPredicate`. Use the same field name and type as for the other ones (`generic_params: Vec<GenericParamDef>`). I have verified that this gives rustdoc JSON clients the data they need and in a format that is easy to work with (see https://github.com/Enselic/public-api/pull/92). I will be happy to add tests for this change (and bump `FORMAT_VERSION` which I just realized I forgot), but it is always nice to get one round of feedback first, so that I don't put a lot of effort into tests that then have to be discarded. `@rustbot` modify labels: +T-rustdoc +A-rustdoc-json
This commit is contained in:
commit
ce49ce2f7e
@ -350,10 +350,16 @@ impl FromWithTcx<clean::WherePredicate> for WherePredicate {
|
||||
fn from_tcx(predicate: clean::WherePredicate, tcx: TyCtxt<'_>) -> Self {
|
||||
use clean::WherePredicate::*;
|
||||
match predicate {
|
||||
BoundPredicate { ty, bounds, .. } => WherePredicate::BoundPredicate {
|
||||
BoundPredicate { ty, bounds, bound_params } => WherePredicate::BoundPredicate {
|
||||
type_: ty.into_tcx(tcx),
|
||||
bounds: bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),
|
||||
// FIXME: add `bound_params` to rustdoc-json-params?
|
||||
generic_params: bound_params
|
||||
.into_iter()
|
||||
.map(|x| GenericParamDef {
|
||||
name: x.0.to_string(),
|
||||
kind: GenericParamDefKind::Lifetime { outlives: vec![] },
|
||||
})
|
||||
.collect(),
|
||||
},
|
||||
RegionPredicate { lifetime, bounds } => WherePredicate::RegionPredicate {
|
||||
lifetime: lifetime.0.to_string(),
|
||||
|
@ -9,7 +9,7 @@ use std::path::PathBuf;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// rustdoc format-version.
|
||||
pub const FORMAT_VERSION: u32 = 14;
|
||||
pub const FORMAT_VERSION: u32 = 15;
|
||||
|
||||
/// A `Crate` is the root of the emitted JSON blob. It contains all type/documentation information
|
||||
/// about the language items in the local crate, as well as info about external items to allow
|
||||
@ -391,6 +391,14 @@ pub enum WherePredicate {
|
||||
#[serde(rename = "type")]
|
||||
type_: Type,
|
||||
bounds: Vec<GenericBound>,
|
||||
/// Used for Higher-Rank Trait Bounds (HRTBs)
|
||||
/// ```plain
|
||||
/// where for<'a> &'a T: Iterator,"
|
||||
/// ^^^^^^^
|
||||
/// |
|
||||
/// this part
|
||||
/// ```
|
||||
generic_params: Vec<GenericParamDef>,
|
||||
},
|
||||
RegionPredicate {
|
||||
lifetime: String,
|
||||
@ -408,7 +416,13 @@ pub enum GenericBound {
|
||||
TraitBound {
|
||||
#[serde(rename = "trait")]
|
||||
trait_: Type,
|
||||
/// Used for HRTBs
|
||||
/// Used for Higher-Rank Trait Bounds (HRTBs)
|
||||
/// ```plain
|
||||
/// where F: for<'a, 'b> Fn(&'a u8, &'b u8)
|
||||
/// ^^^^^^^^^^^
|
||||
/// |
|
||||
/// this part
|
||||
/// ```
|
||||
generic_params: Vec<GenericParamDef>,
|
||||
modifier: TraitBoundModifier,
|
||||
},
|
||||
@ -487,6 +501,13 @@ pub enum Type {
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct FunctionPointer {
|
||||
pub decl: FnDecl,
|
||||
/// Used for Higher-Rank Trait Bounds (HRTBs)
|
||||
/// ```plain
|
||||
/// for<'c> fn(val: &'c i32) -> i32
|
||||
/// ^^^^^^^
|
||||
/// |
|
||||
/// this part
|
||||
/// ```
|
||||
pub generic_params: Vec<GenericParamDef>,
|
||||
pub header: Header,
|
||||
}
|
||||
|
14
src/test/rustdoc-json/fn_pointer/generics.rs
Normal file
14
src/test/rustdoc-json/fn_pointer/generics.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// ignore-tidy-linelength
|
||||
|
||||
#![feature(no_core)]
|
||||
#![no_core]
|
||||
|
||||
// @count generics.json "$.index[*][?(@.name=='WithHigherRankTraitBounds')].inner.type.inner.decl.inputs[*]" 1
|
||||
// @is - "$.index[*][?(@.name=='WithHigherRankTraitBounds')].inner.type.inner.decl.inputs[0][0]" '"val"'
|
||||
// @is - "$.index[*][?(@.name=='WithHigherRankTraitBounds')].inner.type.inner.decl.inputs[0][1].kind" '"borrowed_ref"'
|
||||
// @is - "$.index[*][?(@.name=='WithHigherRankTraitBounds')].inner.type.inner.decl.inputs[0][1].inner.lifetime" \"\'c\"
|
||||
// @is - "$.index[*][?(@.name=='WithHigherRankTraitBounds')].inner.type.inner.decl.output" '{ "kind": "primitive", "inner": "i32" }'
|
||||
// @count - "$.index[*][?(@.name=='WithHigherRankTraitBounds')].inner.type.inner.generic_params[*]" 1
|
||||
// @is - "$.index[*][?(@.name=='WithHigherRankTraitBounds')].inner.type.inner.generic_params[0].name" \"\'c\"
|
||||
// @is - "$.index[*][?(@.name=='WithHigherRankTraitBounds')].inner.type.inner.generic_params[0].kind" '{ "lifetime": { "outlives": [] } }'
|
||||
pub type WithHigherRankTraitBounds = for<'c> fn(val: &'c i32) -> i32;
|
@ -6,6 +6,9 @@
|
||||
// @set foo = generic_args.json "$.index[*][?(@.name=='Foo')].id"
|
||||
pub trait Foo {}
|
||||
|
||||
// @set generic_foo = generic_args.json "$.index[*][?(@.name=='GenericFoo')].id"
|
||||
pub trait GenericFoo<'a> {}
|
||||
|
||||
// @is - "$.index[*][?(@.name=='generics')].inner.generics.where_predicates" "[]"
|
||||
// @count - "$.index[*][?(@.name=='generics')].inner.generics.params[*]" 1
|
||||
// @is - "$.index[*][?(@.name=='generics')].inner.generics.params[0].name" '"F"'
|
||||
@ -29,19 +32,40 @@ pub fn generics<F: Foo>(f: F) {}
|
||||
// @is - "$.index[*][?(@.name=='impl_trait')].inner.decl.inputs[0][1].inner[0].trait_bound.trait.inner.id" $foo
|
||||
pub fn impl_trait(f: impl Foo) {}
|
||||
|
||||
// @count - "$.index[*][?(@.name=='where_clase')].inner.generics.params[*]" 1
|
||||
// @count - "$.index[*][?(@.name=='where_clase')].inner.generics.params[*]" 3
|
||||
// @is - "$.index[*][?(@.name=='where_clase')].inner.generics.params[0].name" '"F"'
|
||||
// @is - "$.index[*][?(@.name=='where_clase')].inner.generics.params[0].kind" '{"type": {"bounds": [], "default": null, "synthetic": false}}'
|
||||
// @count - "$.index[*][?(@.name=='where_clase')].inner.decl.inputs[*]" 1
|
||||
// @count - "$.index[*][?(@.name=='where_clase')].inner.decl.inputs[*]" 3
|
||||
// @is - "$.index[*][?(@.name=='where_clase')].inner.decl.inputs[0][0]" '"f"'
|
||||
// @is - "$.index[*][?(@.name=='where_clase')].inner.decl.inputs[0][1].kind" '"generic"'
|
||||
// @is - "$.index[*][?(@.name=='where_clase')].inner.decl.inputs[0][1].inner" '"F"'
|
||||
// @count - "$.index[*][?(@.name=='where_clase')].inner.generics.where_predicates[*]" 1
|
||||
// @count - "$.index[*][?(@.name=='where_clase')].inner.generics.where_predicates[*]" 3
|
||||
|
||||
// @is - "$.index[*][?(@.name=='where_clase')].inner.generics.where_predicates[0].bound_predicate.type" '{"inner": "F", "kind": "generic"}'
|
||||
// @count - "$.index[*][?(@.name=='where_clase')].inner.generics.where_predicates[0].bound_predicate.bounds[*]" 1
|
||||
// @is - "$.index[*][?(@.name=='where_clase')].inner.generics.where_predicates[0].bound_predicate.bounds[0].trait_bound.trait.inner.id" $foo
|
||||
pub fn where_clase<F>(f: F)
|
||||
|
||||
// @is - "$.index[*][?(@.name=='where_clase')].inner.generics.where_predicates[1].bound_predicate.type" '{"inner": "G", "kind": "generic"}'
|
||||
// @count - "$.index[*][?(@.name=='where_clase')].inner.generics.where_predicates[1].bound_predicate.bounds[*]" 1
|
||||
// @is - "$.index[*][?(@.name=='where_clase')].inner.generics.where_predicates[1].bound_predicate.bounds[0].trait_bound.trait.inner.id" $generic_foo
|
||||
// @count - "$.index[*][?(@.name=='where_clase')].inner.generics.where_predicates[1].bound_predicate.bounds[0].trait_bound.generic_params[*]" 1
|
||||
// @is - "$.index[*][?(@.name=='where_clase')].inner.generics.where_predicates[1].bound_predicate.bounds[0].trait_bound.generic_params[0].name" \"\'a\"
|
||||
// @is - "$.index[*][?(@.name=='where_clase')].inner.generics.where_predicates[1].bound_predicate.bounds[0].trait_bound.generic_params[0].kind" '{ "lifetime": { "outlives": [] } }'
|
||||
// @is - "$.index[*][?(@.name=='where_clase')].inner.generics.where_predicates[1].bound_predicate.generic_params" "[]"
|
||||
|
||||
// @is - "$.index[*][?(@.name=='where_clase')].inner.generics.where_predicates[2].bound_predicate.type.kind" '"borrowed_ref"'
|
||||
// @is - "$.index[*][?(@.name=='where_clase')].inner.generics.where_predicates[2].bound_predicate.type.inner.lifetime" \"\'b\"
|
||||
// @is - "$.index[*][?(@.name=='where_clase')].inner.generics.where_predicates[2].bound_predicate.type.inner.type" '{"inner": "H", "kind": "generic"}'
|
||||
// @count - "$.index[*][?(@.name=='where_clase')].inner.generics.where_predicates[2].bound_predicate.bounds[*]" 1
|
||||
// @is - "$.index[*][?(@.name=='where_clase')].inner.generics.where_predicates[2].bound_predicate.bounds[0].trait_bound.trait.inner.id" $foo
|
||||
// @is - "$.index[*][?(@.name=='where_clase')].inner.generics.where_predicates[2].bound_predicate.bounds[0].trait_bound.generic_params" "[]"
|
||||
// @count - "$.index[*][?(@.name=='where_clase')].inner.generics.where_predicates[2].bound_predicate.generic_params[*]" 1
|
||||
// @is - "$.index[*][?(@.name=='where_clase')].inner.generics.where_predicates[2].bound_predicate.generic_params[0].name" \"\'b\"
|
||||
// @is - "$.index[*][?(@.name=='where_clase')].inner.generics.where_predicates[2].bound_predicate.generic_params[0].kind" '{ "lifetime": { "outlives": [] } }'
|
||||
pub fn where_clase<F, G, H>(f: F, g: G, h: H)
|
||||
where
|
||||
F: Foo,
|
||||
G: for<'a> GenericFoo<'a>,
|
||||
for<'b> &'b H: Foo,
|
||||
{
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user