-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Error for uninitialized vec is unhelpful #2088
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
Comments
OS X 10.5, intel core2duo, branch master at commit 0904f25 |
I agree that the error message is bad, but how would you suggest improving it? Just reduce the amount of noise? |
It took me a couple of minutes of staring and poking at it before I even realized what was going on. Maybe each precondition constraint case could have a descriptive string (like, in this case, "Your local variable is uninitialized") for the compiler to throw out above the details. This might be a good balance, the plain string for the inexperienced newcomer, the detail still there for the people who need it. Alternately, I suppose a let not followed by '=' could be a syntax error, but there might be cases where it isn't. |
Yes, it's a deliberate design feature of Rust that we allow late initialization, so "let" without an '=' is not an error. (It's only an error to use a variable that isn't initialized on every incoming control path, like you saw.) Thanks for the suggestion. I'll try to improve the error message. The info that is there right now is mainly for debugging purposes for implementors -- I never thought it was going to be useful for users, and always meant to improve the error messages, but it's just that no one has asked for that until now :-) |
I suspect that I've been made lazy by writing too much Python lately, but I figured that I should log the things I did notice, since you can only go through the process fresh-eyed the once. If it isn't a priority, I can take a look at improving the messages myself. |
Feel free to try improving the messages. My main priority right now is finishing the implementation of classes, so any help with this would be much appreciated! When it comes to error messages, it's probably best to have someone who isn't the implementor do it anyway, since obviously the messages make sense to me ;-) The main thing you'll probably want to do is distinguish between "this variable is not initialized" and "this precondition is not satisfied", which is one reason why the current message is unclear. The implementation is the same for both situations, but that doesn't mean the error message has to be. Feel free to ask for help. |
How does one trigger the npred branch of the alt? Are there many other constraints? If so, where are they defined? I have it printing something, at this point, but I think that it's not quite the right thing, and want to fiddle with the error propagation some more. Time is tight this weekend, but I should have something to look at early next week. |
I added this as a comment in middle::tstate::auxiliary.rs, before the {{{ cinit and ninit represent init constraints, while cpred and npred In a predicate constraint, the field (and the <def_id> field Hope that's clear enough -- if not, let me know. No rush! |
@evanmcc Ping? If you have code for this, I'd love to review it; if you won't have time, I'll be happy to finish it myself, but I don't want to waste any work you may have already done! |
Hi Tim: I totally failed at having the time for this; I tried to On Thu, Apr 19, 2012 at 12:34 PM, Tim Chevalier
|
@evanmcc No problem -- if you have a patch, even a partial one, feel free to submit a pull req, but otherwise I'll do it. |
What I was hoping to do was two things:
Of course, tried to do #2 first, which I think led to the failure. I Looking forward to the commits for this, and am happy to do any On Thu, Apr 19, 2012 at 12:44 PM, Tim Chevalier
|
punting to 0.4. initness is no longer handled by typestate, so I assume the error message has changed. is this fixed? |
this is fixed. |
Co-authored-by: Adrian Palacios <[email protected]> Co-authored-by: Daniel Schwartz-Narbonne <[email protected]>
trying to compile:
fails with:
The fixed code below (note line 3) compiles correctly:
The text was updated successfully, but these errors were encountered: