summaryrefslogtreecommitdiffstats
path: root/tests/ui/issues/issue-15763.rs
blob: ae0863615e2c7754fbb1d69ad47c4c671da9f393 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// run-pass
#![allow(unreachable_code)]

#[derive(PartialEq, Debug)]
struct Bar {
    x: isize
}
impl Drop for Bar {
    fn drop(&mut self) {
        assert_eq!(self.x, 22);
    }
}

#[derive(PartialEq, Debug)]
struct Foo {
    x: Bar,
    a: isize
}

fn foo() -> Result<Foo, isize> {
    return Ok(Foo {
        x: Bar { x: 22 },
        a: return Err(32)
    });
}

fn baz() -> Result<Foo, isize> {
    Ok(Foo {
        x: Bar { x: 22 },
        a: return Err(32)
    })
}

// explicit immediate return
fn aa() -> isize {
    return 3;
}

// implicit immediate return
fn bb() -> isize {
    3
}

// implicit outptr return
fn cc() -> Result<isize, isize> {
    Ok(3)
}

// explicit outptr return
fn dd() -> Result<isize, isize> {
    return Ok(3);
}

trait A {
    fn aaa(&self) -> isize {
        3
    }
    fn bbb(&self) -> isize {
        return 3;
    }
    fn ccc(&self) -> Result<isize, isize> {
        Ok(3)
    }
    fn ddd(&self) -> Result<isize, isize> {
        return Ok(3);
    }
}

impl A for isize {}

fn main() {
    assert_eq!(foo(), Err(32));
    assert_eq!(baz(), Err(32));

    assert_eq!(aa(), 3);
    assert_eq!(bb(), 3);
    assert_eq!(cc().unwrap(), 3);
    assert_eq!(dd().unwrap(), 3);

    let i = Box::new(32isize) as Box<dyn A>;
    assert_eq!(i.aaa(), 3);
    let i = Box::new(32isize) as Box<dyn A>;
    assert_eq!(i.bbb(), 3);
    let i = Box::new(32isize) as Box<dyn A>;
    assert_eq!(i.ccc().unwrap(), 3);
    let i = Box::new(32isize) as Box<dyn A>;
    assert_eq!(i.ddd().unwrap(), 3);
}