fehler icon indicating copy to clipboard operation
fehler copied to clipboard

throws inserts method body for trait methods

Open gmadrid opened this issue 5 years ago • 0 comments

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.

gmadrid avatar Apr 14 '20 15:04 gmadrid