Why miri need add .as_ref()

fn main() {
    let a = [1, 2, 3];

    let mut iter = a.iter();

    assert_eq!(iter.nth(0), Some(1).as_ref());


why miri need add .as_ref()

What do you mean miri needs it? This has nothing to do with miri whatsoever, I have no idea where you are getting that from. It's a simple type mismatch because .iter() on an array/slice/collection in general returns an iterator over references (so that it doesn't consume the collection).


Miri also returns regular compiler errors when run. This isn't unsafety related, its just a type error. You could also change Some(1).as_ref() to Some(&1) to fix the error as well.

1 Like