Skip to content

throws inserts method body for trait methods #39

@gmadrid

Description

@gmadrid

This code:

trait Example {
    #[throws]
    fn foo();
}

expands to this:

trait Example {
    fn foo() -> ::core::result::Result<(), Error> {
        <_ as ::fehler::__internal::_Succeed>::from_ok(())
    }
}

This inserts a default method for the trait which has two annoying effects:

  1. Complaints about an extra semi-colon
  2. No complaints in trait implementations that don't provide what should be a required method.

This is using rust 1.42.0 with fehler 1.0.0.

The problem appears to be in Throws::fold because the trait method is parsed by parse for ImplItemMethod. The implementation of this function in syn includes this comment:

                // Accept methods without a body in an impl block because
                // rustc's *parser* does not reject them (the compilation error
                // is emitted later than parsing) and it can be useful for macro
                // DSLs.

which causes this problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions