]>
Commit | Line | Data |
---|---|---|
c34b1796 | 1 | // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT |
223e47cc LB |
2 | // file at the top-level directory of this distribution and at |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
c34b1796 AL |
11 | // |
12 | // We get an error message at the top of file (dummy span). | |
13 | // This is not helpful, but also kind of annoying to prevent, | |
14 | // so for now just live with it. | |
15 | // This test case was originally for issue #2258. | |
223e47cc | 16 | |
e9174d1e | 17 | trait ToOpt: Sized { |
223e47cc LB |
18 | fn to_option(&self) -> Option<Self>; |
19 | } | |
20 | ||
c34b1796 | 21 | impl ToOpt for usize { |
1a4d82fc | 22 | fn to_option(&self) -> Option<usize> { |
223e47cc LB |
23 | Some(*self) |
24 | } | |
25 | } | |
26 | ||
c34b1796 | 27 | impl<T:Clone> ToOpt for Option<T> { |
223e47cc | 28 | fn to_option(&self) -> Option<Option<T>> { |
1a4d82fc | 29 | Some((*self).clone()) |
223e47cc LB |
30 | } |
31 | } | |
32 | ||
c34b1796 | 33 | fn function<T:ToOpt + Clone>(counter: usize, t: T) { |
54a0048b | 34 | //~^ ERROR reached the recursion limit while instantiating `function::<std::option::Option< |
c34b1796 AL |
35 | if counter > 0 { |
36 | function(counter - 1, t.to_option()); | |
37 | // FIXME(#4287) Error message should be here. It should be | |
38 | // a type error to instantiate `test` at a type other than T. | |
223e47cc LB |
39 | } |
40 | } | |
41 | ||
42 | fn main() { | |
c34b1796 | 43 | function(22, 22); |
223e47cc | 44 | } |