Skip to content

Strange error message #34359

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

Closed
GuillaumeGomez opened this issue Jun 19, 2016 · 5 comments
Closed

Strange error message #34359

GuillaumeGomez opened this issue Jun 19, 2016 · 5 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@GuillaumeGomez
Copy link
Member

The following code:

fn main() {
    for _ in 0 .. 2 {
        break();
    }
}

Returns the following error (on all rustc versions):

error: the type of this value must be known in this context

Which is really strange. The same error occurs with "continue();".

@apasel422 apasel422 added the A-diagnostics Area: Messages for errors, warnings, and lints label Jun 19, 2016
@durka
Copy link
Contributor

durka commented Jun 19, 2016

This might make it more clear what is going on:

fn main() {
    for _ in 0 .. 2 {
        let x = break;
        x(); //~ERROR
    }
}

@sanxiyn
Copy link
Member

sanxiyn commented Jul 17, 2016

Another way to get this is (return)();. return(); is special cased in the parser so that it does not parse as a call. break(); will get the same treatment if we adopt RFC 1624.

What should be the error message here? I am inclined to close unless there is a good idea.

@eefriedman
Copy link
Contributor

Well, I can see a few weaknesses in the error message:

  1. No extended error explanation (E****).
  2. The error message is describing the error from the compiler's perspective, not the user's perspective, and is overly generic. It would be a lot more clear if the compiler said "not enough information to compute type of callee".
  3. No note describing what we expect the user to do to fix the problem (along the lines of "use a variable to specify the type of an expression like this: let x: i32 = ...;").
  4. (Larger change) It should be possible to detect the source of the unknown type, and give a more specific suggestion; for example, we could give specialized error messages for an uninitialized variable, a return statement, and a generic function whose generic type argument isn't specified.

@GuillaumeGomez
Copy link
Member Author

@eefriedman: In the case the value with the unknown type isn't used, can't rustc just get over it and give it any matching type under the hood?

@sanxiyn
Copy link
Member

sanxiyn commented Jul 18, 2016

I created a patch which changes the error to error: cannot determine the type of this callee.

@steveklabnik steveklabnik removed the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 25, 2017
kennytm added a commit to kennytm/rust that referenced this issue Feb 2, 2018
…uggest removing value from `break` when invalid When attempting to use `break` with a value in a type of loop where it'd be invalid (any non-`loop`), suggest using `break` on its own. Close rust-lang#34359.
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.
Projects
None yet
Development

No branches or pull requests

7 participants