mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-30 02:33:55 +00:00
26 lines
435 B
Rust
26 lines
435 B
Rust
|
fn shorten_lifetime<'a, 'b, 'min>(a: &'a i32, b: &'b i32) -> &'min i32
|
||
|
where
|
||
|
'a: 'min,
|
||
|
'b: 'min,
|
||
|
{
|
||
|
if *a < *b {
|
||
|
&a
|
||
|
} else {
|
||
|
&b
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
|
let promoted_fn_item_ref = &shorten_lifetime;
|
||
|
|
||
|
let a = &5;
|
||
|
let ptr = {
|
||
|
let l = 3;
|
||
|
let b = &l; //~ ERROR does not live long enough
|
||
|
let c = promoted_fn_item_ref(a, b);
|
||
|
c
|
||
|
};
|
||
|
|
||
|
println!("ptr = {:?}", ptr);
|
||
|
}
|