@@ -13,6 +13,7 @@ mod missing_ok_or_some_in_tail_expr;
1313mod missing_unsafe;
1414mod no_such_field;
1515mod remove_this_semicolon;
16+ mod replace_filter_map_next_with_find_map;
1617mod unimplemented_builtin_macro;
1718mod unresolved_extern_crate;
1819mod unresolved_import;
@@ -167,9 +168,6 @@ pub(crate) fn diagnostics(
167168 . on :: < hir:: diagnostics:: IncorrectCase , _ > ( |d| {
168169 res. borrow_mut ( ) . push ( warning_with_fix ( d, & sema, resolve) ) ;
169170 } )
170- . on :: < hir:: diagnostics:: ReplaceFilterMapNextWithFindMap , _ > ( |d| {
171- res. borrow_mut ( ) . push ( warning_with_fix ( d, & sema, resolve) ) ;
172- } )
173171 . on :: < UnlinkedFile , _ > ( |d| {
174172 // Limit diagnostic to the first few characters in the file. This matches how VS Code
175173 // renders it with the full span, but on other editors, and is less invasive.
@@ -225,6 +223,7 @@ pub(crate) fn diagnostics(
225223 AnyDiagnostic :: MissingUnsafe ( d) => missing_unsafe:: missing_unsafe ( & ctx, & d) ,
226224 AnyDiagnostic :: NoSuchField ( d) => no_such_field:: no_such_field ( & ctx, & d) ,
227225 AnyDiagnostic :: RemoveThisSemicolon ( d) => remove_this_semicolon:: remove_this_semicolon ( & ctx, & d) ,
226+ AnyDiagnostic :: ReplaceFilterMapNextWithFindMap ( d) => replace_filter_map_next_with_find_map:: replace_filter_map_next_with_find_map ( & ctx, & d) ,
228227 AnyDiagnostic :: UnimplementedBuiltinMacro ( d) => unimplemented_builtin_macro:: unimplemented_builtin_macro ( & ctx, & d) ,
229228 AnyDiagnostic :: UnresolvedExternCrate ( d) => unresolved_extern_crate:: unresolved_extern_crate ( & ctx, & d) ,
230229 AnyDiagnostic :: UnresolvedImport ( d) => unresolved_import:: unresolved_import ( & ctx, & d) ,
@@ -672,89 +671,6 @@ mod foo;
672671 ) ;
673672 }
674673
675- // Register the required standard library types to make the tests work
676- fn add_filter_map_with_find_next_boilerplate ( body : & str ) -> String {
677- let prefix = r#"
678- //- /main.rs crate:main deps:core
679- use core::iter::Iterator;
680- use core::option::Option::{self, Some, None};
681- "# ;
682- let suffix = r#"
683- //- /core/lib.rs crate:core
684- pub mod option {
685- pub enum Option<T> { Some(T), None }
686- }
687- pub mod iter {
688- pub trait Iterator {
689- type Item;
690- fn filter_map<B, F>(self, f: F) -> FilterMap where F: FnMut(Self::Item) -> Option<B> { FilterMap }
691- fn next(&mut self) -> Option<Self::Item>;
692- }
693- pub struct FilterMap {}
694- impl Iterator for FilterMap {
695- type Item = i32;
696- fn next(&mut self) -> i32 { 7 }
697- }
698- }
699- "# ;
700- format ! ( "{}{}{}" , prefix, body, suffix)
701- }
702-
703- #[ test]
704- fn replace_filter_map_next_with_find_map2 ( ) {
705- check_diagnostics ( & add_filter_map_with_find_next_boilerplate (
706- r#"
707- fn foo() {
708- let m = [1, 2, 3].iter().filter_map(|x| if *x == 2 { Some (4) } else { None }).next();
709- //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ replace filter_map(..).next() with find_map(..)
710- }
711- "# ,
712- ) ) ;
713- }
714-
715- #[ test]
716- fn replace_filter_map_next_with_find_map_no_diagnostic_without_next ( ) {
717- check_diagnostics ( & add_filter_map_with_find_next_boilerplate (
718- r#"
719- fn foo() {
720- let m = [1, 2, 3]
721- .iter()
722- .filter_map(|x| if *x == 2 { Some (4) } else { None })
723- .len();
724- }
725- "# ,
726- ) ) ;
727- }
728-
729- #[ test]
730- fn replace_filter_map_next_with_find_map_no_diagnostic_with_intervening_methods ( ) {
731- check_diagnostics ( & add_filter_map_with_find_next_boilerplate (
732- r#"
733- fn foo() {
734- let m = [1, 2, 3]
735- .iter()
736- .filter_map(|x| if *x == 2 { Some (4) } else { None })
737- .map(|x| x + 2)
738- .len();
739- }
740- "# ,
741- ) ) ;
742- }
743-
744- #[ test]
745- fn replace_filter_map_next_with_find_map_no_diagnostic_if_not_in_chain ( ) {
746- check_diagnostics ( & add_filter_map_with_find_next_boilerplate (
747- r#"
748- fn foo() {
749- let m = [1, 2, 3]
750- .iter()
751- .filter_map(|x| if *x == 2 { Some (4) } else { None });
752- let n = m.next();
753- }
754- "# ,
755- ) ) ;
756- }
757-
758674 #[ test]
759675 fn missing_record_pat_field_no_diagnostic_if_not_exhaustive ( ) {
760676 check_diagnostics (
0 commit comments