Stream: rustdoc

Topic: Representation of defaulted, associated methods


view this post on Zulip HeroicKatora (Jan 23 2021 at 23:56):

How would one differentiate trait methods that are defaulted from those that must be provided? It seems that both kinds of Method items have has_body: true. Is this a bug?

view this post on Zulip CraftSpider (Jan 24 2021 at 00:22):

According to a quick glance at the RFC, has_body should be false in a trait definition with, well, no body. So it sounds like a bug. I'll take a look, and see if I can write up a fix + add some tests

view this post on Zulip HeroicKatora (Jan 24 2021 at 00:31):

Reproduction case:

pub trait ThisIsATrait: Clone {
    /// An ordinary method taking `&self`.
    fn method(&self, param: usize);
}
Warning: Unhandled trait item: Item { id: Id("0:25"), crate_id: 0, name: Some("method"), source: Some(Span { filename: "src/lib.rs", begin: (41, 4), end: (41, 35) }), visibility: Public, docs: "An ordinary method taking `&self`.", links: {}, attrs: [], deprecation: None, kind: Method, inner: MethodItem(Method { decl: FnDecl { inputs: [("self", BorrowedRef { lifetime: None, mutable: false, type_: Generic("Self") }), ("param", Primitive("usize"))], output: None, c_variadic: false }, generics: Generics { params: [], where_predicates: [] }, header: "", has_body: true }) }

view this post on Zulip HeroicKatora (Jan 24 2021 at 00:34):

Another interesting case: Method does not have an ABI but it is valid to add an ABI annotation to trait methods.

view this post on Zulip CraftSpider (Jan 24 2021 at 00:54):

has_body: true - nice

view this post on Zulip CraftSpider (Jan 24 2021 at 00:57):

Okay, so a clean::Function doesn't provide that item, and the way From was implemented is throwing out the extra data. I think I know how to fix it :P

view this post on Zulip CraftSpider (Jan 24 2021 at 01:48):

PR up to fix it: https://github.com/rust-lang/rust/pull/81318


Last updated: Oct 11 2021 at 22:34 UTC