2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2018-09-25 16:51:35 -05:00
|
|
|
#![allow(unreachable_code)]
|
2014-07-29 14:35:38 -05:00
|
|
|
|
2015-01-28 07:34:18 -06:00
|
|
|
#[derive(PartialEq, Debug)]
|
2014-07-29 14:35:38 -05:00
|
|
|
struct Bar {
|
2015-03-25 19:06:52 -05:00
|
|
|
x: isize
|
2014-07-29 14:35:38 -05:00
|
|
|
}
|
|
|
|
impl Drop for Bar {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
assert_eq!(self.x, 22);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 07:34:18 -06:00
|
|
|
#[derive(PartialEq, Debug)]
|
2014-07-29 14:35:38 -05:00
|
|
|
struct Foo {
|
|
|
|
x: Bar,
|
2015-03-25 19:06:52 -05:00
|
|
|
a: isize
|
2014-07-29 14:35:38 -05:00
|
|
|
}
|
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
fn foo() -> Result<Foo, isize> {
|
2017-03-18 11:24:42 -05:00
|
|
|
return Ok(Foo {
|
2014-07-29 14:35:38 -05:00
|
|
|
x: Bar { x: 22 },
|
|
|
|
a: return Err(32)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
fn baz() -> Result<Foo, isize> {
|
2017-03-18 11:24:42 -05:00
|
|
|
Ok(Foo {
|
2014-07-29 14:35:38 -05:00
|
|
|
x: Bar { x: 22 },
|
|
|
|
a: return Err(32)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// explicit immediate return
|
2015-03-25 19:06:52 -05:00
|
|
|
fn aa() -> isize {
|
2014-07-29 14:35:38 -05:00
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
// implicit immediate return
|
2015-03-25 19:06:52 -05:00
|
|
|
fn bb() -> isize {
|
2014-07-29 14:35:38 -05:00
|
|
|
3
|
|
|
|
}
|
|
|
|
|
|
|
|
// implicit outptr return
|
2015-03-25 19:06:52 -05:00
|
|
|
fn cc() -> Result<isize, isize> {
|
2014-07-29 14:35:38 -05:00
|
|
|
Ok(3)
|
|
|
|
}
|
|
|
|
|
|
|
|
// explicit outptr return
|
2015-03-25 19:06:52 -05:00
|
|
|
fn dd() -> Result<isize, isize> {
|
2014-07-29 14:35:38 -05:00
|
|
|
return Ok(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
trait A {
|
2015-03-25 19:06:52 -05:00
|
|
|
fn aaa(&self) -> isize {
|
2014-07-29 14:35:38 -05:00
|
|
|
3
|
|
|
|
}
|
2015-03-25 19:06:52 -05:00
|
|
|
fn bbb(&self) -> isize {
|
2014-07-29 14:35:38 -05:00
|
|
|
return 3;
|
|
|
|
}
|
2015-03-25 19:06:52 -05:00
|
|
|
fn ccc(&self) -> Result<isize, isize> {
|
2014-07-29 14:35:38 -05:00
|
|
|
Ok(3)
|
|
|
|
}
|
2015-03-25 19:06:52 -05:00
|
|
|
fn ddd(&self) -> Result<isize, isize> {
|
2014-07-29 14:35:38 -05:00
|
|
|
return Ok(3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
impl A for isize {}
|
2014-07-29 14:35:38 -05:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2022-07-06 21:36:10 -05:00
|
|
|
let i = Box::new(32isize) as Box<dyn A>;
|
2014-07-29 14:35:38 -05:00
|
|
|
assert_eq!(i.aaa(), 3);
|
2022-07-06 21:36:10 -05:00
|
|
|
let i = Box::new(32isize) as Box<dyn A>;
|
2014-07-29 14:35:38 -05:00
|
|
|
assert_eq!(i.bbb(), 3);
|
2022-07-06 21:36:10 -05:00
|
|
|
let i = Box::new(32isize) as Box<dyn A>;
|
2014-07-29 14:35:38 -05:00
|
|
|
assert_eq!(i.ccc().unwrap(), 3);
|
2022-07-06 21:36:10 -05:00
|
|
|
let i = Box::new(32isize) as Box<dyn A>;
|
2014-07-29 14:35:38 -05:00
|
|
|
assert_eq!(i.ddd().unwrap(), 3);
|
|
|
|
}
|