]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/object-safety-issue-22040.rs
Auto merge of #22541 - Manishearth:rollup, r=Gankro
[rust.git] / src / test / compile-fail / object-safety-issue-22040.rs
1 // Copyright 2015 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 // Regression test for #22040.
12
13 use std::fmt::Debug;
14
15 trait Expr: Debug + PartialEq {
16     fn print_element_count(&self);
17 }
18
19 //#[derive(PartialEq)]
20 #[derive(Debug)]
21 struct SExpr<'x> {
22     elements: Vec<Box<Expr+ 'x>>,
23 }
24
25 impl<'x> PartialEq for SExpr<'x> {
26     fn eq(&self, other:&SExpr<'x>) -> bool {
27         println!("L1: {} L2: {}", self.elements.len(), other.elements.len());
28         let result = self.elements.len() == other.elements.len();
29
30         println!("Got compare {}", result);
31         return result;
32     }
33 }
34
35 impl <'x> SExpr<'x> {
36     fn new() -> SExpr<'x> { return SExpr{elements: Vec::new(),}; }
37 }
38
39 impl <'x> Expr for SExpr<'x> {
40     fn print_element_count(&self) {
41         println!("element count: {}", self.elements.len());
42     }
43 }
44
45 fn main() {
46     let a: Box<Expr> = Box::new(SExpr::new()); //~ ERROR trait `Expr` is not object-safe
47     let b: Box<Expr> = Box::new(SExpr::new()); //~ ERROR trait `Expr` is not object-safe
48
49     assert_eq!(a , b);
50 }