From cc73abf72c46d9f13a176d93d1d38f3a72d638e3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 18 Jun 2021 23:33:01 +0300 Subject: minor: use minicore --- .../handlers/missing_ok_or_some_in_tail_expr.rs | 76 ++-------------------- 1 file changed, 6 insertions(+), 70 deletions(-) (limited to 'crates/ide_diagnostics/src/handlers') diff --git a/crates/ide_diagnostics/src/handlers/missing_ok_or_some_in_tail_expr.rs b/crates/ide_diagnostics/src/handlers/missing_ok_or_some_in_tail_expr.rs index 63de54570..c0edcd7d3 100644 --- a/crates/ide_diagnostics/src/handlers/missing_ok_or_some_in_tail_expr.rs +++ b/crates/ide_diagnostics/src/handlers/missing_ok_or_some_in_tail_expr.rs @@ -49,26 +49,15 @@ mod tests { fn test_wrap_return_type_option() { check_fix( r#" -//- /main.rs crate:main deps:core -use core::option::Option::{self, Some, None}; - +//- minicore: option, result fn div(x: i32, y: i32) -> Option { if y == 0 { return None; } x / y$0 } -//- /core/lib.rs crate:core -pub mod result { - pub enum Result { Ok(T), Err(E) } -} -pub mod option { - pub enum Option { Some(T), None } -} "#, r#" -use core::option::Option::{self, Some, None}; - fn div(x: i32, y: i32) -> Option { if y == 0 { return None; @@ -83,26 +72,15 @@ fn div(x: i32, y: i32) -> Option { fn test_wrap_return_type() { check_fix( r#" -//- /main.rs crate:main deps:core -use core::result::Result::{self, Ok, Err}; - +//- minicore: option, result fn div(x: i32, y: i32) -> Result { if y == 0 { return Err(()); } x / y$0 } -//- /core/lib.rs crate:core -pub mod result { - pub enum Result { Ok(T), Err(E) } -} -pub mod option { - pub enum Option { Some(T), None } -} "#, r#" -use core::result::Result::{self, Ok, Err}; - fn div(x: i32, y: i32) -> Result { if y == 0 { return Err(()); @@ -117,26 +95,15 @@ fn div(x: i32, y: i32) -> Result { fn test_wrap_return_type_handles_generic_functions() { check_fix( r#" -//- /main.rs crate:main deps:core -use core::result::Result::{self, Ok, Err}; - +//- minicore: option, result fn div(x: T) -> Result { if x == 0 { return Err(7); } $0x } -//- /core/lib.rs crate:core -pub mod result { - pub enum Result { Ok(T), Err(E) } -} -pub mod option { - pub enum Option { Some(T), None } -} "#, r#" -use core::result::Result::{self, Ok, Err}; - fn div(x: T) -> Result { if x == 0 { return Err(7); @@ -151,9 +118,7 @@ fn div(x: T) -> Result { fn test_wrap_return_type_handles_type_aliases() { check_fix( r#" -//- /main.rs crate:main deps:core -use core::result::Result::{self, Ok, Err}; - +//- minicore: option, result type MyResult = Result; fn div(x: i32, y: i32) -> MyResult { @@ -162,17 +127,8 @@ fn div(x: i32, y: i32) -> MyResult { } x $0/ y } -//- /core/lib.rs crate:core -pub mod result { - pub enum Result { Ok(T), Err(E) } -} -pub mod option { - pub enum Option { Some(T), None } -} "#, r#" -use core::result::Result::{self, Ok, Err}; - type MyResult = Result; fn div(x: i32, y: i32) -> MyResult { @@ -189,18 +145,8 @@ fn div(x: i32, y: i32) -> MyResult { fn test_wrap_return_type_not_applicable_when_expr_type_does_not_match_ok_type() { check_diagnostics( r#" -//- /main.rs crate:main deps:core -use core::result::Result::{self, Ok, Err}; - +//- minicore: option, result fn foo() -> Result<(), i32> { 0 } - -//- /core/lib.rs crate:core -pub mod result { - pub enum Result { Ok(T), Err(E) } -} -pub mod option { - pub enum Option { Some(T), None } -} "#, ); } @@ -209,20 +155,10 @@ pub mod option { fn test_wrap_return_type_not_applicable_when_return_type_is_not_result_or_option() { check_diagnostics( r#" -//- /main.rs crate:main deps:core -use core::result::Result::{self, Ok, Err}; - +//- minicore: option, result enum SomeOtherEnum { Ok(i32), Err(String) } fn foo() -> SomeOtherEnum { 0 } - -//- /core/lib.rs crate:core -pub mod result { - pub enum Result { Ok(T), Err(E) } -} -pub mod option { - pub enum Option { Some(T), None } -} "#, ); } -- cgit v1.2.3 From 90da9fc9b302de46097065f0d6428ad33c292217 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 18 Jun 2021 23:48:18 +0300 Subject: minor: use minicore --- .../replace_filter_map_next_with_find_map.rs | 86 +++++----------------- 1 file changed, 19 insertions(+), 67 deletions(-) (limited to 'crates/ide_diagnostics/src/handlers') diff --git a/crates/ide_diagnostics/src/handlers/replace_filter_map_next_with_find_map.rs b/crates/ide_diagnostics/src/handlers/replace_filter_map_next_with_find_map.rs index cd87a10bb..839ceac03 100644 --- a/crates/ide_diagnostics/src/handlers/replace_filter_map_next_with_find_map.rs +++ b/crates/ide_diagnostics/src/handlers/replace_filter_map_next_with_find_map.rs @@ -55,44 +55,16 @@ fn fixes( #[cfg(test)] mod tests { - use crate::tests::check_fix; - - // Register the required standard library types to make the tests work - #[track_caller] - fn check_diagnostics(ra_fixture: &str) { - let prefix = r#" -//- /main.rs crate:main deps:core -use core::iter::Iterator; -use core::option::Option::{self, Some, None}; -"#; - let suffix = r#" -//- /core/lib.rs crate:core -pub mod option { - pub enum Option { Some(T), None } -} -pub mod iter { - pub trait Iterator { - type Item; - fn filter_map(self, f: F) -> FilterMap where F: FnMut(Self::Item) -> Option { FilterMap } - fn next(&mut self) -> Option; - } - pub struct FilterMap {} - impl Iterator for FilterMap { - type Item = i32; - fn next(&mut self) -> i32 { 7 } - } -} -"#; - crate::tests::check_diagnostics(&format!("{}{}{}", prefix, ra_fixture, suffix)) - } + use crate::tests::{check_diagnostics, check_fix}; #[test] fn replace_filter_map_next_with_find_map2() { check_diagnostics( r#" - fn foo() { - let m = [1, 2, 3].iter().filter_map(|x| Some(92)).next(); - } //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 💡 weak: replace filter_map(..).next() with find_map(..) +//- minicore: iterators +fn foo() { + let m = core::iter::repeat(()).filter_map(|()| Some(92)).next(); +} //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 💡 weak: replace filter_map(..).next() with find_map(..) "#, ); } @@ -101,11 +73,11 @@ pub mod iter { fn replace_filter_map_next_with_find_map_no_diagnostic_without_next() { check_diagnostics( r#" +//- minicore: iterators fn foo() { - let m = [1, 2, 3] - .iter() - .filter_map(|x| Some(92)) - .len(); + let m = core::iter::repeat(()) + .filter_map(|()| Some(92)) + .count(); } "#, ); @@ -115,12 +87,12 @@ fn foo() { fn replace_filter_map_next_with_find_map_no_diagnostic_with_intervening_methods() { check_diagnostics( r#" +//- minicore: iterators fn foo() { - let m = [1, 2, 3] - .iter() - .filter_map(|x| Some(92)) + let m = core::iter::repeat(()) + .filter_map(|()| Some(92)) .map(|x| x + 2) - .len(); + .next(); } "#, ); @@ -130,10 +102,10 @@ fn foo() { fn replace_filter_map_next_with_find_map_no_diagnostic_if_not_in_chain() { check_diagnostics( r#" +//- minicore: iterators fn foo() { - let m = [1, 2, 3] - .iter() - .filter_map(|x| Some(92)); + let m = core::iter::repeat(()) + .filter_map(|()| Some(92)); let n = m.next(); } "#, @@ -144,34 +116,14 @@ fn foo() { fn replace_with_wind_map() { check_fix( r#" -//- /main.rs crate:main deps:core -use core::iter::Iterator; -use core::option::Option::{self, Some, None}; +//- minicore: iterators fn foo() { - let m = [1, 2, 3].iter().$0filter_map(|x| Some(92)).next(); -} -//- /core/lib.rs crate:core -pub mod option { - pub enum Option { Some(T), None } -} -pub mod iter { - pub trait Iterator { - type Item; - fn filter_map(self, f: F) -> FilterMap where F: FnMut(Self::Item) -> Option { FilterMap } - fn next(&mut self) -> Option; - } - pub struct FilterMap {} - impl Iterator for FilterMap { - type Item = i32; - fn next(&mut self) -> i32 { 7 } - } + let m = core::iter::repeat(()).$0filter_map(|()| Some(92)).next(); } "#, r#" -use core::iter::Iterator; -use core::option::Option::{self, Some, None}; fn foo() { - let m = [1, 2, 3].iter().find_map(|x| Some(92)); + let m = core::iter::repeat(()).find_map(|()| Some(92)); } "#, ) -- cgit v1.2.3