Skip to content

Commit a2f5c72

Browse files
committed
Fix has_body for trait methods
1 parent 74500b9 commit a2f5c72

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-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

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

0 commit comments

Comments
 (0)