2015-02-20 11:25:30 -06:00
|
|
|
//
|
|
|
|
// We get an error message at the top of file (dummy span).
|
|
|
|
// This is not helpful, but also kind of annoying to prevent,
|
|
|
|
// so for now just live with it.
|
|
|
|
// This test case was originally for issue #2258.
|
2012-04-23 09:44:52 -05:00
|
|
|
|
2015-08-07 09:58:00 -05:00
|
|
|
trait ToOpt: Sized {
|
2013-03-12 21:32:14 -05:00
|
|
|
fn to_option(&self) -> Option<Self>;
|
2012-04-23 09:44:52 -05:00
|
|
|
}
|
|
|
|
|
2015-02-20 11:25:30 -06:00
|
|
|
impl ToOpt for usize {
|
2015-01-08 05:02:42 -06:00
|
|
|
fn to_option(&self) -> Option<usize> {
|
2013-03-13 19:57:30 -05:00
|
|
|
Some(*self)
|
2012-04-23 09:44:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-20 11:25:30 -06:00
|
|
|
impl<T:Clone> ToOpt for Option<T> {
|
2013-03-12 21:32:14 -05:00
|
|
|
fn to_option(&self) -> Option<Option<T>> {
|
2013-07-02 14:47:32 -05:00
|
|
|
Some((*self).clone())
|
2012-04-23 09:44:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-20 11:25:30 -06:00
|
|
|
fn function<T:ToOpt + Clone>(counter: usize, t: T) {
|
2016-03-20 06:24:08 -05:00
|
|
|
//~^ ERROR reached the recursion limit while instantiating `function::<std::option::Option<
|
2015-03-03 02:42:26 -06:00
|
|
|
if counter > 0 {
|
|
|
|
function(counter - 1, t.to_option());
|
2015-02-20 11:25:30 -06:00
|
|
|
// FIXME(#4287) Error message should be here. It should be
|
|
|
|
// a type error to instantiate `test` at a type other than T.
|
2012-04-23 09:44:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2015-03-03 02:42:26 -06:00
|
|
|
function(22, 22);
|
2012-04-23 09:44:52 -05:00
|
|
|
}
|