diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2021-02-05 12:25:54 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-05 12:25:54 +0100 |
| commit | 0493e3aa88e0a9d74eaa29b886b10b4a6b1fc053 (patch) | |
| tree | 331758bcac4893d4b1c78dddaace05581a883703 | |
| parent | 8d49ca11a2ec5492626f7a62fe2bef8daefe9e72 (diff) | |
| parent | 1c60d27a52ee0341c3848f170c2635d5e74bd0a8 (diff) | |
| download | rust-0493e3aa88e0a9d74eaa29b886b10b4a6b1fc053.tar.gz rust-0493e3aa88e0a9d74eaa29b886b10b4a6b1fc053.zip | |
Rollup merge of #81318 - CraftSpider:json-trait-fix, r=jyn514
rustdoc-json: Fix has_body Previously, `has_body` was always true. Now propagate the type of the method to set it correctly. Relies on #81287, that will need to be merged first.
| -rw-r--r-- | src/librustdoc/json/conversions.rs | 20 | ||||
| -rw-r--r-- | src/test/rustdoc-json/traits/has_body.rs | 21 |
2 files changed, 30 insertions, 11 deletions
diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index b2e5c8834b8..438a8d57cc2 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -162,8 +162,8 @@ impl From<clean::ItemKind> for ItemEnum { ForeignFunctionItem(f) => ItemEnum::FunctionItem(f.into()), TraitItem(t) => ItemEnum::TraitItem(t.into()), TraitAliasItem(t) => ItemEnum::TraitAliasItem(t.into()), - MethodItem(m, _) => ItemEnum::MethodItem(m.into()), - TyMethodItem(m) => ItemEnum::MethodItem(m.into()), + MethodItem(m, _) => ItemEnum::MethodItem(from_function_method(m, true)), + TyMethodItem(m) => ItemEnum::MethodItem(from_function_method(m, false)), ImplItem(i) => ItemEnum::ImplItem(i.into()), StaticItem(s) => ItemEnum::StaticItem(s.into()), ForeignStaticItem(s) => ItemEnum::StaticItem(s.into()), @@ -435,15 +435,13 @@ impl From<clean::Impl> for Impl { } } -impl From<clean::Function> for Method { - fn from(function: clean::Function) -> Self { - let clean::Function { header, decl, generics, all_types: _, ret_types: _ } = function; - Method { - decl: decl.into(), - generics: generics.into(), - header: stringify_header(&header), - has_body: true, - } +crate fn from_function_method(function: clean::Function, has_body: bool) -> Method { + let clean::Function { header, decl, generics, all_types: _, ret_types: _ } = function; + Method { + decl: decl.into(), + generics: generics.into(), + header: stringify_header(&header), + has_body, } } diff --git a/src/test/rustdoc-json/traits/has_body.rs b/src/test/rustdoc-json/traits/has_body.rs new file mode 100644 index 00000000000..44dacb1ee75 --- /dev/null +++ b/src/test/rustdoc-json/traits/has_body.rs @@ -0,0 +1,21 @@ +// @has has_body.json "$.index[*][?(@.name=='Foo')]" +pub trait Foo { + // @has - "$.index[*][?(@.name=='no_self')].inner.has_body" false + fn no_self(); + // @has - "$.index[*][?(@.name=='move_self')].inner.has_body" false + fn move_self(self); + // @has - "$.index[*][?(@.name=='ref_self')].inner.has_body" false + fn ref_self(&self); + + // @has - "$.index[*][?(@.name=='no_self_def')].inner.has_body" true + fn no_self_def() {} + // @has - "$.index[*][?(@.name=='move_self_def')].inner.has_body" true + fn move_self_def(self) {} + // @has - "$.index[*][?(@.name=='ref_self_def')].inner.has_body" true + fn ref_self_def(&self) {} +} + +pub trait Bar: Clone { + // @has - "$.index[*][?(@.name=='method')].inner.has_body" false + fn method(&self, param: usize); +} |
