fehler
fehler copied to clipboard
Fehler didn't support returning `Result<Box<dyn Trait>, _>`
Code:
use fehler::throws;
trait FooTrait {}
struct FooStruct;
struct FooError;
impl FooTrait for FooStruct {}
#[throws(FooError)]
fn foo() -> Box<dyn FooTrait> {
Box::new(FooStruct)
}
Compile result:
Error[E0271]: type mismatch resolving ...
|
104 | #[throws(FooError)]
| ^^^^^^^^^^^^^^^^^^^^^^ expected trait object `dyn mymodule::FooTrait`, found struct `mymodule::FooStruct`
|
= note: expected type `std::boxed::Box<dyn mymodule::FooTrait>`
found struct `std::boxed::Box<mymodule::FooStruct>`
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
It should work if you add as Box<dyn FooTrait> to the return expression, but its frustrating that the cast doesn't happen automatically here the way it normally would. Can you build against master and see if the problem persists?
A possible fix for this issue would be to change the expansion of return expressions from wrapping in ok to wrapping in ok and casting to the ret type.