rust/src/test/ui/infinite/infinite-instantiation.rs

29 lines
549 B
Rust
Raw Normal View History

// build-fail
trait ToOpt: Sized {
fn to_option(&self) -> Option<Self>;
}
impl ToOpt for usize {
fn to_option(&self) -> Option<usize> {
2013-03-13 19:57:30 -05:00
Some(*self)
}
}
impl<T:Clone> ToOpt for Option<T> {
fn to_option(&self) -> Option<Option<T>> {
2013-07-02 14:47:32 -05:00
Some((*self).clone())
}
}
fn function<T:ToOpt + Clone>(counter: usize, t: T) {
if counter > 0 {
function(counter - 1, t.to_option());
//~^ ERROR reached the recursion limit while instantiating `function::<Option<
}
}
fn main() {
function(22, 22);
}