1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
// SPDX-License-Identifier: Apache-2.0 OR MIT
#![cfg(feature = "type_analysis")]
#![allow(dead_code)]
use std::fmt;
use auto_enums::auto_enum;
#[test]
fn func() {
#[auto_enum] // there is no need to specify std library's traits
fn test1(x: i32) -> impl Iterator<Item = i32> {
match x {
0 => 1..10,
_ => vec![5, 10].into_iter(),
}
}
#[auto_enum] // this is handled as a dummy attribute.
fn test2(x: i32) -> impl Iterator<Item = i32> {
#[auto_enum(Iterator)]
match x {
0 => 1..10,
_ => vec![5, 10].into_iter(),
}
}
#[auto_enum] // there is no need to specify std library's traits
fn test3(x: i32) -> impl Iterator<Item = i32> {
match x {
0 => return 1..10,
_ => vec![5, 10].into_iter(),
}
}
#[auto_enum] // this is handled as a dummy attribute.
fn test4(x: i32) -> impl Iterator<Item = i32> {
#[auto_enum(Iterator)]
let iter = match x {
0 => 1..10,
1 => 11..=20,
_ => return vec![5, 10].into_iter(),
};
iter.collect::<Vec<_>>().into_iter()
}
#[auto_enum]
fn break_in_loop(mut x: i32) -> impl Iterator<Item = i32> {
loop {
if x < 0 {
break x..0;
} else if x % 5 == 0 {
break 0..=x;
}
x -= 1;
}
}
#[auto_enum]
fn return_in_loop(mut x: i32) -> impl Iterator<Item = i32> {
loop {
if x < 0 {
return x..0;
} else if x % 5 == 0 {
return 0..=x;
}
x -= 1;
}
}
}
#[test]
fn local() {
#[auto_enum]
fn test1(x: i32) {
#[auto_enum]
let _y: impl Iterator<Item = i32> = match x {
0 => 1..10,
_ => vec![5, 10].into_iter(),
};
}
#[auto_enum]
fn test2(x: i32) -> impl Iterator<Item = i32> + fmt::Debug {
#[auto_enum(fmt::Debug)]
let y: impl Iterator<Item = i32> = match x {
0 => 1..10,
_ => vec![5, 10].into_iter(),
};
y
}
}
|