Skip to content

Typecheck error with SmallVec crate #12030

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

Open
y21 opened this issue Apr 19, 2022 · 2 comments
Open

Typecheck error with SmallVec crate #12030

y21 opened this issue Apr 19, 2022 · 2 comments
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now

Comments

@y21
Copy link
Member

y21 commented Apr 19, 2022

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)

@bjorn3
Copy link
Member

bjorn3 commented Apr 19, 2022

(@matklad looks like I lost triage and write permission with the migration to the rust-lang org)

@lnicola lnicola added A-ty type system / type inference / traits / method resolution S-actionable Someone could pick this issue up and work on it right now C-bug Category: bug labels Apr 19, 2022
@HKalbasi
Copy link
Member

We don't evaluate const generics yet (#7434) so SmallVec<[Option<()>; SIZE]> becomes SmallVec<[Option<()>; _]>. And (unless you enable const_generic feature of small vec, with that it should work) there are some random impls for its Array trait (1, 2, 5, 1024, ...) which _ is not necessarily in them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

No branches or pull requests

4 participants