Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTry to tailor error messages for common scenarios #24002
Comments
This comment has been minimized.
This comment has been minimized.
|
triage: P-high (1.0) |
rust-highfive
added
the
P-medium
label
Apr 3, 2015
rust-highfive
added this to the 1.0 milestone
Apr 3, 2015
nikomatsakis
added
the
A-diagnostics
label
Apr 3, 2015
nikomatsakis
self-assigned this
Apr 3, 2015
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
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.)
|
This comment has been minimized.
This comment has been minimized.
|
see #23581 |
This comment has been minimized.
This comment has been minimized.
|
Suggesting
|
This comment has been minimized.
This comment has been minimized.
|
More complete example: use std::thread::spawn;
fn main() {
let mut books = vec![1,2,3];
spawn(|| books.push(4));
} |
This comment has been minimized.
This comment has been minimized.
|
Similar to that case is this one http://is.gd/ExwsE4 |
This comment has been minimized.
This comment has been minimized.
|
@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. |
This comment has been minimized.
This comment has been minimized.
|
PR for the escaping closure case: #24242 |
nikomatsakis
changed the title
Try to tailor lifetime error messages for common scenarios
Try to tailor error messages for common scenarios
Apr 9, 2015
This comment has been minimized.
This comment has been minimized.
|
From Carl: https://gist.github.com/carllerche/d058aff63c9f9ae7a8a8 Things that would have helped:
|
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
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:
|
This comment has been minimized.
This comment has been minimized.
|
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 |
steveklabnik
removed this from the 1.0 milestone
May 21, 2015
This comment has been minimized.
This comment has been minimized.
|
From #25885: This example: http://is.gd/oDK41V yields an amazingly bad error message:
the problem here is that the variable |
This comment has been minimized.
This comment has been minimized.
|
@carllerche I recently hit that one, and it's easy to miss that one gots to use |
This comment has been minimized.
This comment has been minimized.
|
I see the problem has been reported: #22692 |
This comment has been minimized.
This comment has been minimized.
|
Closing old vague bug cc @nikomatsakis |
brson
closed this
Jul 14, 2016
This comment has been minimized.
This comment has been minimized.
|
@jonathandturner you might want to look at this thread for inspiration |
nikomatsakis commentedApr 3, 2015
This is a vague bug but here is my intention: