Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
Next Next commit
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.
  • Loading branch information
Enselic committed Jun 23, 2025
commit 7c0ef44d4f7b43ba79c8a45ff357b4c8c3f94881
29 changes: 16 additions & 13 deletions src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions tests/rustdoc-json/generic-args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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