Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Aaron1011 opened this issue Oct 30, 2020 · 2 comments
Open
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-traits Area: Trait system D-confusing Diagnostics: Confusing error or lint that should be reworked. D-crate-version-mismatch Diagnostics: Errors or lints caused be the use of two different crate versions. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Aaron1011
Copy link
Member

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.

@Aaron1011 Aaron1011 added A-traits Area: Trait system T-community D-confusing Diagnostics: Confusing error or lint that should be reworked. D-crate-version-mismatch Diagnostics: Errors or lints caused be the use of two different crate versions. labels Oct 30, 2020
@Aaron1011
Copy link
Member Author

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

@jyn514
Copy link
Member

jyn514 commented Oct 30, 2020

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.

@Aaron1011 Aaron1011 added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed T-community labels Oct 30, 2020
@camelid camelid added the A-diagnostics Area: Messages for errors, warnings, and lints label Oct 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-traits Area: Trait system D-confusing Diagnostics: Confusing error or lint that should be reworked. D-crate-version-mismatch Diagnostics: Errors or lints caused be the use of two different crate versions. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants