rust-lang / rust-lang/rust

`Box<dyn std::error::Error>` fails to satisfy `TryFrom::Error: std::error::Error`

Open
#149,086 2 comments 0 reactions 1 assignee View on GitHub

@JaredDyreson is already working on this.

Since Nov 22, 2025.

A-diagnostics A-dyn-trait A-error-handling D-newcomer-roadblock T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

fn main() {
    foo::<Bar>();
}

fn foo<T>() -> Result<T, T::Error>
where
    T: TryFrom<i64, Error: std::error::Error>,
{
    todo!();
}

struct Bar;

impl TryFrom<i64> for Bar {
    type Error = Box<dyn std::error::Error>;

    fn try_from(_: i64) -> Result<Self, Self::Error> {
        Ok(Self)
    }
}

I expected to see this happen: It compile success.

Instead, this happened:

error[E0277]: the size for values of type `(dyn std::error::Error + 'static)` cannot be known at compilation time
 --> src/main.rs:2:11
  |
2 |     foo::<Bar>();
  |           ^^^ doesn't have a size known at compile-time
  |
  = help: the trait `Sized` is not implemented for `(dyn std::error::Error + 'static)`
  = help: the trait `std::error::Error` is implemented for `Box<E>`
  = note: required for `Box<(dyn std::error::Error + 'static)>` to implement `std::error::Error`
note: required by a bound in `foo`
 --> src/main.rs:7:28
  |
5 | fn foo<T>() -> Result<T, T::Error>
  |    --- required by a bound in this function
6 | where
7 |     T: TryFrom<i64, Error: std::error::Error>,
  |                            ^^^^^^^^^^^^^^^^^ required by this bound in `foo`

For more information about this error, try `rustc --explain E0277`.
Meta

rustc --version --verbose:

rustc 1.91.0 (f8297e351 2025-10-28)
binary: rustc
commit-hash: f8297e351a40c1439a467bbbb6879088047f50b3
commit-date: 2025-10-28
host: x86_64-unknown-linux-gnu
release: 1.91.0
LLVM version: 21.1.2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.