]> git.lizzy.rs Git - rust.git/blob - src/test/ui/object-safety/object-safety-issue-22040.rs
Merge commit '91496c2ac6abf6454c413bb23e8becf6b6dc20ea' into clippyup
[rust.git] / src / test / ui / object-safety / object-safety-issue-22040.rs
1 // Regression test for #22040.
2
3 use std::fmt::Debug;
4
5 trait Expr: Debug + PartialEq {
6     fn print_element_count(&self);
7 }
8
9 //#[derive(PartialEq)]
10 #[derive(Debug)]
11 struct SExpr<'x> {
12     elements: Vec<Box<dyn Expr + 'x>>,
13     //~^ ERROR E0038
14 }
15
16 impl<'x> PartialEq for SExpr<'x> {
17     fn eq(&self, other:&SExpr<'x>) -> bool {
18         println!("L1: {} L2: {}", self.elements.len(), other.elements.len());
19
20         let result = self.elements.len() == other.elements.len();
21
22         println!("Got compare {}", result);
23         return result;
24     }
25 }
26
27 impl <'x> SExpr<'x> {
28     fn new() -> SExpr<'x> { return SExpr{elements: Vec::new(),}; }
29 }
30
31 impl <'x> Expr for SExpr<'x> {
32     fn print_element_count(&self) {
33         println!("element count: {}", self.elements.len());
34     }
35 }
36
37 fn main() {
38     let a: Box<dyn Expr> = Box::new(SExpr::new());
39     let b: Box<dyn Expr> = Box::new(SExpr::new());
40
41     // assert_eq!(a , b);
42 }