Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc-json: Fix has_body #81318

Merged
merged 2 commits into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 9 additions & 11 deletions src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
jyn514 marked this conversation as resolved.
Show resolved Hide resolved
ImplItem(i) => ItemEnum::ImplItem(i.into()),
StaticItem(s) => ItemEnum::StaticItem(s.into()),
ForeignStaticItem(s) => ItemEnum::StaticItem(s.into()),
Expand Down Expand Up @@ -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,
}
}

Expand Down
21 changes: 21 additions & 0 deletions src/test/rustdoc-json/traits/has_body.rs
Original file line number Diff line number Diff line change
@@ -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);
}