2019-12-14 03:28:32 +00:00
|
|
|
//@ build-fail
|
2025-01-30 17:10:19 +00:00
|
|
|
// The regex below normalizes the long type file name to make it suitable for compare-modes.
|
|
|
|
//@ normalize-stderr: "'\$TEST_BUILD_DIR/.*\.long-type.txt'" -> "'$$TEST_BUILD_DIR/$$FILE.long-type.txt'"
|
2019-12-14 03:28:32 +00:00
|
|
|
|
2015-08-07 14:58:00 +00:00
|
|
|
trait ToOpt: Sized {
|
2013-03-13 02:32:14 +00:00
|
|
|
fn to_option(&self) -> Option<Self>;
|
2012-04-23 14:44:52 +00:00
|
|
|
}
|
|
|
|
|
2015-02-20 17:25:30 +00:00
|
|
|
impl ToOpt for usize {
|
2015-01-08 11:02:42 +00:00
|
|
|
fn to_option(&self) -> Option<usize> {
|
2013-03-14 00:57:30 +00:00
|
|
|
Some(*self)
|
2012-04-23 14:44:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-20 17:25:30 +00:00
|
|
|
impl<T:Clone> ToOpt for Option<T> {
|
2013-03-13 02:32:14 +00:00
|
|
|
fn to_option(&self) -> Option<Option<T>> {
|
2013-07-02 19:47:32 +00:00
|
|
|
Some((*self).clone())
|
2012-04-23 14:44:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-20 17:25:30 +00:00
|
|
|
fn function<T:ToOpt + Clone>(counter: usize, t: T) {
|
2015-03-03 08:42:26 +00:00
|
|
|
if counter > 0 {
|
|
|
|
function(counter - 1, t.to_option());
|
2020-09-02 07:40:56 +00:00
|
|
|
//~^ ERROR reached the recursion limit while instantiating `function::<Option<
|
2012-04-23 14:44:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2015-03-03 08:42:26 +00:00
|
|
|
function(22, 22);
|
2012-04-23 14:44:52 +00:00
|
|
|
}
|