rustdoc-json: Keep empty generic args if parenthesized
Because in the case of for example
pub fn my_fn3(f: impl FnMut()) {}
we want to keep `()` even if it is empty since that matches e.g. Rust
syntax requirements.
This commit is contained in:
parent
42245d34d2
commit
7c0ef44d4f
2 changed files with 19 additions and 13 deletions
|
|
@ -194,22 +194,25 @@ impl FromClean<attrs::Deprecation> for Deprecation {
|
|||
}
|
||||
|
||||
impl FromClean<clean::GenericArgs> for Option<Box<GenericArgs>> {
|
||||
fn from_clean(args: &clean::GenericArgs, renderer: &JsonRenderer<'_>) -> Self {
|
||||
fn from_clean(generic_args: &clean::GenericArgs, renderer: &JsonRenderer<'_>) -> Self {
|
||||
use clean::GenericArgs::*;
|
||||
if args.is_empty() {
|
||||
return None;
|
||||
}
|
||||
Some(Box::new(match args {
|
||||
AngleBracketed { args, constraints } => GenericArgs::AngleBracketed {
|
||||
args: args.into_json(renderer),
|
||||
constraints: constraints.into_json(renderer),
|
||||
},
|
||||
Parenthesized { inputs, output } => GenericArgs::Parenthesized {
|
||||
match generic_args {
|
||||
AngleBracketed { args, constraints } => {
|
||||
if generic_args.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(Box::new(GenericArgs::AngleBracketed {
|
||||
args: args.into_json(renderer),
|
||||
constraints: constraints.into_json(renderer),
|
||||
}))
|
||||
}
|
||||
}
|
||||
Parenthesized { inputs, output } => Some(Box::new(GenericArgs::Parenthesized {
|
||||
inputs: inputs.into_json(renderer),
|
||||
output: output.into_json(renderer),
|
||||
},
|
||||
ReturnTypeNotation => GenericArgs::ReturnTypeNotation,
|
||||
}))
|
||||
})),
|
||||
ReturnTypeNotation => Some(Box::new(GenericArgs::ReturnTypeNotation)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,4 +17,7 @@ pub fn my_fn1(_: <MyStruct as MyTrait>::MyType) {}
|
|||
//@ is "$.index[?(@.name=='my_fn2')].inner.function.sig.inputs[0][1].dyn_trait.traits[0].trait.args.angle_bracketed.constraints[0].args" null
|
||||
pub fn my_fn2(_: IntoIterator<Item = MyStruct, IntoIter = impl Clone>) {}
|
||||
|
||||
//@ is "$.index[?(@.name=='my_fn3')].inner.function.sig.inputs[0][1].impl_trait[0].trait_bound.trait.args.parenthesized.inputs" []
|
||||
pub fn my_fn3(f: impl FnMut()) {}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue