|
| 1 | +//@ run-pass |
| 2 | +//@ needs-unwind |
| 3 | + |
| 4 | +#![feature(rust_preserve_none_cc)] |
| 5 | + |
| 6 | +struct CrateOf<'a> { |
| 7 | + mcintosh: f64, |
| 8 | + golden_delicious: u64, |
| 9 | + jonagold: Option<&'a u64>, |
| 10 | + rome: [u64; 12], |
| 11 | +} |
| 12 | + |
| 13 | +#[inline(never)] |
| 14 | +extern "rust-preserve-none" fn oven_explosion() { |
| 15 | + panic!("bad time"); |
| 16 | +} |
| 17 | + |
| 18 | +#[inline(never)] |
| 19 | +fn bite_into(yummy: u64) -> u64 { |
| 20 | + let did_it_actually = std::panic::catch_unwind(move || { |
| 21 | + oven_explosion() |
| 22 | + }); |
| 23 | + assert!(did_it_actually.is_err()); |
| 24 | + yummy - 25 |
| 25 | +} |
| 26 | + |
| 27 | +#[inline(never)] |
| 28 | +extern "rust-preserve-none" fn lotsa_apples( |
| 29 | + honeycrisp: u64, |
| 30 | + gala: u32, |
| 31 | + fuji: f64, |
| 32 | + granny_smith: &[u64], |
| 33 | + pink_lady: (), |
| 34 | + and_a: CrateOf<'static>, |
| 35 | + cosmic_crisp: u64, |
| 36 | + ambrosia: f64, |
| 37 | + winesap: &[u64], |
| 38 | +) -> (u64, f64, u64, u64) { |
| 39 | + assert_eq!(honeycrisp, 220); |
| 40 | + assert_eq!(gala, 140); |
| 41 | + assert_eq!(fuji, 210.54201234); |
| 42 | + assert_eq!(granny_smith, &[180, 210]); |
| 43 | + assert_eq!(pink_lady, ()); |
| 44 | + assert_eq!(and_a.mcintosh, 150.0); |
| 45 | + assert_eq!(and_a.golden_delicious, 185); |
| 46 | + assert_eq!(and_a.jonagold, None); // my scales can't weight these gargantuans. |
| 47 | + assert_eq!(and_a.rome, [180, 182, 184, 186, 188, 190, 192, 194, 196, 198, 200, 202]); |
| 48 | + assert_eq!(cosmic_crisp, 270); |
| 49 | + assert_eq!(ambrosia, 193.1); |
| 50 | + assert_eq!(winesap, &[]); |
| 51 | + (and_a.rome.iter().sum(), fuji + ambrosia, cosmic_crisp - honeycrisp, bite_into(and_a.golden_delicious)) |
| 52 | +} |
| 53 | + |
| 54 | +fn main() { |
| 55 | + let pie = lotsa_apples(220, 140, 210.54201234, &[180, 210], (), CrateOf { |
| 56 | + mcintosh: 150.0, |
| 57 | + golden_delicious: 185, |
| 58 | + jonagold: None, |
| 59 | + rome: [180, 182, 184, 186, 188, 190, 192, 194, 196, 198, 200, 202] |
| 60 | + }, 270, 193.1, &[]); |
| 61 | + assert_eq!(pie, (2292, 403.64201234, 50, 160)); |
| 62 | +} |
0 commit comments