-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lints
Description
Minimal-ish working example:
use std::string::String;
struct Foo {
a: String,
b: String,
// Possibly some more fields here
}
struct FooThing(Vec<Foo>);
impl FooThing {
fn filter(&mut self, bar: &Foo) {
let FooThing(ref buf) = self.clone(); // Oops. Shouldn't be a `ref` there
let new_buf: Vec<Foo> = buf.move_iter().filter(|f| f.a == bar.a && f.b == bar.b).collect();
}
}
fn main() {
}
The usage of ref buf
means that buf.move_iter
won't work, since buf
is an &-pointer now. An error is expected.
However, the error shown is:
test.rs:12:53: 12:56 error: the type of this value must be known in this context
test.rs:12 let new_buf: Vec<Foo> = buf.move_iter().filter(|f| f.a == bar.a && f.b == bar.b).collect();
^~~
For some reason, the red caret points at f.a
. Swapping f.a
and bar.a
, it still points at f.a
. Swapping the two equality checks, it now points at f.b
. I don't know what the difference was, but in my real-world case it was the second equality check that had the pointer on it.
The error snake goes to buf.move_iter()
correctly if you replace self.clone()
with *self
.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lints