Trait objects without an explicit `dyn` are deprecated

I have the code for iotedge which using the following:

    fn from(err: &'a Error) -> Self {
        match Fail::find_root_cause(err).downcast_ref::<ErrorKind>() {
            Some(ErrorKind::NotFound(_)) => ModuleRuntimeErrorReason::NotFound,
            _ => ModuleRuntimeErrorReason::Other,
While compiling, I get the following:
error: trait objects without an explicit `dyn` are deprecated
|    --> edgelet-docker/src/
|     |
| 151 |         match Fail::find_root_cause(err).downcast_ref::<ErrorKind>() {
|     |               ^^^^ help: use `dyn`: `<dyn Fail>`
|     |

Being a newbie, unable to understand how do I fix it. Any input would be of great help

Please format your code using backticks (```) so people can read it.

1 Like

Thanks Michael. Edited the post

Did you try replacing Fail with dyn Fail as the compiler suggests:

match dyn Fail::find_root_cause(err).downcast_ref::() {


match <dyn Fail>::find_root_cause(err).downcast_ref::() {

( I'm not sure which form is necessary)

1 Like

The trait name can be be a full path, like dyn std::fmt::Debug, so the <>s are there because Fail::find_root_cause isn't the trait.


Thanks. This helps.

Works and resolves the issue.