Skip to content

Error snake for moving out of an &-pointer is wrong sometimes #15479

@Manishearth

Description

@Manishearth

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

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions