Lokathor / tinyvec

Just, really the littlest Vec you could need. So smol.
https://docs.rs/tinyvec
Apache License 2.0
648 stars 49 forks source link

"unsatisfied trait bounds" for `N` > 33? #169

Closed schubart closed 1 year ago

schubart commented 1 year ago
    let some_ints = ArrayVec::<[usize; 33]>::new();
    let more_ints = ArrayVec::<[usize; 34]>::new();

gives

error[E0599]: the function or associated item `new` exists for struct `ArrayVec<[usize; 34]>`, but its trait bounds were not satisfied
  --> src/main.rs:19:46
   |
19 |     let more_ints = ArrayVec::<[usize; 34]>::new();
   |                                              ^^^ function or associated item cannot be called on `ArrayVec<[usize; 34]>` due to unsatisfied trait bounds
   |
   = note: the following trait bounds were not satisfied:
           `[usize; 34]: Array`

For more information about this error, try `rustc --explain E0599`.

Why does it compile for 33 but not for 34? What's the significance of 33 and 34?

(Rust 1.65.0, tinyvec 1.6.0.)

schubart commented 1 year ago

I now found https://docs.rs/tinyvec/latest/tinyvec/trait.Array.html and understood that not all N are supported, unless you use the rustc_1_55 feature. This fixed the compile error.

I think this deserves a more prominent mention on the documentation front page. I'd imagine that most new users of the crate will be tripped up by this.

Lokathor commented 1 year ago

Ah, we could document this better.

The traits are only implemented for up to 33 unless the min const generics stuff is used, which is what the rustc_1_55 is mostly turning on.

EDIT: as to "why 33?", well because "that's already one more than you'd ever need!" was the idea. I believe several powers of 2 are also available.