Skip to content

Typecheck error with SmallVec crate #12030

Open
@y21

Description

@y21

The following produces a R-A error, but compiles just fine:

use smallvec::SmallVec;

const SIZE: usize = 1;

fn bug(ve: &SmallVec<[Option<()>; SIZE]>) -> Option<Option<&()>> {
    ve.iter().next().map(|x| x.as_ref())
}

fn main() {}

I haven't been able to come up with a minimal example that does not use SmallVec. ve.iter() is inferred as Iter<{unknown}> by RA in that function. Note that this does not error if the array size is written in place: [Option<()>; 1].

This does not happen if I simply replace SmallVec with some type that implements Deref<Target=[Option<()>]> or &[Option<()>; SIZE] itself.

image

rust-analyzer version: rust-analyzer version: 24cf957 2022-04-11 stable

rustc version: rustc 1.62.0-nightly (878c7833f 2022-04-16)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tytype system / type inference / traits / method resolutionC-bugCategory: bugS-actionableSomeone could pick this issue up and work on it right now

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions