1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
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.
11 // Check that a trait is still object-safe (and usable) if it has
12 // methods that return `Self` so long as they require `Self : Sized`.
16 fn new() -> Self where Self : Sized;
17 fn tick(&mut self) -> u32;
24 impl Counter for CCounter {
25 fn new() -> CCounter { CCounter { c: 0 } }
26 fn tick(&mut self) -> u32 { self.c += 1; self.c }
29 fn preticked<C:Counter>() -> C {
30 let mut c: C = Counter::new();
35 fn tick(c: &mut Counter) {
39 fn tick_generic<C:?Sized+Counter>(c: &mut C) {
45 let mut c = preticked::<CCounter>();
47 assert_eq!(c.tick(), 5);