1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Elaborated version of the opening example from RFC 738. This failed
12 // to compile before variance because invariance of `Option` prevented
13 // us from approximating the lifetimes of `field1` and `field2` to a
14 // common intersection.
22 field2: Option<&'l i32>,
25 fn foo(field1: &i32, field2: Option<&i32>) -> i32 {
26 let list = List { field1: field1, field2: field2 };
27 *list.field1 + list.field2.cloned().unwrap_or(0)
34 assert_eq!(foo(&x, y.as_ref()), 25);
35 assert_eq!(foo(&x, z.as_ref()), 22);