2020-06-22 12:57:03 +00:00
|
|
|
//@ build-fail
|
2021-10-01 02:03:49 +00:00
|
|
|
//@ compile-flags:-Zpolymorphize=on -Zinline-mir=off
|
2023-10-19 21:46:28 +00:00
|
|
|
#![feature(generic_const_exprs, coroutines, coroutine_trait, rustc_attrs)]
|
2021-08-27 16:04:57 +00:00
|
|
|
//~^ WARN the feature `generic_const_exprs` is incomplete
|
2020-06-22 12:57:03 +00:00
|
|
|
|
|
|
|
use std::marker::Unpin;
|
2023-10-19 16:06:43 +00:00
|
|
|
use std::ops::{Coroutine, CoroutineState};
|
2020-06-22 12:57:03 +00:00
|
|
|
use std::pin::Pin;
|
|
|
|
|
|
|
|
enum YieldOrReturn<Y, R> {
|
|
|
|
Yield(Y),
|
|
|
|
Return(R),
|
|
|
|
}
|
|
|
|
|
|
|
|
fn finish<T, Y, R>(mut t: T) -> Vec<YieldOrReturn<Y, R>>
|
|
|
|
where
|
2023-10-19 16:06:43 +00:00
|
|
|
T: Coroutine<(), Yield = Y, Return = R> + Unpin,
|
2020-06-22 12:57:03 +00:00
|
|
|
{
|
|
|
|
let mut results = Vec::new();
|
|
|
|
loop {
|
|
|
|
match Pin::new(&mut t).resume(()) {
|
2023-10-19 16:06:43 +00:00
|
|
|
CoroutineState::Yielded(yielded) => results.push(YieldOrReturn::Yield(yielded)),
|
|
|
|
CoroutineState::Complete(returned) => {
|
2020-06-22 12:57:03 +00:00
|
|
|
results.push(YieldOrReturn::Return(returned));
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 21:46:28 +00:00
|
|
|
// This test checks that the polymorphization analysis functions on coroutines.
|
2020-06-22 12:57:03 +00:00
|
|
|
|
2020-07-16 16:52:23 +00:00
|
|
|
#[rustc_polymorphize_error]
|
2023-10-19 16:06:43 +00:00
|
|
|
pub fn unused_type<T>() -> impl Coroutine<(), Yield = u32, Return = u32> + Unpin {
|
2024-04-11 13:15:34 +00:00
|
|
|
#[coroutine]
|
2020-06-22 12:57:03 +00:00
|
|
|
|| {
|
|
|
|
//~^ ERROR item has unused generic parameters
|
|
|
|
yield 1;
|
|
|
|
2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-16 16:52:23 +00:00
|
|
|
#[rustc_polymorphize_error]
|
2023-10-19 16:06:43 +00:00
|
|
|
pub fn used_type_in_yield<Y: Default>() -> impl Coroutine<(), Yield = Y, Return = u32> + Unpin {
|
2024-04-11 13:15:34 +00:00
|
|
|
#[coroutine]
|
2020-06-22 12:57:03 +00:00
|
|
|
|| {
|
|
|
|
yield Y::default();
|
|
|
|
2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-16 16:52:23 +00:00
|
|
|
#[rustc_polymorphize_error]
|
2023-10-19 16:06:43 +00:00
|
|
|
pub fn used_type_in_return<R: Default>() -> impl Coroutine<(), Yield = u32, Return = R> + Unpin {
|
2024-04-11 13:15:34 +00:00
|
|
|
#[coroutine]
|
2020-06-22 12:57:03 +00:00
|
|
|
|| {
|
|
|
|
yield 3;
|
|
|
|
R::default()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-16 16:52:23 +00:00
|
|
|
#[rustc_polymorphize_error]
|
2023-10-19 16:06:43 +00:00
|
|
|
pub fn unused_const<const T: u32>() -> impl Coroutine<(), Yield = u32, Return = u32> + Unpin {
|
2024-04-11 13:15:34 +00:00
|
|
|
#[coroutine]
|
2020-06-22 12:57:03 +00:00
|
|
|
|| {
|
|
|
|
//~^ ERROR item has unused generic parameters
|
|
|
|
yield 1;
|
|
|
|
2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-16 16:52:23 +00:00
|
|
|
#[rustc_polymorphize_error]
|
2023-10-19 16:06:43 +00:00
|
|
|
pub fn used_const_in_yield<const Y: u32>() -> impl Coroutine<(), Yield = u32, Return = u32> + Unpin
|
2020-06-22 12:57:03 +00:00
|
|
|
{
|
2024-04-11 13:15:34 +00:00
|
|
|
#[coroutine]
|
2020-06-22 12:57:03 +00:00
|
|
|
|| {
|
|
|
|
yield Y;
|
|
|
|
2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-16 16:52:23 +00:00
|
|
|
#[rustc_polymorphize_error]
|
2023-10-19 16:06:43 +00:00
|
|
|
pub fn used_const_in_return<const R: u32>() -> impl Coroutine<(), Yield = u32, Return = u32> + Unpin
|
2020-06-22 12:57:03 +00:00
|
|
|
{
|
2024-04-11 13:15:34 +00:00
|
|
|
#[coroutine]
|
2020-06-22 12:57:03 +00:00
|
|
|
|| {
|
|
|
|
yield 4;
|
|
|
|
R
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
finish(unused_type::<u32>());
|
|
|
|
finish(used_type_in_yield::<u32>());
|
|
|
|
finish(used_type_in_return::<u32>());
|
|
|
|
finish(unused_const::<1u32>());
|
|
|
|
finish(used_const_in_yield::<1u32>());
|
|
|
|
finish(used_const_in_return::<1u32>());
|
|
|
|
}
|