aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/rust/execute/torture/issue-2236.rs
blob: 850b99718ef6fc4306440aa0c53c8b35136060d4 (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
// { dg-options "-w" }
#[lang = "sized"]
pub trait Sized {}

mod core {
    mod ops {
        #[lang = "deref"]
        trait Deref {
            type Target;
            fn deref(&self) -> &Self::Target;
        }

        impl<T> Deref for &T {
            type Target = T;

            fn deref(&self) -> &T {
                *self
            }
        }
    }
}

impl i32 {
    fn max(self, other: i32) -> i32 {
        if self > other {
            self
        } else {
            other
        }
    }
}

fn foo<T: core::ops::Deref<Target = i32>>(t: T) -> i32 {
    t.max(2)
}

fn main() -> i32 {
    let a: i32 = 1;
    foo(&a) - 2
}