Vendor things
This commit is contained in:
parent
5deceec006
commit
977e3c17e5
19434 changed files with 10682014 additions and 0 deletions
33
third-party/vendor/num_enum-0.5.11/tests/default.rs
vendored
Normal file
33
third-party/vendor/num_enum-0.5.11/tests/default.rs
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
// Guard against https://github.com/illicitonion/num_enum/issues/27
|
||||
mod alloc {}
|
||||
mod core {}
|
||||
mod num_enum {}
|
||||
mod std {}
|
||||
|
||||
#[test]
|
||||
fn default() {
|
||||
#[derive(Debug, Eq, PartialEq, ::num_enum::Default)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
#[allow(unused)]
|
||||
Zero = 0,
|
||||
#[num_enum(default)]
|
||||
NonZero = 1,
|
||||
}
|
||||
|
||||
assert_eq!(Enum::NonZero, <Enum as ::core::default::Default>::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_standard_default_attribute() {
|
||||
#[derive(Debug, Eq, PartialEq, ::num_enum::Default)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
#[allow(unused)]
|
||||
Zero = 0,
|
||||
#[default]
|
||||
NonZero = 1,
|
||||
}
|
||||
|
||||
assert_eq!(Enum::NonZero, <Enum as ::core::default::Default>::default());
|
||||
}
|
||||
144
third-party/vendor/num_enum-0.5.11/tests/from_primitive.rs
vendored
Normal file
144
third-party/vendor/num_enum-0.5.11/tests/from_primitive.rs
vendored
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
use ::std::convert::TryFrom;
|
||||
|
||||
use ::num_enum::{FromPrimitive, TryFromPrimitive};
|
||||
|
||||
// Guard against https://github.com/illicitonion/num_enum/issues/27
|
||||
mod alloc {}
|
||||
mod core {}
|
||||
mod num_enum {}
|
||||
mod std {}
|
||||
|
||||
#[test]
|
||||
fn has_from_primitive_number_u64() {
|
||||
#[derive(Debug, Eq, PartialEq, FromPrimitive)]
|
||||
#[repr(u64)]
|
||||
enum Enum {
|
||||
Zero = 0,
|
||||
#[num_enum(default)]
|
||||
NonZero = 1,
|
||||
}
|
||||
|
||||
let zero = Enum::from_primitive(0_u64);
|
||||
assert_eq!(zero, Enum::Zero);
|
||||
|
||||
let one = Enum::from_primitive(1_u64);
|
||||
assert_eq!(one, Enum::NonZero);
|
||||
|
||||
let two = Enum::from_primitive(2_u64);
|
||||
assert_eq!(two, Enum::NonZero);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn has_from_primitive_number() {
|
||||
#[derive(Debug, Eq, PartialEq, FromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
Zero = 0,
|
||||
#[num_enum(default)]
|
||||
NonZero = 1,
|
||||
}
|
||||
|
||||
let zero = Enum::from_primitive(0_u8);
|
||||
assert_eq!(zero, Enum::Zero);
|
||||
|
||||
let one = Enum::from_primitive(1_u8);
|
||||
assert_eq!(one, Enum::NonZero);
|
||||
|
||||
let two = Enum::from_primitive(2_u8);
|
||||
assert_eq!(two, Enum::NonZero);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn has_from_primitive_number_standard_default_attribute() {
|
||||
#[derive(Debug, Eq, PartialEq, FromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
Zero = 0,
|
||||
#[default]
|
||||
NonZero = 1,
|
||||
}
|
||||
|
||||
let zero = Enum::from_primitive(0_u8);
|
||||
assert_eq!(zero, Enum::Zero);
|
||||
|
||||
let one = Enum::from_primitive(1_u8);
|
||||
assert_eq!(one, Enum::NonZero);
|
||||
|
||||
let two = Enum::from_primitive(2_u8);
|
||||
assert_eq!(two, Enum::NonZero);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_primitive_number() {
|
||||
#[derive(Debug, Eq, PartialEq, FromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
#[num_enum(default)]
|
||||
Whatever = 0,
|
||||
}
|
||||
|
||||
// #[derive(FromPrimitive)] generates implementations for the following traits:
|
||||
//
|
||||
// - `FromPrimitive<T>`
|
||||
// - `From<T>`
|
||||
// - `TryFromPrimitive<T>`
|
||||
// - `TryFrom<T>`
|
||||
let from_primitive = Enum::from_primitive(0_u8);
|
||||
assert_eq!(from_primitive, Enum::Whatever);
|
||||
|
||||
let from = Enum::from(0_u8);
|
||||
assert_eq!(from, Enum::Whatever);
|
||||
|
||||
let try_from_primitive = Enum::try_from_primitive(0_u8);
|
||||
assert_eq!(try_from_primitive, Ok(Enum::Whatever));
|
||||
|
||||
let try_from = Enum::try_from(0_u8);
|
||||
assert_eq!(try_from, Ok(Enum::Whatever));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_primitive_number_catch_all() {
|
||||
#[derive(Debug, Eq, PartialEq, FromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
Zero = 0,
|
||||
#[num_enum(catch_all)]
|
||||
NonZero(u8),
|
||||
}
|
||||
|
||||
let zero = Enum::from_primitive(0_u8);
|
||||
assert_eq!(zero, Enum::Zero);
|
||||
|
||||
let one = Enum::from_primitive(1_u8);
|
||||
assert_eq!(one, Enum::NonZero(1_u8));
|
||||
|
||||
let two = Enum::from_primitive(2_u8);
|
||||
assert_eq!(two, Enum::NonZero(2_u8));
|
||||
}
|
||||
|
||||
#[cfg(feature = "complex-expressions")]
|
||||
#[test]
|
||||
fn from_primitive_number_with_inclusive_range() {
|
||||
#[derive(Debug, Eq, PartialEq, FromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
Zero = 0,
|
||||
#[num_enum(alternatives = [2..=255])]
|
||||
NonZero,
|
||||
}
|
||||
|
||||
let zero = Enum::from_primitive(0_u8);
|
||||
assert_eq!(zero, Enum::Zero);
|
||||
|
||||
let one = Enum::from_primitive(1_u8);
|
||||
assert_eq!(one, Enum::NonZero);
|
||||
|
||||
let two = Enum::from_primitive(2_u8);
|
||||
assert_eq!(two, Enum::NonZero);
|
||||
|
||||
let three = Enum::from_primitive(3_u8);
|
||||
assert_eq!(three, Enum::NonZero);
|
||||
|
||||
let twofivefive = Enum::from_primitive(255_u8);
|
||||
assert_eq!(twofivefive, Enum::NonZero);
|
||||
}
|
||||
47
third-party/vendor/num_enum-0.5.11/tests/into_primitive.rs
vendored
Normal file
47
third-party/vendor/num_enum-0.5.11/tests/into_primitive.rs
vendored
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
use ::num_enum::IntoPrimitive;
|
||||
|
||||
// Guard against https://github.com/illicitonion/num_enum/issues/27
|
||||
mod alloc {}
|
||||
mod core {}
|
||||
mod num_enum {}
|
||||
mod std {}
|
||||
|
||||
#[derive(IntoPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
Zero,
|
||||
One,
|
||||
Two,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simple() {
|
||||
let zero: u8 = Enum::Zero.into();
|
||||
assert_eq!(zero, 0u8);
|
||||
|
||||
let one: u8 = Enum::One.into();
|
||||
assert_eq!(one, 1u8);
|
||||
|
||||
let two: u8 = Enum::Two.into();
|
||||
assert_eq!(two, 2u8);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn catch_all() {
|
||||
#[derive(Debug, Eq, PartialEq, IntoPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
Zero = 0,
|
||||
#[num_enum(catch_all)]
|
||||
NonZero(u8),
|
||||
}
|
||||
|
||||
let zero: u8 = Enum::Zero.into();
|
||||
assert_eq!(zero, 0u8);
|
||||
|
||||
let one: u8 = Enum::NonZero(1u8).into();
|
||||
assert_eq!(one, 1u8);
|
||||
|
||||
let two: u8 = Enum::NonZero(2u8).into();
|
||||
assert_eq!(two, 2u8);
|
||||
}
|
||||
33
third-party/vendor/num_enum-0.5.11/tests/renamed_num_enum.rs
vendored
Normal file
33
third-party/vendor/num_enum-0.5.11/tests/renamed_num_enum.rs
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#[test]
|
||||
fn no_std() {
|
||||
assert!(::std::process::Command::new("cargo")
|
||||
.args([
|
||||
"run",
|
||||
"--manifest-path",
|
||||
concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/../renamed_num_enum/Cargo.toml",
|
||||
),
|
||||
])
|
||||
.status()
|
||||
.unwrap()
|
||||
.success())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn std() {
|
||||
assert!(::std::process::Command::new("cargo")
|
||||
.args([
|
||||
"run",
|
||||
"--manifest-path",
|
||||
concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/../renamed_num_enum/Cargo.toml",
|
||||
),
|
||||
"--features",
|
||||
"std",
|
||||
])
|
||||
.status()
|
||||
.unwrap()
|
||||
.success())
|
||||
}
|
||||
123
third-party/vendor/num_enum-0.5.11/tests/try_build.rs
vendored
Normal file
123
third-party/vendor/num_enum-0.5.11/tests/try_build.rs
vendored
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
use std::error::Error;
|
||||
use std::path::{Path, PathBuf};
|
||||
use walkdir::WalkDir;
|
||||
|
||||
#[test]
|
||||
fn trybuild() {
|
||||
let directory = PathBuf::from("tests/try_build");
|
||||
|
||||
let mut _renamer = None;
|
||||
|
||||
let compile_fail_dir = directory.join("compile_fail");
|
||||
|
||||
// Sometimes error messages change on beta/nightly - allow alternate errors on those.
|
||||
_renamer = Some(Renamer::rename(compile_fail_dir.clone()).unwrap());
|
||||
|
||||
let fail = trybuild::TestCases::new();
|
||||
fail.compile_fail(compile_fail_dir.join("*.rs"));
|
||||
add_feature_dirs(&compile_fail_dir, &fail, ExpectedResult::Fail);
|
||||
|
||||
let pass = trybuild::TestCases::new();
|
||||
let pass_dir = directory.join("pass");
|
||||
pass.pass(pass_dir.join("*.rs"));
|
||||
add_feature_dirs(&pass_dir, &pass, ExpectedResult::Pass);
|
||||
}
|
||||
|
||||
enum ExpectedResult {
|
||||
Pass,
|
||||
Fail,
|
||||
}
|
||||
|
||||
fn add_feature_dirs(
|
||||
parent_dir: &Path,
|
||||
test_cases: &trybuild::TestCases,
|
||||
expected_result: ExpectedResult,
|
||||
) {
|
||||
let features_dir = parent_dir.join("features");
|
||||
let feature_specific_dir = if cfg!(feature = "complex-expressions") {
|
||||
features_dir.join("complex-expressions")
|
||||
} else {
|
||||
features_dir.join("!complex-expressions")
|
||||
};
|
||||
let tests = feature_specific_dir.join("*.rs");
|
||||
match expected_result {
|
||||
ExpectedResult::Pass => test_cases.pass(tests),
|
||||
ExpectedResult::Fail => test_cases.compile_fail(tests),
|
||||
}
|
||||
}
|
||||
|
||||
struct Renamer(Vec<PathBuf>);
|
||||
|
||||
impl Renamer {
|
||||
const STDERR_EXTENSION: &'static str = "stderr";
|
||||
|
||||
#[rustversion::all(beta)]
|
||||
const VERSION_SPECIFIC_EXTENSION: &'static str = "stderr_beta";
|
||||
|
||||
#[rustversion::all(nightly)]
|
||||
const VERSION_SPECIFIC_EXTENSION: &'static str = "stderr_nightly";
|
||||
|
||||
#[rustversion::all(not(beta), not(nightly))]
|
||||
const VERSION_SPECIFIC_EXTENSION: &'static str = "stderr_doesnotexist";
|
||||
|
||||
const NON_VERSION_SPECIFIC_BACKUP_EXTENSION: &'static str =
|
||||
"stderr_non_version_specific_backup";
|
||||
|
||||
fn rename(dir: PathBuf) -> anyhow::Result<Self> {
|
||||
let nightly_paths = WalkDir::new(dir)
|
||||
.max_depth(1)
|
||||
.into_iter()
|
||||
.filter_map(|dir_entry| {
|
||||
let dir_entry = match dir_entry {
|
||||
Ok(dir_entry) => dir_entry,
|
||||
Err(err) => return Some(Err(err)),
|
||||
};
|
||||
let path = dir_entry.path();
|
||||
if let Some(file_name) = path.file_name() {
|
||||
if Path::new(file_name).extension()
|
||||
== Some(Renamer::VERSION_SPECIFIC_EXTENSION.as_ref())
|
||||
{
|
||||
return Some(Ok(path.to_path_buf()));
|
||||
}
|
||||
}
|
||||
None
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
// Create early so that if we end up returning an error this gets dropped and undoes any
|
||||
// already-done renames.
|
||||
let renamer = Renamer(nightly_paths);
|
||||
|
||||
for nightly_path in &renamer.0 {
|
||||
std::fs::rename(
|
||||
nightly_path.with_extension(Renamer::STDERR_EXTENSION),
|
||||
nightly_path.with_extension(Renamer::NON_VERSION_SPECIFIC_BACKUP_EXTENSION),
|
||||
)?;
|
||||
std::fs::rename(
|
||||
nightly_path.with_extension(Renamer::VERSION_SPECIFIC_EXTENSION),
|
||||
nightly_path.with_extension(Renamer::STDERR_EXTENSION),
|
||||
)?;
|
||||
}
|
||||
Ok(renamer)
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Renamer {
|
||||
fn drop(&mut self) {
|
||||
for path in &self.0 {
|
||||
ignore_error(std::fs::rename(
|
||||
path.with_extension(Renamer::STDERR_EXTENSION),
|
||||
path.with_extension(Renamer::VERSION_SPECIFIC_EXTENSION),
|
||||
));
|
||||
ignore_error(std::fs::rename(
|
||||
path.with_extension(Renamer::NON_VERSION_SPECIFIC_BACKUP_EXTENSION),
|
||||
path.with_extension(Renamer::STDERR_EXTENSION),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn ignore_error<T, E: Error>(result: Result<T, E>) {
|
||||
if let Err(err) = result {
|
||||
eprintln!("Ignoring error: {}", err);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
#[derive(num_enum::TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Numbers {
|
||||
Zero = 0,
|
||||
#[num_enum(alternatives = [3,1,4])]
|
||||
One = 1,
|
||||
Two = 2,
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
error: '1' in the alternative values is already attributed as the discriminant of this variant
|
||||
--> tests/try_build/compile_fail/alternative_clashes_with_its_discriminant.rs:5:34
|
||||
|
|
||||
5 | #[num_enum(alternatives = [3,1,4])]
|
||||
| ^
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
#[derive(num_enum::TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Numbers {
|
||||
Zero = 0,
|
||||
#[num_enum(alternatives = [2])]
|
||||
One = 1,
|
||||
Two = 2,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
error: The discriminant '2' collides with a value attributed to a previous variant
|
||||
--> tests/try_build/compile_fail/alternative_clashes_with_variant.rs:7:5
|
||||
|
|
||||
7 | Two = 2,
|
||||
| ^^^
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
#[derive(num_enum::TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Numbers {
|
||||
Zero = 0,
|
||||
#[num_enum(alternatives = [5,7,0,3])]
|
||||
One = 1,
|
||||
Two = 2,
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
error: '0' in the alternative values is already attributed to a previous variant
|
||||
--> tests/try_build/compile_fail/alternative_clashes_with_variant_out_of_order.rs:5:36
|
||||
|
|
||||
5 | #[num_enum(alternatives = [5,7,0,3])]
|
||||
| ^
|
||||
13
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/alternative_exprs.rs
vendored
Normal file
13
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/alternative_exprs.rs
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
const THREE: u8 = 3;
|
||||
|
||||
#[derive(num_enum::TryFromPrimitive)]
|
||||
#[repr(i8)]
|
||||
enum Numbers {
|
||||
Zero = 0,
|
||||
#[num_enum(alternatives = [-1, 2, THREE])]
|
||||
One = 1,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
}
|
||||
5
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/alternative_exprs.stderr
vendored
Normal file
5
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/alternative_exprs.stderr
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
error: Only literals are allowed as num_enum alternate values
|
||||
--> tests/try_build/compile_fail/alternative_exprs.rs:7:39
|
||||
|
|
||||
7 | #[num_enum(alternatives = [-1, 2, THREE])]
|
||||
| ^^^^^
|
||||
9
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/catch_all_multiple_fields.rs
vendored
Normal file
9
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/catch_all_multiple_fields.rs
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#[derive(Debug, Eq, PartialEq, num_enum::FromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
Zero = 0,
|
||||
#[num_enum(catch_all)]
|
||||
NonZero(u8, u8),
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
error: Variant with `catch_all` must be a tuple with exactly 1 field matching the repr type
|
||||
--> tests/try_build/compile_fail/catch_all_multiple_fields.rs:5:16
|
||||
|
|
||||
5 | #[num_enum(catch_all)]
|
||||
| ^^^^^^^^^
|
||||
9
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/catch_all_non_tuple.rs
vendored
Normal file
9
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/catch_all_non_tuple.rs
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#[derive(Debug, Eq, PartialEq, num_enum::FromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
Zero = 0,
|
||||
#[num_enum(catch_all)]
|
||||
NonZero = 1,
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
5
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/catch_all_non_tuple.stderr
vendored
Normal file
5
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/catch_all_non_tuple.stderr
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
error: Variant with `catch_all` must be a tuple with exactly 1 field matching the repr type
|
||||
--> tests/try_build/compile_fail/catch_all_non_tuple.rs:5:16
|
||||
|
|
||||
5 | #[num_enum(catch_all)]
|
||||
| ^^^^^^^^^
|
||||
9
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/catch_all_type_mismatch.rs
vendored
Normal file
9
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/catch_all_type_mismatch.rs
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#[derive(Debug, Eq, PartialEq, num_enum::FromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
Zero = 0,
|
||||
#[num_enum(catch_all)]
|
||||
NonZero(i32),
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
error: Variant with `catch_all` must be a tuple with exactly 1 field matching the repr type
|
||||
--> tests/try_build/compile_fail/catch_all_type_mismatch.rs:5:16
|
||||
|
|
||||
5 | #[num_enum(catch_all)]
|
||||
| ^^^^^^^^^
|
||||
9
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/conflicting_default.rs
vendored
Normal file
9
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/conflicting_default.rs
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#[derive(Default, num_enum::Default)]
|
||||
#[repr(u8)]
|
||||
enum Number {
|
||||
#[default]
|
||||
Zero,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
9
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/conflicting_default.stderr
vendored
Normal file
9
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/conflicting_default.stderr
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
error[E0119]: conflicting implementations of trait `Default` for type `Number`
|
||||
--> tests/try_build/compile_fail/conflicting_default.rs:1:19
|
||||
|
|
||||
1 | #[derive(Default, num_enum::Default)]
|
||||
| ------- ^^^^^^^^^^^^^^^^^ conflicting implementation for `Number`
|
||||
| |
|
||||
| first implementation here
|
||||
|
|
||||
= note: this error originates in the derive macro `num_enum::Default` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
11
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/conflicting_derive.rs
vendored
Normal file
11
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/conflicting_derive.rs
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#[derive(num_enum::FromPrimitive, num_enum::TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Numbers {
|
||||
Zero,
|
||||
#[num_enum(default)]
|
||||
One,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
}
|
||||
20
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/conflicting_derive.stderr
vendored
Normal file
20
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/conflicting_derive.stderr
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
error[E0119]: conflicting implementations of trait `TryFromPrimitive` for type `Numbers`
|
||||
--> tests/try_build/compile_fail/conflicting_derive.rs:1:35
|
||||
|
|
||||
1 | #[derive(num_enum::FromPrimitive, num_enum::TryFromPrimitive)]
|
||||
| ----------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Numbers`
|
||||
| |
|
||||
| first implementation here
|
||||
|
|
||||
= note: this error originates in the derive macro `num_enum::TryFromPrimitive` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0119]: conflicting implementations of trait `TryFrom<u8>` for type `Numbers`
|
||||
--> tests/try_build/compile_fail/conflicting_derive.rs:1:35
|
||||
|
|
||||
1 | #[derive(num_enum::FromPrimitive, num_enum::TryFromPrimitive)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: conflicting implementation in crate `core`:
|
||||
- impl<T, U> TryFrom<U> for T
|
||||
where U: Into<T>;
|
||||
= note: this error originates in the derive macro `num_enum::TryFromPrimitive` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
10
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/default_and_catch_all.rs
vendored
Normal file
10
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/default_and_catch_all.rs
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#[derive(Debug, Eq, PartialEq, num_enum::FromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
#[default]
|
||||
Zero = 0,
|
||||
#[num_enum(catch_all)]
|
||||
NonZero(u8),
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
5
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/default_and_catch_all.stderr
vendored
Normal file
5
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/default_and_catch_all.stderr
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
error: Attribute `catch_all` is mutually exclusive with `default`
|
||||
--> tests/try_build/compile_fail/default_and_catch_all.rs:6:16
|
||||
|
|
||||
6 | #[num_enum(catch_all)]
|
||||
| ^^^^^^^^^
|
||||
10
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/default_and_catch_all_alt.rs
vendored
Normal file
10
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/default_and_catch_all_alt.rs
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#[derive(Debug, Eq, PartialEq, num_enum::FromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
#[num_enum(default)]
|
||||
Zero = 0,
|
||||
#[num_enum(catch_all)]
|
||||
NonZero(u8),
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
error: Attribute `catch_all` is mutually exclusive with `default`
|
||||
--> tests/try_build/compile_fail/default_and_catch_all_alt.rs:6:16
|
||||
|
|
||||
6 | #[num_enum(catch_all)]
|
||||
| ^^^^^^^^^
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
#[derive(Debug, Eq, PartialEq, num_enum::FromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
Zero = 0,
|
||||
#[num_enum(catch_all)]
|
||||
#[default]
|
||||
NonZero(u8),
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
error: Attribute `default` is mutually exclusive with `catch_all`
|
||||
--> tests/try_build/compile_fail/default_and_catch_all_same_variant.rs:6:5
|
||||
|
|
||||
6 | #[default]
|
||||
| ^^^^^^^^^^
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
#[derive(Debug, Eq, PartialEq, num_enum::FromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
Zero = 0,
|
||||
#[num_enum(catch_all)]
|
||||
#[num_enum(default)]
|
||||
NonZero(u8),
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
error: Attribute `default` is mutually exclusive with `catch_all`
|
||||
--> tests/try_build/compile_fail/default_and_catch_all_same_variant_alt.rs:6:16
|
||||
|
|
||||
6 | #[num_enum(default)]
|
||||
| ^^^^^^^
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#[derive(num_enum::FromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Numbers {
|
||||
Zero = 0,
|
||||
#[num_enum(alternatives = [2..=255])]
|
||||
NonZero = 1,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
error: Ranges are only supported as num_enum alternate values if the `complex-expressions` feature of the crate `num_enum` is enabled
|
||||
--> tests/try_build/compile_fail/features/!complex-expressions/alternate_exprs_with_range.rs:5:5
|
||||
|
|
||||
5 | #[num_enum(alternatives = [2..=255])]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#[derive(num_enum::TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Numbers {
|
||||
Zero = 0,
|
||||
#[num_enum(alternatives = [..255])]
|
||||
NonZero = 1,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
error: When ranges are used for alternate values, both bounds most be explicitly specified numeric literals
|
||||
--> tests/try_build/compile_fail/features/complex-expressions/alternate_exprs_range_missing_lower_bound.rs:5:32
|
||||
|
|
||||
5 | #[num_enum(alternatives = [..255])]
|
||||
| ^^^^^
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#[derive(num_enum::TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Numbers {
|
||||
Zero = 0,
|
||||
#[num_enum(alternatives = [2..])]
|
||||
NonZero = 1,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
error: When ranges are used for alternate values, both bounds most be explicitly specified numeric literals
|
||||
--> tests/try_build/compile_fail/features/complex-expressions/alternate_exprs_range_missing_upper_bound.rs:5:32
|
||||
|
|
||||
5 | #[num_enum(alternatives = [2..])]
|
||||
| ^^^
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
const TWO: u8 = 2;
|
||||
|
||||
#[derive(num_enum::TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Numbers {
|
||||
Zero = 0,
|
||||
#[num_enum(alternatives = [TWO..=255])]
|
||||
NonZero = 1,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
error: When ranges are used for alternate values, both bounds most be explicitly specified numeric literals
|
||||
--> tests/try_build/compile_fail/features/complex-expressions/alternate_exprs_range_nonlit_lower_bound.rs:7:32
|
||||
|
|
||||
7 | #[num_enum(alternatives = [TWO..=255])]
|
||||
| ^^^^^^^^^
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
const TWOFIVEFIVE: u8 = 255;
|
||||
|
||||
#[derive(num_enum::TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Numbers {
|
||||
Zero = 0,
|
||||
#[num_enum(alternatives = [2..=TWOFIVEFIVE])]
|
||||
NonZero = 1,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
error: When ranges are used for alternate values, both bounds most be explicitly specified numeric literals
|
||||
--> tests/try_build/compile_fail/features/complex-expressions/alternate_exprs_range_nonlit_upper_bound.rs:7:32
|
||||
|
|
||||
7 | #[num_enum(alternatives = [2..=TWOFIVEFIVE])]
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#[derive(num_enum::TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Numbers {
|
||||
Zero = 0,
|
||||
#[num_enum(alternatives = [255..=2])]
|
||||
NonZero = 1,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
error: When using ranges for alternate values, upper bound must not be less than lower bound
|
||||
--> tests/try_build/compile_fail/features/complex-expressions/alternate_exprs_range_swapped_bounds.rs:5:32
|
||||
|
|
||||
5 | #[num_enum(alternatives = [255..=2])]
|
||||
| ^^^^^^^
|
||||
12
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/garbage_attribute.rs
vendored
Normal file
12
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/garbage_attribute.rs
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#[derive(num_enum::TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Numbers {
|
||||
Zero = 0,
|
||||
#[num_enum(garbage)]
|
||||
One = 1,
|
||||
Two = 2,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
}
|
||||
5
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/garbage_attribute.stderr
vendored
Normal file
5
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/garbage_attribute.stderr
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
error: Invalid attribute: expected one of: `default`, `catch_all`, `alternatives`
|
||||
--> $DIR/garbage_attribute.rs:5:5
|
||||
|
|
||||
5 | #[num_enum(garbage)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
11
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/missing_default.rs
vendored
Normal file
11
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/missing_default.rs
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#[derive(num_enum::FromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Numbers {
|
||||
Zero,
|
||||
One,
|
||||
Two,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
}
|
||||
7
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/missing_default.stderr
vendored
Normal file
7
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/missing_default.stderr
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
error: #[derive(num_enum::FromPrimitive)] requires enum to be exhaustive, or a variant marked with `#[default]`, `#[num_enum(default)]`, or `#[num_enum(catch_all)`
|
||||
--> $DIR/missing_default.rs:1:10
|
||||
|
|
||||
1 | #[derive(num_enum::FromPrimitive)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this error originates in the derive macro `num_enum::FromPrimitive` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
7
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/missing_repr.rs
vendored
Normal file
7
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/missing_repr.rs
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#[derive(num_enum::IntoPrimitive)]
|
||||
enum Numbers {
|
||||
Zero,
|
||||
One,
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
7
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/missing_repr.stderr
vendored
Normal file
7
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/missing_repr.stderr
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
error: Missing `#[repr({Integer})]` attribute
|
||||
--> $DIR/missing_repr.rs:1:10
|
||||
|
|
||||
1 | #[derive(num_enum::IntoPrimitive)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this error originates in the derive macro `num_enum::IntoPrimitive` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
10
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/multiple_catch_all.rs
vendored
Normal file
10
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/multiple_catch_all.rs
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#[derive(Debug, Eq, PartialEq, num_enum::FromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
#[num_enum(catch_all)]
|
||||
Zero(u8),
|
||||
#[num_enum(catch_all)]
|
||||
NonZero(u8),
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
5
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/multiple_catch_all.stderr
vendored
Normal file
5
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/multiple_catch_all.stderr
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
error: Multiple variants marked with `#[num_enum(catch_all)]`
|
||||
--> tests/try_build/compile_fail/multiple_catch_all.rs:6:16
|
||||
|
|
||||
6 | #[num_enum(catch_all)]
|
||||
| ^^^^^^^^^
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
#[derive(Debug, Eq, PartialEq, num_enum::FromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
Zero = 0,
|
||||
#[num_enum(catch_all)]
|
||||
#[num_enum(catch_all)]
|
||||
NonZero(u8),
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
error: Multiple variants marked with `#[num_enum(catch_all)]`
|
||||
--> tests/try_build/compile_fail/multiple_catch_all_same_variant.rs:6:16
|
||||
|
|
||||
6 | #[num_enum(catch_all)]
|
||||
| ^^^^^^^^^
|
||||
13
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/multiple_defaults.rs
vendored
Normal file
13
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/multiple_defaults.rs
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#[derive(num_enum::FromPrimitive, num_enum::TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Numbers {
|
||||
Zero,
|
||||
#[default]
|
||||
One,
|
||||
#[default]
|
||||
Two,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
}
|
||||
5
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/multiple_defaults.stderr
vendored
Normal file
5
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/multiple_defaults.stderr
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
error: Multiple variants marked `#[default]` or `#[num_enum(default)]` found
|
||||
--> $DIR/multiple_defaults.rs:7:5
|
||||
|
|
||||
7 | #[default]
|
||||
| ^^^^^^^^^^
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
#[derive(num_enum::FromPrimitive, num_enum::TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Numbers {
|
||||
Zero,
|
||||
#[default]
|
||||
One,
|
||||
#[num_enum(default)]
|
||||
Two,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
error: Multiple variants marked `#[default]` or `#[num_enum(default)]` found
|
||||
--> $DIR/multiple_defaults_different_kinds.rs:7:16
|
||||
|
|
||||
7 | #[num_enum(default)]
|
||||
| ^^^^^^^
|
||||
13
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/multiple_num_enum_defaults.rs
vendored
Normal file
13
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/multiple_num_enum_defaults.rs
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#[derive(num_enum::FromPrimitive, num_enum::TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Numbers {
|
||||
Zero,
|
||||
#[num_enum(default)]
|
||||
One,
|
||||
#[num_enum(default)]
|
||||
Two,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
error: Multiple variants marked `#[default]` or `#[num_enum(default)]` found
|
||||
--> $DIR/multiple_num_enum_defaults.rs:7:16
|
||||
|
|
||||
7 | #[num_enum(default)]
|
||||
| ^^^^^^^
|
||||
8
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/repr_c.rs
vendored
Normal file
8
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/repr_c.rs
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#[derive(num_enum::IntoPrimitive)]
|
||||
#[repr(C)]
|
||||
enum Numbers {
|
||||
Zero,
|
||||
One,
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
5
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/repr_c.stderr
vendored
Normal file
5
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/repr_c.stderr
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
error: repr(C) doesn't have a well defined size
|
||||
--> $DIR/repr_c.rs:2:8
|
||||
|
|
||||
2 | #[repr(C)]
|
||||
| ^
|
||||
11
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/unpexpected_alternatives.rs
vendored
Normal file
11
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/unpexpected_alternatives.rs
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#[derive(num_enum::UnsafeFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Numbers {
|
||||
Zero,
|
||||
#[num_enum(alternatives = [2])]
|
||||
One,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
error: #[derive(UnsafeFromPrimitive)] does not support `#[num_enum(alternatives = [..])]`
|
||||
--> $DIR/unpexpected_alternatives.rs:5:16
|
||||
|
|
||||
5 | #[num_enum(alternatives = [2])]
|
||||
| ^^^^^^^^^^^^
|
||||
11
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/unpexpected_default.rs
vendored
Normal file
11
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/unpexpected_default.rs
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#[derive(num_enum::UnsafeFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Numbers {
|
||||
Zero,
|
||||
#[num_enum(default)]
|
||||
NoneZero,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
}
|
||||
5
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/unpexpected_default.stderr
vendored
Normal file
5
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/unpexpected_default.stderr
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
error: #[derive(UnsafeFromPrimitive)] does not support `#[num_enum(default)]`
|
||||
--> $DIR/unpexpected_default.rs:5:16
|
||||
|
|
||||
5 | #[num_enum(default)]
|
||||
| ^^^^^^^
|
||||
22
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/variants_with_fields.rs
vendored
Normal file
22
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/variants_with_fields.rs
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
use num_enum::{FromPrimitive, IntoPrimitive, TryFromPrimitive};
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Number {
|
||||
Zero,
|
||||
NonZero(u8),
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, FromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Colour {
|
||||
Red { intensity: u8 },
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, IntoPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Meaningless {
|
||||
Beep(),
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
17
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/variants_with_fields.stderr
vendored
Normal file
17
third-party/vendor/num_enum-0.5.11/tests/try_build/compile_fail/variants_with_fields.stderr
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
error: `num_enum` only supports unit variants (with no associated data), but `Number::NonZero` was not a unit variant.
|
||||
--> $DIR/variants_with_fields.rs:7:5
|
||||
|
|
||||
7 | NonZero(u8),
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: `num_enum` only supports unit variants (with no associated data), but `Colour::Red` was not a unit variant.
|
||||
--> $DIR/variants_with_fields.rs:13:5
|
||||
|
|
||||
13 | Red { intensity: u8 },
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: `num_enum` only supports unit variants (with no associated data), but `Meaningless::Beep` was not a unit variant.
|
||||
--> $DIR/variants_with_fields.rs:19:5
|
||||
|
|
||||
19 | Beep(),
|
||||
| ^^^^^^
|
||||
66
third-party/vendor/num_enum-0.5.11/tests/try_build/pass/default_and_alternatives.rs
vendored
Normal file
66
third-party/vendor/num_enum-0.5.11/tests/try_build/pass/default_and_alternatives.rs
vendored
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
#[derive(num_enum::TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Default {
|
||||
#[num_enum(default)]
|
||||
Foo = 0,
|
||||
Bar = 1,
|
||||
}
|
||||
|
||||
#[derive(num_enum::TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Alternatives {
|
||||
#[num_enum(alternatives = [])]
|
||||
Foo = 0,
|
||||
#[num_enum(alternatives = [3])]
|
||||
Bar = 1,
|
||||
#[num_enum(alternatives = [4, 5])]
|
||||
Baz = 2,
|
||||
#[num_enum(alternatives = [7])]
|
||||
#[num_enum(alternatives = [8])]
|
||||
Blee = 6,
|
||||
}
|
||||
|
||||
#[derive(num_enum::TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Both {
|
||||
#[num_enum(default)]
|
||||
Foo = 0,
|
||||
#[num_enum(alternatives = [3])]
|
||||
Bar = 1,
|
||||
}
|
||||
|
||||
mod mixed {
|
||||
#[derive(num_enum::TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum AlternativesFollowedByDefaultInSingleAttribute {
|
||||
#[num_enum(alternatives = [1, 2], default)]
|
||||
Foo = 0,
|
||||
}
|
||||
|
||||
#[derive(num_enum::TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum DefaultFollowedByAlternativesInSingleAttribute {
|
||||
#[num_enum(default, alternatives = [1, 2])]
|
||||
Foo = 0,
|
||||
}
|
||||
|
||||
#[derive(num_enum::TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum AlternativesFollowedByDefaultInMultipleAttributes {
|
||||
#[num_enum(alternatives = [1, 2])]
|
||||
#[num_enum(default)]
|
||||
Foo = 0,
|
||||
}
|
||||
|
||||
#[derive(num_enum::TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum DefaultFollowedByAlternativesInMultipleAttributes {
|
||||
#[num_enum(default)]
|
||||
#[num_enum(alternatives = [1, 2])]
|
||||
Foo = 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
}
|
||||
40
third-party/vendor/num_enum-0.5.11/tests/try_build/pass/exhaustive_enum_try_from.rs
vendored
Normal file
40
third-party/vendor/num_enum-0.5.11/tests/try_build/pass/exhaustive_enum_try_from.rs
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#[derive(num_enum::TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum ExhaustiveTryFrom {
|
||||
#[num_enum(alternatives = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])]
|
||||
A = 0,
|
||||
#[num_enum(alternatives = [17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31])]
|
||||
B = 16,
|
||||
#[num_enum(alternatives = [33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47])]
|
||||
C = 32,
|
||||
#[num_enum(alternatives = [49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63])]
|
||||
D = 48,
|
||||
#[num_enum(alternatives = [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79])]
|
||||
E = 64,
|
||||
#[num_enum(alternatives = [81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95])]
|
||||
F = 80,
|
||||
#[num_enum(alternatives = [97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111])]
|
||||
G = 96,
|
||||
#[num_enum(alternatives = [113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127])]
|
||||
H = 112,
|
||||
#[num_enum(alternatives = [129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143])]
|
||||
I = 128,
|
||||
#[num_enum(alternatives = [145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159])]
|
||||
J = 144,
|
||||
#[num_enum(alternatives = [161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175])]
|
||||
K = 160,
|
||||
#[num_enum(alternatives = [177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191])]
|
||||
L = 176,
|
||||
#[num_enum(alternatives = [193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207])]
|
||||
M = 192,
|
||||
#[num_enum(alternatives = [209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223])]
|
||||
N = 208,
|
||||
#[num_enum(alternatives = [225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239])]
|
||||
O = 224,
|
||||
#[num_enum(alternatives = [241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255])]
|
||||
P = 240,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
}
|
||||
40
third-party/vendor/num_enum-0.5.11/tests/try_build/pass/exhaustive_enum_via_alternatives.rs
vendored
Normal file
40
third-party/vendor/num_enum-0.5.11/tests/try_build/pass/exhaustive_enum_via_alternatives.rs
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#[derive(num_enum::FromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum ExhaustiveFrom {
|
||||
#[num_enum(alternatives = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])]
|
||||
A = 0,
|
||||
#[num_enum(alternatives = [17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31])]
|
||||
B = 16,
|
||||
#[num_enum(alternatives = [33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47])]
|
||||
C = 32,
|
||||
#[num_enum(alternatives = [49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63])]
|
||||
D = 48,
|
||||
#[num_enum(alternatives = [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79])]
|
||||
E = 64,
|
||||
#[num_enum(alternatives = [81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95])]
|
||||
F = 80,
|
||||
#[num_enum(alternatives = [97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111])]
|
||||
G = 96,
|
||||
#[num_enum(alternatives = [113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127])]
|
||||
H = 112,
|
||||
#[num_enum(alternatives = [129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143])]
|
||||
I = 128,
|
||||
#[num_enum(alternatives = [145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159])]
|
||||
J = 144,
|
||||
#[num_enum(alternatives = [161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175])]
|
||||
K = 160,
|
||||
#[num_enum(alternatives = [177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191])]
|
||||
L = 176,
|
||||
#[num_enum(alternatives = [193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207])]
|
||||
M = 192,
|
||||
#[num_enum(alternatives = [209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223])]
|
||||
N = 208,
|
||||
#[num_enum(alternatives = [225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239])]
|
||||
O = 224,
|
||||
#[num_enum(alternatives = [241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255])]
|
||||
P = 240,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
}
|
||||
39
third-party/vendor/num_enum-0.5.11/tests/try_build/pass/exhaustive_enum_via_default.rs
vendored
Normal file
39
third-party/vendor/num_enum-0.5.11/tests/try_build/pass/exhaustive_enum_via_default.rs
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#[derive(num_enum::FromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum ExhaustiveFrom {
|
||||
#[num_enum(default)]
|
||||
#[num_enum(alternatives = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])]
|
||||
A = 0,
|
||||
#[num_enum(alternatives = [17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31])]
|
||||
B = 16,
|
||||
#[num_enum(alternatives = [33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47])]
|
||||
C = 32,
|
||||
#[num_enum(alternatives = [49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63])]
|
||||
D = 48,
|
||||
#[num_enum(alternatives = [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79])]
|
||||
E = 64,
|
||||
#[num_enum(alternatives = [81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95])]
|
||||
F = 80,
|
||||
#[num_enum(alternatives = [97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111])]
|
||||
G = 96,
|
||||
#[num_enum(alternatives = [113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127])]
|
||||
H = 112,
|
||||
#[num_enum(alternatives = [129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143])]
|
||||
I = 128,
|
||||
#[num_enum(alternatives = [145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159])]
|
||||
J = 144,
|
||||
#[num_enum(alternatives = [161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175])]
|
||||
K = 160,
|
||||
#[num_enum(alternatives = [177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191])]
|
||||
L = 176,
|
||||
#[num_enum(alternatives = [193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207])]
|
||||
M = 192,
|
||||
#[num_enum(alternatives = [209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223])]
|
||||
N = 208,
|
||||
#[num_enum(alternatives = [225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239])]
|
||||
O = 224,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#[derive(num_enum::FromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Numbers {
|
||||
Zero = 0,
|
||||
#[num_enum(alternatives = [2..=255])]
|
||||
NonZero = 1,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#[derive(num_enum::TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Numbers {
|
||||
Zero = 0,
|
||||
#[num_enum(alternatives = [2..255])]
|
||||
NonZero = 1,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
}
|
||||
504
third-party/vendor/num_enum-0.5.11/tests/try_from_primitive.rs
vendored
Normal file
504
third-party/vendor/num_enum-0.5.11/tests/try_from_primitive.rs
vendored
Normal file
|
|
@ -0,0 +1,504 @@
|
|||
use ::std::convert::{TryFrom, TryInto};
|
||||
|
||||
use ::num_enum::TryFromPrimitive;
|
||||
|
||||
// Guard against https://github.com/illicitonion/num_enum/issues/27
|
||||
mod alloc {}
|
||||
mod core {}
|
||||
mod num_enum {}
|
||||
mod std {}
|
||||
|
||||
#[test]
|
||||
fn simple() {
|
||||
#[derive(Debug, Eq, PartialEq, TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
Zero,
|
||||
One,
|
||||
Two,
|
||||
}
|
||||
|
||||
let zero: Result<Enum, _> = 0u8.try_into();
|
||||
assert_eq!(zero, Ok(Enum::Zero));
|
||||
|
||||
let three: Result<Enum, _> = 3u8.try_into();
|
||||
assert_eq!(
|
||||
three.unwrap_err().to_string(),
|
||||
"No discriminant in enum `Enum` matches the value `3`"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn even() {
|
||||
#[derive(Debug, Eq, PartialEq, TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
Zero = 0,
|
||||
Two = 2,
|
||||
Four = 4,
|
||||
}
|
||||
|
||||
let zero: Result<Enum, _> = 0u8.try_into();
|
||||
assert_eq!(zero, Ok(Enum::Zero));
|
||||
|
||||
let one: Result<Enum, _> = 1u8.try_into();
|
||||
assert_eq!(
|
||||
one.unwrap_err().to_string(),
|
||||
"No discriminant in enum `Enum` matches the value `1`"
|
||||
);
|
||||
|
||||
let two: Result<Enum, _> = 2u8.try_into();
|
||||
assert_eq!(two, Ok(Enum::Two));
|
||||
|
||||
let three: Result<Enum, _> = 3u8.try_into();
|
||||
assert_eq!(
|
||||
three.unwrap_err().to_string(),
|
||||
"No discriminant in enum `Enum` matches the value `3`"
|
||||
);
|
||||
|
||||
let four: Result<Enum, _> = 4u8.try_into();
|
||||
assert_eq!(four, Ok(Enum::Four));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn skipped_value() {
|
||||
#[derive(Debug, Eq, PartialEq, TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
Zero,
|
||||
One,
|
||||
Three = 3,
|
||||
Four,
|
||||
}
|
||||
|
||||
let zero: Result<Enum, _> = 0u8.try_into();
|
||||
assert_eq!(zero, Ok(Enum::Zero));
|
||||
|
||||
let one: Result<Enum, _> = 1u8.try_into();
|
||||
assert_eq!(one, Ok(Enum::One));
|
||||
|
||||
let two: Result<Enum, _> = 2u8.try_into();
|
||||
assert_eq!(
|
||||
two.unwrap_err().to_string(),
|
||||
"No discriminant in enum `Enum` matches the value `2`"
|
||||
);
|
||||
|
||||
let three: Result<Enum, _> = 3u8.try_into();
|
||||
assert_eq!(three, Ok(Enum::Three));
|
||||
|
||||
let four: Result<Enum, _> = 4u8.try_into();
|
||||
assert_eq!(four, Ok(Enum::Four));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wrong_order() {
|
||||
#[derive(Debug, Eq, PartialEq, TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
Four = 4,
|
||||
Three = 3,
|
||||
Zero = 0,
|
||||
One, // Zero + 1
|
||||
}
|
||||
|
||||
let zero: Result<Enum, _> = 0u8.try_into();
|
||||
assert_eq!(zero, Ok(Enum::Zero));
|
||||
|
||||
let one: Result<Enum, _> = 1u8.try_into();
|
||||
assert_eq!(one, Ok(Enum::One));
|
||||
|
||||
let two: Result<Enum, _> = 2u8.try_into();
|
||||
assert_eq!(
|
||||
two.unwrap_err().to_string(),
|
||||
"No discriminant in enum `Enum` matches the value `2`"
|
||||
);
|
||||
|
||||
let three: Result<Enum, _> = 3u8.try_into();
|
||||
assert_eq!(three, Ok(Enum::Three));
|
||||
|
||||
let four: Result<Enum, _> = 4u8.try_into();
|
||||
assert_eq!(four, Ok(Enum::Four));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn negative_values() {
|
||||
#[derive(Debug, Eq, PartialEq, TryFromPrimitive)]
|
||||
#[repr(i8)]
|
||||
enum Enum {
|
||||
MinusTwo = -2,
|
||||
MinusOne = -1,
|
||||
Zero = 0,
|
||||
One = 1,
|
||||
Two = 2,
|
||||
}
|
||||
|
||||
let minus_two: Result<Enum, _> = (-2i8).try_into();
|
||||
assert_eq!(minus_two, Ok(Enum::MinusTwo));
|
||||
|
||||
let minus_one: Result<Enum, _> = (-1i8).try_into();
|
||||
assert_eq!(minus_one, Ok(Enum::MinusOne));
|
||||
|
||||
let zero: Result<Enum, _> = 0i8.try_into();
|
||||
assert_eq!(zero, Ok(Enum::Zero));
|
||||
|
||||
let one: Result<Enum, _> = 1i8.try_into();
|
||||
assert_eq!(one, Ok(Enum::One));
|
||||
|
||||
let two: Result<Enum, _> = 2i8.try_into();
|
||||
assert_eq!(two, Ok(Enum::Two));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn discriminant_expressions() {
|
||||
const ONE: u8 = 1;
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
Zero,
|
||||
One = ONE,
|
||||
Two,
|
||||
Four = 4u8,
|
||||
Five,
|
||||
Six = ONE + ONE + 2u8 + 2,
|
||||
}
|
||||
|
||||
let zero: Result<Enum, _> = 0u8.try_into();
|
||||
assert_eq!(zero, Ok(Enum::Zero));
|
||||
|
||||
let one: Result<Enum, _> = 1u8.try_into();
|
||||
assert_eq!(one, Ok(Enum::One));
|
||||
|
||||
let two: Result<Enum, _> = 2u8.try_into();
|
||||
assert_eq!(two, Ok(Enum::Two));
|
||||
|
||||
let three: Result<Enum, _> = 3u8.try_into();
|
||||
assert_eq!(
|
||||
three.unwrap_err().to_string(),
|
||||
"No discriminant in enum `Enum` matches the value `3`",
|
||||
);
|
||||
|
||||
let four: Result<Enum, _> = 4u8.try_into();
|
||||
assert_eq!(four, Ok(Enum::Four));
|
||||
|
||||
let five: Result<Enum, _> = 5u8.try_into();
|
||||
assert_eq!(five, Ok(Enum::Five));
|
||||
|
||||
let six: Result<Enum, _> = 6u8.try_into();
|
||||
assert_eq!(six, Ok(Enum::Six));
|
||||
}
|
||||
|
||||
#[cfg(feature = "complex-expressions")]
|
||||
mod complex {
|
||||
use num_enum::TryFromPrimitive;
|
||||
use std::convert::TryInto;
|
||||
|
||||
const ONE: u8 = 1;
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
Zero,
|
||||
One = ONE,
|
||||
Two,
|
||||
Four = 4u8,
|
||||
Five,
|
||||
Six = ONE + ONE + 2u8 + 2,
|
||||
Seven = (7, 2).0,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn different_values() {
|
||||
let zero: Result<Enum, _> = 0u8.try_into();
|
||||
assert_eq!(zero, Ok(Enum::Zero));
|
||||
|
||||
let one: Result<Enum, _> = 1u8.try_into();
|
||||
assert_eq!(one, Ok(Enum::One));
|
||||
|
||||
let two: Result<Enum, _> = 2u8.try_into();
|
||||
assert_eq!(two, Ok(Enum::Two));
|
||||
|
||||
let three: Result<Enum, _> = 3u8.try_into();
|
||||
assert_eq!(
|
||||
three.unwrap_err().to_string(),
|
||||
"No discriminant in enum `Enum` matches the value `3`",
|
||||
);
|
||||
|
||||
let four: Result<Enum, _> = 4u8.try_into();
|
||||
assert_eq!(four, Ok(Enum::Four));
|
||||
|
||||
let five: Result<Enum, _> = 5u8.try_into();
|
||||
assert_eq!(five, Ok(Enum::Five));
|
||||
|
||||
let six: Result<Enum, _> = 6u8.try_into();
|
||||
assert_eq!(six, Ok(Enum::Six));
|
||||
|
||||
let seven: Result<Enum, _> = 7u8.try_into();
|
||||
assert_eq!(seven, Ok(Enum::Seven));
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum EnumWithExclusiveRange {
|
||||
Zero = 0,
|
||||
#[num_enum(alternatives = [2..4])]
|
||||
OneOrTwoOrThree,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn different_values_with_exclusive_range() {
|
||||
let zero: Result<EnumWithExclusiveRange, _> = 0u8.try_into();
|
||||
assert_eq!(zero, Ok(EnumWithExclusiveRange::Zero));
|
||||
|
||||
let one: Result<EnumWithExclusiveRange, _> = 1u8.try_into();
|
||||
assert_eq!(one, Ok(EnumWithExclusiveRange::OneOrTwoOrThree));
|
||||
|
||||
let two: Result<EnumWithExclusiveRange, _> = 2u8.try_into();
|
||||
assert_eq!(two, Ok(EnumWithExclusiveRange::OneOrTwoOrThree));
|
||||
|
||||
let three: Result<EnumWithExclusiveRange, _> = 3u8.try_into();
|
||||
assert_eq!(three, Ok(EnumWithExclusiveRange::OneOrTwoOrThree));
|
||||
|
||||
let four: Result<EnumWithExclusiveRange, _> = 4u8.try_into();
|
||||
assert_eq!(
|
||||
four.unwrap_err().to_string(),
|
||||
"No discriminant in enum `EnumWithExclusiveRange` matches the value `4`",
|
||||
);
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum EnumWithInclusiveRange {
|
||||
Zero = 0,
|
||||
#[num_enum(alternatives = [2..=3])]
|
||||
OneOrTwoOrThree,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn different_values_with_inclusive_range() {
|
||||
let zero: Result<EnumWithInclusiveRange, _> = 0u8.try_into();
|
||||
assert_eq!(zero, Ok(EnumWithInclusiveRange::Zero));
|
||||
|
||||
let one: Result<EnumWithInclusiveRange, _> = 1u8.try_into();
|
||||
assert_eq!(one, Ok(EnumWithInclusiveRange::OneOrTwoOrThree));
|
||||
|
||||
let two: Result<EnumWithInclusiveRange, _> = 2u8.try_into();
|
||||
assert_eq!(two, Ok(EnumWithInclusiveRange::OneOrTwoOrThree));
|
||||
|
||||
let three: Result<EnumWithInclusiveRange, _> = 3u8.try_into();
|
||||
assert_eq!(three, Ok(EnumWithInclusiveRange::OneOrTwoOrThree));
|
||||
|
||||
let four: Result<EnumWithInclusiveRange, _> = 4u8.try_into();
|
||||
assert_eq!(
|
||||
four.unwrap_err().to_string(),
|
||||
"No discriminant in enum `EnumWithInclusiveRange` matches the value `4`",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_trailing_comma() {
|
||||
#[rustfmt::skip]
|
||||
#[derive(Debug, Eq, PartialEq, TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
Zero,
|
||||
One
|
||||
}
|
||||
|
||||
let zero: Result<Enum, _> = 0u8.try_into();
|
||||
assert_eq!(zero, Ok(Enum::Zero));
|
||||
|
||||
let one: Result<Enum, _> = 1u8.try_into();
|
||||
assert_eq!(one, Ok(Enum::One));
|
||||
|
||||
let two: Result<Enum, _> = 2u8.try_into();
|
||||
assert_eq!(
|
||||
two.unwrap_err().to_string(),
|
||||
"No discriminant in enum `Enum` matches the value `2`"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ignores_extra_attributes() {
|
||||
#[derive(Debug, Eq, PartialEq, TryFromPrimitive)]
|
||||
#[allow(unused)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
Zero,
|
||||
#[allow(unused)]
|
||||
One,
|
||||
}
|
||||
|
||||
let zero: Result<Enum, _> = 0u8.try_into();
|
||||
assert_eq!(zero, Ok(Enum::Zero));
|
||||
|
||||
let one: Result<Enum, _> = 1u8.try_into();
|
||||
assert_eq!(one, Ok(Enum::One));
|
||||
|
||||
let two: Result<Enum, _> = 2u8.try_into();
|
||||
assert_eq!(
|
||||
two.unwrap_err().to_string(),
|
||||
"No discriminant in enum `Enum` matches the value `2`"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn visibility_is_fine() {
|
||||
#[derive(Debug, Eq, PartialEq, TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
pub(crate) enum Enum {
|
||||
Zero,
|
||||
One,
|
||||
}
|
||||
|
||||
let zero: Result<Enum, _> = 0u8.try_into();
|
||||
assert_eq!(zero, Ok(Enum::Zero));
|
||||
|
||||
let one: Result<Enum, _> = 1u8.try_into();
|
||||
assert_eq!(one, Ok(Enum::One));
|
||||
|
||||
let two: Result<Enum, _> = 2u8.try_into();
|
||||
assert_eq!(
|
||||
two.unwrap_err().to_string(),
|
||||
"No discriminant in enum `Enum` matches the value `2`"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_variant_is_allowed() {
|
||||
#[derive(Debug, Eq, PartialEq, TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
pub enum Enum {
|
||||
Ok,
|
||||
Error,
|
||||
}
|
||||
|
||||
let ok: Result<Enum, _> = 0u8.try_into();
|
||||
assert_eq!(ok, Ok(Enum::Ok));
|
||||
|
||||
let err: Result<Enum, _> = 1u8.try_into();
|
||||
assert_eq!(err, Ok(Enum::Error));
|
||||
|
||||
let unknown: Result<Enum, _> = 2u8.try_into();
|
||||
assert_eq!(
|
||||
unknown.unwrap_err().to_string(),
|
||||
"No discriminant in enum `Enum` matches the value `2`"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alternative_values() {
|
||||
#[derive(Debug, Eq, PartialEq, TryFromPrimitive)]
|
||||
#[repr(i8)]
|
||||
enum Enum {
|
||||
Zero = 0,
|
||||
#[num_enum(alternatives = [-1, 2, 3])]
|
||||
OneTwoThreeOrMinusOne = 1,
|
||||
}
|
||||
|
||||
let minus_one: Result<Enum, _> = (-1i8).try_into();
|
||||
assert_eq!(minus_one, Ok(Enum::OneTwoThreeOrMinusOne));
|
||||
|
||||
let zero: Result<Enum, _> = 0i8.try_into();
|
||||
assert_eq!(zero, Ok(Enum::Zero));
|
||||
|
||||
let one: Result<Enum, _> = 1i8.try_into();
|
||||
assert_eq!(one, Ok(Enum::OneTwoThreeOrMinusOne));
|
||||
|
||||
let two: Result<Enum, _> = 2i8.try_into();
|
||||
assert_eq!(two, Ok(Enum::OneTwoThreeOrMinusOne));
|
||||
|
||||
let three: Result<Enum, _> = 3i8.try_into();
|
||||
assert_eq!(three, Ok(Enum::OneTwoThreeOrMinusOne));
|
||||
|
||||
let four: Result<Enum, _> = 4i8.try_into();
|
||||
assert_eq!(
|
||||
four.unwrap_err().to_string(),
|
||||
"No discriminant in enum `Enum` matches the value `4`"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_value() {
|
||||
#[derive(Debug, Eq, PartialEq, TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
Zero = 0,
|
||||
One = 1,
|
||||
#[num_enum(default)]
|
||||
Other = 2,
|
||||
}
|
||||
|
||||
let zero: Result<Enum, _> = 0u8.try_into();
|
||||
assert_eq!(zero, Ok(Enum::Zero));
|
||||
|
||||
let one: Result<Enum, _> = 1u8.try_into();
|
||||
assert_eq!(one, Ok(Enum::One));
|
||||
|
||||
let two: Result<Enum, _> = 2u8.try_into();
|
||||
assert_eq!(two, Ok(Enum::Other));
|
||||
|
||||
let max_value: Result<Enum, _> = u8::max_value().try_into();
|
||||
assert_eq!(max_value, Ok(Enum::Other));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alternative_values_and_default_value() {
|
||||
#[derive(Debug, Eq, PartialEq, TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
#[num_enum(default)]
|
||||
Zero = 0,
|
||||
One = 1,
|
||||
#[num_enum(alternatives = [3])]
|
||||
TwoOrThree = 2,
|
||||
Four = 4,
|
||||
}
|
||||
|
||||
let zero: Result<Enum, _> = 0u8.try_into();
|
||||
assert_eq!(zero, Ok(Enum::Zero));
|
||||
|
||||
let one: Result<Enum, _> = 1u8.try_into();
|
||||
assert_eq!(one, Ok(Enum::One));
|
||||
|
||||
let two: Result<Enum, _> = 2u8.try_into();
|
||||
assert_eq!(two, Ok(Enum::TwoOrThree));
|
||||
|
||||
let three: Result<Enum, _> = 3u8.try_into();
|
||||
assert_eq!(three, Ok(Enum::TwoOrThree));
|
||||
|
||||
let four: Result<Enum, _> = 4u8.try_into();
|
||||
assert_eq!(four, Ok(Enum::Four));
|
||||
|
||||
let five: Result<Enum, _> = 5u8.try_into();
|
||||
assert_eq!(five, Ok(Enum::Zero));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn try_from_primitive_number() {
|
||||
#[derive(Debug, Eq, PartialEq, TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
#[num_enum(default)]
|
||||
Whatever = 0,
|
||||
}
|
||||
|
||||
// #[derive(FromPrimitive)] generates implementations for the following traits:
|
||||
//
|
||||
// - `TryFromPrimitive<T>`
|
||||
// - `TryFrom<T>`
|
||||
|
||||
let try_from_primitive = Enum::try_from_primitive(0_u8);
|
||||
assert_eq!(try_from_primitive, Ok(Enum::Whatever));
|
||||
|
||||
let try_from = Enum::try_from(0_u8);
|
||||
assert_eq!(try_from, Ok(Enum::Whatever));
|
||||
}
|
||||
|
||||
// #[derive(FromPrimitive)] generates implementations for the following traits:
|
||||
//
|
||||
// - `FromPrimitive<T>`
|
||||
// - `From<T>`
|
||||
// - `TryFromPrimitive<T>`
|
||||
// - `TryFrom<T>`
|
||||
22
third-party/vendor/num_enum-0.5.11/tests/unsafe_from_primitive.rs
vendored
Normal file
22
third-party/vendor/num_enum-0.5.11/tests/unsafe_from_primitive.rs
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
use ::num_enum::UnsafeFromPrimitive;
|
||||
|
||||
// Guard against https://github.com/illicitonion/num_enum/issues/27
|
||||
mod alloc {}
|
||||
mod core {}
|
||||
mod num_enum {}
|
||||
mod std {}
|
||||
|
||||
#[test]
|
||||
fn has_unsafe_from_primitive_number() {
|
||||
#[derive(Debug, Eq, PartialEq, UnsafeFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
Zero,
|
||||
One,
|
||||
}
|
||||
|
||||
unsafe {
|
||||
assert_eq!(Enum::from_unchecked(0_u8), Enum::Zero);
|
||||
assert_eq!(Enum::from_unchecked(1_u8), Enum::One);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue