Skip to content

Commit a94528d

Browse files
authored
Rollup merge of rust-lang#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 rust-lang#81287, that will need to be merged first.
2 parents a5c1085 + 1c60d27 commit a94528d

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

src/librustdoc/json/conversions.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ impl From<clean::ItemKind> for ItemEnum {
162162
ForeignFunctionItem(f) => ItemEnum::FunctionItem(f.into()),
163163
TraitItem(t) => ItemEnum::TraitItem(t.into()),
164164
TraitAliasItem(t) => ItemEnum::TraitAliasItem(t.into()),
165-
MethodItem(m, _) => ItemEnum::MethodItem(m.into()),
166-
TyMethodItem(m) => ItemEnum::MethodItem(m.into()),
165+
MethodItem(m, _) => ItemEnum::MethodItem(from_function_method(m, true)),
166+
TyMethodItem(m) => ItemEnum::MethodItem(from_function_method(m, false)),
167167
ImplItem(i) => ItemEnum::ImplItem(i.into()),
168168
StaticItem(s) => ItemEnum::StaticItem(s.into()),
169169
ForeignStaticItem(s) => ItemEnum::StaticItem(s.into()),
@@ -435,15 +435,13 @@ impl From<clean::Impl> for Impl {
435435
}
436436
}
437437

438-
impl From<clean::Function> for Method {
439-
fn from(function: clean::Function) -> Self {
440-
let clean::Function { header, decl, generics, all_types: _, ret_types: _ } = function;
441-
Method {
442-
decl: decl.into(),
443-
generics: generics.into(),
444-
header: stringify_header(&header),
445-
has_body: true,
446-
}
438+
crate fn from_function_method(function: clean::Function, has_body: bool) -> Method {
439+
let clean::Function { header, decl, generics, all_types: _, ret_types: _ } = function;
440+
Method {
441+
decl: decl.into(),
442+
generics: generics.into(),
443+
header: stringify_header(&header),
444+
has_body,
447445
}
448446
}
449447

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// @has has_body.json "$.index[*][?(@.name=='Foo')]"
2+
pub trait Foo {
3+
// @has - "$.index[*][?(@.name=='no_self')].inner.has_body" false
4+
fn no_self();
5+
// @has - "$.index[*][?(@.name=='move_self')].inner.has_body" false
6+
fn move_self(self);
7+
// @has - "$.index[*][?(@.name=='ref_self')].inner.has_body" false
8+
fn ref_self(&self);
9+
10+
// @has - "$.index[*][?(@.name=='no_self_def')].inner.has_body" true
11+
fn no_self_def() {}
12+
// @has - "$.index[*][?(@.name=='move_self_def')].inner.has_body" true
13+
fn move_self_def(self) {}
14+
// @has - "$.index[*][?(@.name=='ref_self_def')].inner.has_body" true
15+
fn ref_self_def(&self) {}
16+
}
17+
18+
pub trait Bar: Clone {
19+
// @has - "$.index[*][?(@.name=='method')].inner.has_body" false
20+
fn method(&self, param: usize);
21+
}

0 commit comments

Comments
 (0)