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

Confusing error message: the trait bound String: From<impl Into<String>> is not satisfied #57661

Open
earthengine opened this issue Jan 16, 2019 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@earthengine
Copy link

earthengine commented Jan 16, 2019

Playground

struct Foo(String);
trait Bar {
    fn buz(&self, s: impl AsRef<str>) -> Foo;
}
impl Bar for () {
    fn buz(&self, s: impl Into<String>) -> Foo
    {
        Foo(s.into())
    }
}

The true error is that the trait signature is different than the impl block (and maybe the impl keyword shall not be in the trait as yet?). The message however, is really confusing:

error[E0277]: the trait bound `std::string::String: std::convert::From<impl Into<String>>` is not satisfied
 --> src/lib.rs:6:5
  |
6 |     fn buz(&self, s: impl Into<String>) -> Foo
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::convert::From<impl Into<String>>` is not implemented for `std::string::String`
  |
  = help: consider adding a `where std::string::String: std::convert::From<impl Into<String>>` bound
  = note: required because of the requirements on the impl of `std::convert::Into<std::string::String>` for `impl Into<String>`
  = note: the requirement `impl Into<String>: std::convert::Into<std::string::String>` appears on the impl method but not on the corresponding trait method

error: aborting due to previous error
@hellow554
Copy link
Contributor

The second note makes the statement

= note: the requirement impl Into<String>: std::convert::Into<std::string::String> appears on the impl method but not on the corresponding trait method

I guess one could make that more present, e.g. as the actual error? I don't know if the impl method can actually differ from the trait method at all. Never tried that tbh ^^

@Centril Centril added the A-diagnostics Area: Messages for errors, warnings, and lints label Jan 16, 2019
@estebank estebank added D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 18, 2019
@estebank
Copy link
Contributor

estebank commented Nov 7, 2019

@hellow554 it is possible to make implement a trait with a more restricting impl Trait argument than its trait, but then the trait's obligation for that argument flows down and makes it a requirement on use, which can be quite confusing, and slightly tangential to the original report.

@crlf0710 crlf0710 added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jun 11, 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 C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. 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

5 participants