-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Try to tailor error messages for common scenarios #24002
Comments
triage: P-high (1.0) |
I've been reading through this thread http://internals.rust-lang.org/t/confused-by-lifetime-error-messages-tell-me-about-it/358/ and trying to extract some specific examples I'd like to target. I will add them as comments here for now. |
Outliving temporary lifetimes, particularly with the newer rules: use std::collections::HashMap;
use std::io::BufRead;
fn main() {
let map = (|| {
let mut map = HashMap::new();
map.insert("imo", "in my opinion");
map
})();
for line in std::io::stdin().lock().lines().map(|l| l.unwrap()) {
println!("{}", line.split(' ')
.map(|seg| if map.contains_key(seg) {
map[seg.as_slice()].to_string()
} else {
seg.to_string()
}).collect::<Vec<String>>().connect(" "));
}
} compiled yields an error (see below). Some thoughts:
We do make a helpful suggestion, but we could make it more concrete perhaps, by indicating what specifically should be moved into a (In general, my impression is that indicating the precise scopes seems to (usually) not be that helpful, particularly in cases like these.)
|
see #23581 |
Suggesting
|
More complete example: use std::thread::spawn;
fn main() {
let mut books = vec![1,2,3];
spawn(|| books.push(4));
} |
Similar to that case is this one http://is.gd/ExwsE4 |
@nikomatsakis I also don't think that this message is very useful:
If you already know roughly how things work, the basic message says what you need to know, and if you don't, it's totally obtuse. |
PR for the escaping closure case: #24242 |
From Carl: https://gist.github.com/carllerche/d058aff63c9f9ae7a8a8 Things that would have helped:
|
Another example of a dropck-related error: http://is.gd/KtjuPX I'm not sure how best to handle these errors. The scenario is complicated. Perhaps suggesting an edit would help, though it may itself (maybe) trigger other errors. |
Another error that frustrated me a lot. Sometimes when I try to send a value to another thread, I will get something like:
The problem is that I don't know where in the original struct this field is because it could be deeply nested in sub structs and span a number of crates. A better error would probably be to error on the deepest type in the current crate and indicate which field is not Send (and possibly the path from there). Hope this makes sense. |
A new rust user hit the following when using mio. Instead of doing Code: extern crate mio;
fn main() {
let _ = mio::Io.new(123);
} Output:
|
On Thu, Apr 09, 2015 at 11:45:57PM -0700, Carl Lerche wrote:
It's interesting because we try to give backtraces in such cases. I'm actually thinking of modifying the compiler to give more such |
From #25885: This example: http://is.gd/oDK41V yields an amazingly bad error message:
the problem here is that the variable |
@carllerche I recently hit that one, and it's easy to miss that one gots to use |
I see the problem has been reported: #22692 |
Closing old vague bug cc @nikomatsakis |
@jonathandturner you might want to look at this thread for inspiration |
This is a vague bug but here is my intention:
The text was updated successfully, but these errors were encountered: