Skip to content

Cannot use tiny_vec! with one non-constant element #200

Description

@TonalidadeHidrica

The following code tries to create a TinyVec with a single element, but it fails at the tiny_vec!. (playground)

use tinyvec::{TinyVec, tiny_vec};

fn main() {
    let a = 1;
    let _: TinyVec<[u8; 4]> = tiny_vec![a];
}
   Compiling playground v0.0.1 (/playground)
error[E0435]: attempt to use a non-constant value in a constant
 --> src/main.rs:5:41
  |
5 |     let _: TinyVec<[u8; 4]> = tiny_vec![a];
  |                                         ^ non-constant value
  |
help: consider using `const` instead of `let`
  |
4 |     const a: /* Type */ = 1;
  |     ~~~~~  ++++++++++++

For more information about this error, try `rustc --explain E0435`.
error: could not compile `playground` (bin "playground") due to 1 previous error

This does not seem to happen for zero or two elements, or when the type is declared on its left (tiny_vec![ [u8; 4] => a ]).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions