-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
mismatches types [E0308] doesn't offer enough information to fix the error #34721
Comments
This was the error (see the comment): https://play.rust-lang.org/?gist=841b50e5845c61f2a1ebfd141673c151&version=nightly&backtrace=0 The error message is just completely help less. |
Errors from |
I think this error has been fixed long ago and improved recently with the add of method suggestions. I'm closing it then. |
@GuillaumeGomez You are correct that right now there is a method suggestion, which is nice. But the error right now is the same as the error back then: So I don't think this has been fixed at all. And while it has improved a little bit, it is far from being a good error message. Just check the playground link. |
You didn't add the playground link. Reopening the issue. |
Sorry, the playground example was in the second comment on this issue. I've added it to the issue as well so that it cannot be missed. |
The compiler now suggests adding a semicolon:
When following the suggestion, it (correctly) complains about visibility, after fixing that, it complains about using a moved value, adding a constraint on There're still 3 errors when only one is actually relevant. The lack of
|
…sakis When using value after move, point at span of local When trying to use a value after move, instead of using a note, point at the local declaration that has a type that doesn't implement `Copy` trait. ``` error[E0382]: use of moved value: `x` --> $DIR/issue-34721.rs:27:9 | LL | pub fn baz<T: Foo>(x: T) -> T { | - - move occurs because `x` has type `T`, which does not implement the `Copy` trait | | | consider adding a `Copy` constraint to this type argument LL | if 0 == 1 { LL | bar::bar(x.zero()) | - value moved here LL | } else { LL | x.zero() | - value moved here LL | }; LL | x.zero() | ^ value used here after move ``` Fix rust-lang#34721.
I get an error message like this:
This tells me "what the error is", but gives me too little context (or no context at all) to actually solve it: I have to go to the
intrinsics
module, find thebzhi
function, read its signature, and in my case, I end up baffled because it actually takes aT
(so theexpected type ()
makes no sense).I still haven't figured out what is going on, but it would be good if when rustc detects a type error when calling a function, it would not only tell me where the error is, which type i am passing, and what type is expected, but where exactly the function is and what's its complete signature so that if needed I know where to go to read up the comments. Probably the real error here is that I am calling a function with the same name but from a different module, so it might be even better if rustc would check all functions in all modules in scope for functions with the same name and the type signature I am passing it and make a suggestion like "did you meant to call the
bzhi
function from thebar
module instead?".In particular the next error is a type error on the second function argument, so it would be even better if rustc could collapse these two errors into one.
EDIT: An example of the error is given here:
https://play.rust-lang.org/?gist=841b50e5845c61f2a1ebfd141673c151&version=nightly&backtrace=0
where the following error message is not very helpful:
In particular the
expected (), found type parameter T
is very misleading.The text was updated successfully, but these errors were encountered: