-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Improve "no type for local variable" error when in check_const_with_ty #24414
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
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
Comments
Just received a lone fn main() {
let len: usize = 1;
let arr: [char; len] = ['a'];
} |
Any update for more informative error message? as described in #31082 |
This is an outright bug, the correct behavior is for the use of a variable from a constant to not resolve. |
bors
added a commit
that referenced
this issue
Dec 28, 2016
[10/n] Split constants and functions' arguments into disjoint bodies. _This is part of a series ([prev](#38053) | [next]()) of patches designed to rework rustc into an out-of-order on-demand pipeline model for both better feature support (e.g. [MIR-based](https://github.com/solson/miri) early constant evaluation) and incremental execution of compiler passes (e.g. type-checking), with beneficial consequences to IDE support as well. If any motivation is unclear, please ask for additional PR description clarifications or code comments._ <hr> Finishes the signature-body split started in #37918, namely: * `trait` items are separated just like `impl` items were, for uniformity, closing #37712 * `static`s, `const`s (including associated ones), `enum` discriminants and array lengths get bodies * even the count in "repeat expressions", i.e. `n` in `[x; n]`, which fixes #24414 * arguments' patterns are moved to the bodies, with the types staying in `FnDecl` * `&self` now desugars to `self: &Self` instead of `self: &_` (similarly for other `self` forms) * `astconv`'s and metadata's (for rustdoc) informative uses are explicitly ignored for the purposes of the dep graph. this could be fixed in the future by hashing the exact information being extracted about the arguments as opposed to generating a dependency on *the whole body*
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The control flow for
rustc_typeck::check::check_const_with_ty
can end up spitting out an error of the form:With the compiler as it stands today, this is usually coupled with an error of the form:
but other changes being made may lead to only the "no type for local variable" message being emitted.
We can do better here, e.g. by passing along knowledge that we are looking at a const-expr and then reporting that local variables simply are invalid within const-exprs.
The text was updated successfully, but these errors were encountered: