Skip to content

Note when trait bound may be satisfied for a different version of a crate #78552

Open

Description

@Aaron1011

On the playground, the following code:

use bytes::Bytes;
use http::Response;
use hyper::Body;

pub fn build(data: Bytes) -> Response<Body> {
    Response::new(data.into())
}

fn main() {
}

currently produces the following error:

error[E0277]: the trait bound `hyper::Body: std::convert::From<bytes::Bytes>` is not satisfied
 --> src/main.rs:6:19
  |
6 |     Response::new(data.into())
  |                   ^^^^^^^^^^^ the trait `std::convert::From<bytes::Bytes>` is not implemented for `hyper::Body`
  |
  = help: the following implementations were found:
            <hyper::Body as std::convert::From<&'static [u8]>>
            <hyper::Body as std::convert::From<&'static str>>
            <hyper::Body as std::convert::From<hyper::body::Bytes>>
            <hyper::Body as std::convert::From<std::borrow::Cow<'static, [u8]>>>
          and 4 others
  = note: required because of the requirements on the impl of `std::convert::Into<hyper::Body>` for `bytes::Bytes`

Note that hyper::body::Bytes is an alias for bytes::Bytes. We should detect when an unment trait bound's substs match the fully-qualified names of our desired trait bound, and note that multiple versions of the same crate may be in use.

Activity

  1. added
    D-confusingDiagnostics: Confusing error or lint that should be reworked.
    D-crate-version-mismatchDiagnostics: Errors or lints caused be the use of two different crate versions.
    on Oct 30, 2020
  2. Aaron1011 commented on Oct 30, 2020

    @Aaron1011
    ContributorAuthor

    This is similar to #73560, but it occurs in a different part of the compiler.

  3. jyn514 commented on Oct 30, 2020

    @jyn514
    Member

    A similar error:

    error[E0277]: a value of type `HashMap<std::string::String, cargo_metadata::Package>` cannot be built from an iterator over elements of type `(std::string::String, cargo_metadata::Package)`
      --> src/utils/cargo_metadata.rs:46:18
       |
    46 |                 .collect(),
       |                  ^^^^^^^ value of type `HashMap<std::string::String, cargo_metadata::Package>` cannot be built from `std::iter::Iterator<Item=(std::string::String, cargo_metadata::Package)>`
       |
       = help: the trait `FromIterator<(std::string::String, cargo_metadata::Package)>` is not implemented for `HashMap<std::string::String, cargo_metadata::Package>`
    

    The first cargo_metadata is a module, the second is a crate.

  4. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    and removed on Oct 30, 2020
  5. added
    S-needs-reproStatus: This issue has no reproduction and needs a reproduction to make progress.
    on Sep 29, 2025
  6. isosphere commented on Dec 30, 2025

    @isosphere

    Reproduction

    This workspace has (deliberately) mismatched dependency versions and an impl for a struct that dependency provides; the "runtime" crate included will therefore not compile.

    The error does not help the user determine that the underlying issue is the mismatched versions.

    https://github.com/isosphere/rust-issue-78552-repro

    @Aaron1011, I think we're talking about the same thing here, but please correct me if I'm wrong.

    Here's the error on 1.92.0:

    error[E0277]: `?` couldn't convert the error to `Status`
     --> repro-runtime/src/main.rs:5:78
      |
    4 | fn main() -> Result<(), Status> {
      |              ------------------ expected `Status` because of this
    5 |     Err(ApplicationError::ImpossibleCondition("you tried to run it!".into()))?
      |     -------------------------------------------------------------------------^ the trait `From<ApplicationError>` is not implemented for `Status`
      |     |
      |     this can't be annotated with `?` because it has type `Result<_, ApplicationError>`
      |
      = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
      = help: the following other types implement trait `From<T>`:
                `Status` implements `From<h2::error::Error>`
                `Status` implements `From<std::io::Error>`
    
    For more information about this error, try `rustc --explain E0277`.
    error: could not compile `repro-runtime` (bin "repro-runtime") due to 1 previous error
    

    #146874 is merged into 1.92.0 and should offer a hint, but it is not triggered in this case.

  7. added 2 commits that reference this issue on Jan 3, 2026
  8. added a commit that references this issue on Jan 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemD-confusingDiagnostics: Confusing error or lint that should be reworked.D-crate-version-mismatchDiagnostics: Errors or lints caused be the use of two different crate versions.S-needs-reproStatus: This issue has no reproduction and needs a reproduction to make progress.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions