summaryrefslogtreecommitdiffstats
path: root/tests/ui/object-safety/object-safety-issue-22040.rs
blob: 1fc5c5442c21ba0120cefcbf198874f03d11bb24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Regression test for #22040.

use std::fmt::Debug;

trait Expr: Debug + PartialEq {
    fn print_element_count(&self);
}

//#[derive(PartialEq)]
#[derive(Debug)]
struct SExpr<'x> {
    elements: Vec<Box<dyn Expr + 'x>>,
    //~^ ERROR E0038
}

impl<'x> PartialEq for SExpr<'x> {
    fn eq(&self, other:&SExpr<'x>) -> bool {
        println!("L1: {} L2: {}", self.elements.len(), other.elements.len());

        let result = self.elements.len() == other.elements.len();

        println!("Got compare {}", result);
        return result;
    }
}

impl <'x> SExpr<'x> {
    fn new() -> SExpr<'x> { return SExpr{elements: Vec::new(),}; }
}

impl <'x> Expr for SExpr<'x> {
    fn print_element_count(&self) {
        println!("element count: {}", self.elements.len());
    }
}

fn main() {
    let a: Box<dyn Expr> = Box::new(SExpr::new());
    let b: Box<dyn Expr> = Box::new(SExpr::new());

    // assert_eq!(a , b);
}