2 // compile-flags:-Zpolymorphize=on
3 #![feature(generic_const_exprs, generators, generator_trait, rustc_attrs)]
4 //~^ WARN the feature `generic_const_exprs` is incomplete
6 use std::marker::Unpin;
7 use std::ops::{Generator, GeneratorState};
10 enum YieldOrReturn<Y, R> {
15 fn finish<T, Y, R>(mut t: T) -> Vec<YieldOrReturn<Y, R>>
17 T: Generator<(), Yield = Y, Return = R> + Unpin,
19 let mut results = Vec::new();
21 match Pin::new(&mut t).resume(()) {
22 GeneratorState::Yielded(yielded) => results.push(YieldOrReturn::Yield(yielded)),
23 GeneratorState::Complete(returned) => {
24 results.push(YieldOrReturn::Return(returned));
31 // This test checks that the polymorphization analysis functions on generators.
33 #[rustc_polymorphize_error]
34 pub fn unused_type<T>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin {
35 //~^ ERROR item has unused generic parameters
37 //~^ ERROR item has unused generic parameters
43 #[rustc_polymorphize_error]
44 pub fn used_type_in_yield<Y: Default>() -> impl Generator<(), Yield = Y, Return = u32> + Unpin {
51 #[rustc_polymorphize_error]
52 pub fn used_type_in_return<R: Default>() -> impl Generator<(), Yield = u32, Return = R> + Unpin {
59 #[rustc_polymorphize_error]
60 pub fn unused_const<const T: u32>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin {
61 //~^ ERROR item has unused generic parameters
63 //~^ ERROR item has unused generic parameters
69 #[rustc_polymorphize_error]
70 pub fn used_const_in_yield<const Y: u32>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin
78 #[rustc_polymorphize_error]
79 pub fn used_const_in_return<const R: u32>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin
88 finish(unused_type::<u32>());
89 finish(used_type_in_yield::<u32>());
90 finish(used_type_in_return::<u32>());
91 finish(unused_const::<1u32>());
92 finish(used_const_in_yield::<1u32>());
93 finish(used_const_in_return::<1u32>());