]> git.proxmox.com Git - rustc.git/blame - src/test/compile-fail/infinite-instantiation.rs
Imported Upstream version 1.5.0+dfsg1
[rustc.git] / src / test / compile-fail / infinite-instantiation.rs
CommitLineData
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//~^^^^^^^^^^ ERROR overflow
12//
13// We get an error message at the top of file (dummy span).
14// This is not helpful, but also kind of annoying to prevent,
15// so for now just live with it.
16// This test case was originally for issue #2258.
223e47cc 17
e9174d1e 18trait ToOpt: Sized {
223e47cc
LB
19 fn to_option(&self) -> Option<Self>;
20}
21
c34b1796 22impl ToOpt for usize {
1a4d82fc 23 fn to_option(&self) -> Option<usize> {
223e47cc
LB
24 Some(*self)
25 }
26}
27
c34b1796 28impl<T:Clone> ToOpt for Option<T> {
223e47cc 29 fn to_option(&self) -> Option<Option<T>> {
1a4d82fc 30 Some((*self).clone())
223e47cc
LB
31 }
32}
33
c34b1796
AL
34fn function<T:ToOpt + Clone>(counter: usize, t: T) {
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
42fn main() {
c34b1796 43 function(22, 22);
223e47cc 44}