test formatting

This commit is contained in:
Grzegorz 2019-02-10 21:23:04 +01:00
parent 16881390e1
commit f7c0df9183
2 changed files with 44 additions and 36 deletions

View file

@ -28,7 +28,6 @@ fn main() {
// See #515
let a: Option<Box<::std::ops::Deref<Target = [i32]>>> =
Some(vec![1i32, 2]).map(|v| -> Box<::std::ops::Deref<Target = [i32]>> { Box::new(v) });
}
trait TestTrait {
@ -37,48 +36,58 @@ trait TestTrait {
}
struct TestStruct<'a> {
some_ref: &'a i32
some_ref: &'a i32,
}
impl<'a> TestStruct<'a> {
fn foo(self) -> bool { false }
unsafe fn foo_unsafe(self) -> bool { true }
fn foo(self) -> bool {
false
}
unsafe fn foo_unsafe(self) -> bool {
true
}
}
impl<'a> TestTrait for TestStruct<'a> {
fn trait_foo(self) -> bool { false }
fn trait_foo_ref(&self) -> bool { false }
fn trait_foo(self) -> bool {
false
}
fn trait_foo_ref(&self) -> bool {
false
}
}
impl<'a> std::ops::Deref for TestStruct<'a> {
type Target = char;
fn deref(&self) -> &char { &'a' }
fn deref(&self) -> &char {
&'a'
}
}
fn test_redundant_closures_containing_method_calls() {
let i = 10;
let e = Some(TestStruct{some_ref: &i}).map(|a| a.foo());
let e = Some(TestStruct{some_ref: &i}).map(TestStruct::foo);
let e = Some(TestStruct{some_ref: &i}).map(|a| a.trait_foo());
let e = Some(TestStruct{some_ref: &i}).map(|a| a.trait_foo_ref());
let e = Some(TestStruct{some_ref: &i}).map(TestTrait::trait_foo);
let e = Some(&mut vec!(1,2,3)).map(|v| v.clear());
let e = Some(&mut vec!(1,2,3)).map(std::vec::Vec::clear);
let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo());
let e = Some(TestStruct { some_ref: &i }).map(TestStruct::foo);
let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo());
let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo_ref());
let e = Some(TestStruct { some_ref: &i }).map(TestTrait::trait_foo);
let e = Some(&mut vec![1, 2, 3]).map(|v| v.clear());
let e = Some(&mut vec![1, 2, 3]).map(std::vec::Vec::clear);
unsafe {
let e = Some(TestStruct{some_ref: &i}).map(|a| a.foo_unsafe());
let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo_unsafe());
}
let e = Some("str").map(|s| s.to_string());
let e = Some("str").map(str::to_string);
let e = Some('a').map(|s| s.to_uppercase());
let e = Some('a').map(char::to_uppercase);
let e: std::vec::Vec<usize> = vec!('a','b','c').iter().map(|c| c.len_utf8()).collect();
let e: std::vec::Vec<char> = vec!('a','b','c').iter().map(|c| c.to_ascii_uppercase()).collect();
let e: std::vec::Vec<char> = vec!('a','b','c').iter().map(char::to_ascii_uppercase).collect();
let e: std::vec::Vec<usize> = vec!['a', 'b', 'c'].iter().map(|c| c.len_utf8()).collect();
let e: std::vec::Vec<char> = vec!['a', 'b', 'c'].iter().map(|c| c.to_ascii_uppercase()).collect();
let e: std::vec::Vec<char> = vec!['a', 'b', 'c'].iter().map(char::to_ascii_uppercase).collect();
let p = Some(PathBuf::new());
let e = p.as_ref().and_then(|s| s.to_str());
//let e = p.as_ref().and_then(std::path::Path::to_str);
let c = Some(TestStruct{some_ref: &i}).as_ref().map(|c| c.to_ascii_uppercase());
//let c = Some(TestStruct{some_ref: &i}).as_ref().map(char::to_ascii_uppercase);
let c = Some(TestStruct { some_ref: &i })
.as_ref()
.map(|c| c.to_ascii_uppercase());
}
fn meta<F>(f: F)
@ -114,4 +123,3 @@ fn divergent(_: u8) -> ! {
fn generic<T>(_: T) -> u8 {
0
}

View file

@ -33,40 +33,40 @@ LL | let e = Some(1u8).map(|a| generic(a));
| ^^^^^^^^^^^^^^ help: remove closure as shown: `generic`
error: redundant closure found
--> $DIR/eta.rs:60:48
--> $DIR/eta.rs:69:51
|
LL | let e = Some(TestStruct{some_ref: &i}).map(|a| a.foo());
| ^^^^^^^^^^^ help: remove closure as shown: `TestStruct::foo`
LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo());
| ^^^^^^^^^^^ help: remove closure as shown: `TestStruct::foo`
error: redundant closure found
--> $DIR/eta.rs:62:48
--> $DIR/eta.rs:71:51
|
LL | let e = Some(TestStruct{some_ref: &i}).map(|a| a.trait_foo());
| ^^^^^^^^^^^^^^^^^ help: remove closure as shown: `TestTrait::trait_foo`
LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo());
| ^^^^^^^^^^^^^^^^^ help: remove closure as shown: `TestTrait::trait_foo`
error: redundant closure found
--> $DIR/eta.rs:65:40
--> $DIR/eta.rs:74:42
|
LL | let e = Some(&mut vec!(1,2,3)).map(|v| v.clear());
| ^^^^^^^^^^^^^ help: remove closure as shown: `std::vec::Vec::clear`
LL | let e = Some(&mut vec![1, 2, 3]).map(|v| v.clear());
| ^^^^^^^^^^^^^ help: remove closure as shown: `std::vec::Vec::clear`
error: redundant closure found
--> $DIR/eta.rs:70:29
--> $DIR/eta.rs:79:29
|
LL | let e = Some("str").map(|s| s.to_string());
| ^^^^^^^^^^^^^^^^^ help: remove closure as shown: `std::string::ToString::to_string`
error: redundant closure found
--> $DIR/eta.rs:72:27
--> $DIR/eta.rs:81:27
|
LL | let e = Some('a').map(|s| s.to_uppercase());
| ^^^^^^^^^^^^^^^^^^^^ help: remove closure as shown: `char::to_uppercase`
error: redundant closure found
--> $DIR/eta.rs:75:63
--> $DIR/eta.rs:84:65
|
LL | let e: std::vec::Vec<char> = vec!('a','b','c').iter().map(|c| c.to_ascii_uppercase()).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove closure as shown: `char::to_ascii_uppercase`
LL | let e: std::vec::Vec<char> = vec!['a', 'b', 'c'].iter().map(|c| c.to_ascii_uppercase()).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove closure as shown: `char::to_ascii_uppercase`
error: aborting due to 11 previous errors