2017-02-04 22:41:09 -06:00
|
|
|
#![deny(identity_conversion)]
|
|
|
|
|
|
|
|
fn test_generic<T: Copy>(val: T) -> T {
|
|
|
|
let _ = T::from(val);
|
|
|
|
val.into()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_generic2<T: Copy + Into<i32> + Into<U>, U: From<T>>(val: T) {
|
|
|
|
// ok
|
|
|
|
let _: i32 = val.into();
|
|
|
|
let _: U = val.into();
|
|
|
|
let _ = U::from(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_questionmark() -> Result<(), ()> {
|
|
|
|
{
|
|
|
|
let _: i32 = 0i32.into();
|
|
|
|
Ok(Ok(()))
|
|
|
|
}??;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
test_generic(10i32);
|
|
|
|
test_generic2::<i32, i32>(10i32);
|
|
|
|
test_questionmark().unwrap();
|
|
|
|
|
|
|
|
let _: String = "foo".into();
|
|
|
|
let _: String = From::from("foo");
|
|
|
|
let _ = String::from("foo");
|
2017-10-04 08:26:41 -05:00
|
|
|
#[allow(identity_conversion)]
|
|
|
|
{
|
|
|
|
let _: String = "foo".into();
|
|
|
|
let _ = String::from("foo");
|
|
|
|
}
|
2017-02-04 22:41:09 -06:00
|
|
|
|
|
|
|
let _: String = "foo".to_string().into();
|
|
|
|
let _: String = From::from("foo".to_string());
|
|
|
|
let _ = String::from("foo".to_string());
|
|
|
|
}
|