Skip to content

Commit 010af6a

Browse files
Rollup merge of #142932 - Enselic:keep-empty-generic-params, r=aDotInTheVoid
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 is an amendment to #142502, so: r? ``@aDotInTheVoid`` cc ``@nnethercote`` cc cargo-public-api/cargo-public-api#798
2 parents 7375c44 + 7c0ef44 commit 010af6a

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/librustdoc/json/conversions.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -194,22 +194,25 @@ impl FromClean<attrs::Deprecation> for Deprecation {
194194
}
195195

196196
impl FromClean<clean::GenericArgs> for Option<Box<GenericArgs>> {
197-
fn from_clean(args: &clean::GenericArgs, renderer: &JsonRenderer<'_>) -> Self {
197+
fn from_clean(generic_args: &clean::GenericArgs, renderer: &JsonRenderer<'_>) -> Self {
198198
use clean::GenericArgs::*;
199-
if args.is_empty() {
200-
return None;
201-
}
202-
Some(Box::new(match args {
203-
AngleBracketed { args, constraints } => GenericArgs::AngleBracketed {
204-
args: args.into_json(renderer),
205-
constraints: constraints.into_json(renderer),
206-
},
207-
Parenthesized { inputs, output } => GenericArgs::Parenthesized {
199+
match generic_args {
200+
AngleBracketed { args, constraints } => {
201+
if generic_args.is_empty() {
202+
None
203+
} else {
204+
Some(Box::new(GenericArgs::AngleBracketed {
205+
args: args.into_json(renderer),
206+
constraints: constraints.into_json(renderer),
207+
}))
208+
}
209+
}
210+
Parenthesized { inputs, output } => Some(Box::new(GenericArgs::Parenthesized {
208211
inputs: inputs.into_json(renderer),
209212
output: output.into_json(renderer),
210-
},
211-
ReturnTypeNotation => GenericArgs::ReturnTypeNotation,
212-
}))
213+
})),
214+
ReturnTypeNotation => Some(Box::new(GenericArgs::ReturnTypeNotation)),
215+
}
213216
}
214217
}
215218

tests/rustdoc-json/generic-args.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@ pub fn my_fn1(_: <MyStruct as MyTrait>::MyType) {}
1717
//@ is "$.index[?(@.name=='my_fn2')].inner.function.sig.inputs[0][1].dyn_trait.traits[0].trait.args.angle_bracketed.constraints[0].args" null
1818
pub fn my_fn2(_: IntoIterator<Item = MyStruct, IntoIter = impl Clone>) {}
1919

20+
//@ is "$.index[?(@.name=='my_fn3')].inner.function.sig.inputs[0][1].impl_trait[0].trait_bound.trait.args.parenthesized.inputs" []
21+
pub fn my_fn3(f: impl FnMut()) {}
22+
2023
fn main() {}

0 commit comments

Comments
 (0)