-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Unclear clear error message for borrowed contexts #25507
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
This could definitely be improved. Just as an FYI, for loops take for foo in &self.member {
// ...
} This is because We should probably add a detailed error message for this case; you're not the first to be confused. |
I just stumbled into this, +1 for more helpful error message |
I also stumbled upon this myself. Adding iter() also worked. +1 for better error message handling... |
I just ran into this. Here's a slightly different example: #[derive(Debug)]
struct X; // not Copy
struct Y{field: Option<X>}
fn main() {
let v: Vec<Y> = Vec::new();
for y in v.iter() {
println!("{:?}", y.field.unwrap_or(X));
}
} Error:
Ultimately, the diagnostic here should explain why something is being moved, and what was borrowed in the first place. Namely, it's because the call to The lifecycle of my example is worth nothing as well: The loop originally iterated over just |
This particular error pops up on me occasionally, so I have some more insight/complaints about my example. Let These three all give "cannot move out of borrowed content":
But this gives "expected type
When I type |
Triage: no changes, I do see people complain about this diagnostic fairly regularly... |
|
Current output:
|
The error message for the following snippet could be improved, from IRC I was told to add
.iter()
onto line 7 (which worked). I believe a hint in the error message would be helpful.Error seen:
rustc --version --verbose:
The text was updated successfully, but these errors were encountered: