2019-09-20 06:53:58 +00:00
|
|
|
// run-rustfix
|
|
|
|
|
2020-05-17 15:36:26 +00:00
|
|
|
#![deny(clippy::useless_conversion)]
|
2020-11-23 12:51:04 +00:00
|
|
|
#![allow(clippy::unnecessary_wraps)]
|
2019-09-20 06:53:58 +00:00
|
|
|
|
|
|
|
fn test_generic<T: Copy>(val: T) -> T {
|
|
|
|
let _ = val;
|
|
|
|
val
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
Ok(Ok(()))
|
|
|
|
}??;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_issue_3913() -> Result<(), std::io::Error> {
|
|
|
|
use std::fs;
|
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
let path = Path::new(".");
|
|
|
|
for _ in fs::read_dir(path)? {}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-07-26 19:07:07 +00:00
|
|
|
fn test_issue_5833() -> Result<(), ()> {
|
|
|
|
let text = "foo\r\nbar\n\nbaz\n";
|
|
|
|
let lines = text.lines();
|
|
|
|
if Some("ok") == lines.into_iter().next() {}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-09-20 06:53:58 +00:00
|
|
|
fn main() {
|
|
|
|
test_generic(10i32);
|
|
|
|
test_generic2::<i32, i32>(10i32);
|
|
|
|
test_questionmark().unwrap();
|
|
|
|
test_issue_3913().unwrap();
|
2020-07-26 19:07:07 +00:00
|
|
|
test_issue_5833().unwrap();
|
2019-09-20 06:53:58 +00:00
|
|
|
|
|
|
|
let _: String = "foo".into();
|
|
|
|
let _: String = From::from("foo");
|
|
|
|
let _ = String::from("foo");
|
2020-05-17 15:36:26 +00:00
|
|
|
#[allow(clippy::useless_conversion)]
|
2019-09-20 06:53:58 +00:00
|
|
|
{
|
|
|
|
let _: String = "foo".into();
|
|
|
|
let _ = String::from("foo");
|
|
|
|
let _ = "".lines().into_iter();
|
|
|
|
}
|
|
|
|
|
|
|
|
let _: String = "foo".to_string();
|
|
|
|
let _: String = "foo".to_string();
|
|
|
|
let _ = "foo".to_string();
|
|
|
|
let _ = format!("A: {:04}", 123);
|
|
|
|
let _ = "".lines();
|
|
|
|
let _ = vec![1, 2, 3].into_iter();
|
|
|
|
let _: String = format!("Hello {}", "world");
|
2020-08-28 14:10:16 +00:00
|
|
|
|
2021-10-17 10:04:01 +00:00
|
|
|
// keep parentheses around `a + b` for suggestion (see #4750)
|
2020-08-28 14:10:16 +00:00
|
|
|
let a: i32 = 1;
|
|
|
|
let b: i32 = 1;
|
|
|
|
let _ = (a + b) * 3;
|
2021-05-20 10:30:31 +00:00
|
|
|
|
|
|
|
// see #7205
|
|
|
|
let s: Foo<'a'> = Foo;
|
|
|
|
let _: Foo<'b'> = s.into();
|
|
|
|
let s2: Foo<'a'> = Foo;
|
|
|
|
let _: Foo<'a'> = s2;
|
|
|
|
let s3: Foo<'a'> = Foo;
|
|
|
|
let _ = s3;
|
|
|
|
let s4: Foo<'a'> = Foo;
|
|
|
|
let _ = vec![s4, s4, s4].into_iter();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
struct Foo<const C: char>;
|
|
|
|
|
|
|
|
impl From<Foo<'a'>> for Foo<'b'> {
|
|
|
|
fn from(_s: Foo<'a'>) -> Self {
|
|
|
|
Foo
|
|
|
|
}
|
2019-09-20 06:53:58 +00:00
|
|
|
}
|