]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/regions-trait-1.rs
New upstream version 1.24.1+dfsg1
[rustc.git] / src / test / compile-fail / regions-trait-1.rs
1 // Copyright 2012 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.
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
11 #![feature(box_syntax)]
12
13 struct ctxt { v: usize }
14
15 trait get_ctxt {
16 // Here the `&` is bound in the method definition:
17 fn get_ctxt(&self) -> &ctxt;
18 }
19
20 struct has_ctxt<'a> { c: &'a ctxt }
21
22 impl<'a> get_ctxt for has_ctxt<'a> {
23
24 // Here an error occurs because we used `&self` but
25 // the definition used `&`:
26 fn get_ctxt(&self) -> &'a ctxt { //~ ERROR method not compatible with trait
27 self.c
28 }
29
30 }
31
32 fn get_v(gc: Box<get_ctxt>) -> usize {
33 gc.get_ctxt().v
34 }
35
36 fn main() {
37 let ctxt = ctxt { v: 22 };
38 let hc = has_ctxt { c: &ctxt };
39 assert_eq!(get_v(box hc as Box<get_ctxt>), 22);
40 }