2013-09-02 08:33:17 -05:00
|
|
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
/*
|
|
|
|
# if b { x } else { y } requires identical types for x and y
|
|
|
|
*/
|
|
|
|
|
|
|
|
fn print1(b: bool, s1: &str, s2: &str) {
|
2014-01-09 04:06:55 -06:00
|
|
|
println!("{}", if b { s1 } else { s2 });
|
2013-09-02 08:33:17 -05:00
|
|
|
}
|
|
|
|
fn print2<'a, 'b>(b: bool, s1: &'a str, s2: &'b str) {
|
2014-01-09 04:06:55 -06:00
|
|
|
println!("{}", if b { s1 } else { s2 });
|
2013-09-02 08:33:17 -05:00
|
|
|
}
|
|
|
|
fn print3(b: bool, s1: &str, s2: &str) {
|
|
|
|
let mut s: &str;
|
|
|
|
if b { s = s1; } else { s = s2; }
|
2014-01-09 04:06:55 -06:00
|
|
|
println!("{}", s);
|
2013-09-02 08:33:17 -05:00
|
|
|
}
|
|
|
|
fn print4<'a, 'b>(b: bool, s1: &'a str, s2: &'b str) {
|
|
|
|
let mut s: &str;
|
|
|
|
if b { s = s1; } else { s = s2; }
|
2014-01-09 04:06:55 -06:00
|
|
|
println!("{}", s);
|
2013-09-02 08:33:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {}
|