File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -1975,6 +1975,13 @@ fn lint_search_is_some<'a, 'tcx>(
1975
1975
) ;
1976
1976
let search_snippet = snippet ( cx, search_args[ 1 ] . span , ".." ) ;
1977
1977
if search_snippet. lines ( ) . count ( ) <= 1 {
1978
+ // suggest `any(|x| ..)` instead of `any(|&x| ..)` for `find(|&x| ..).is_some()`
1979
+ let any_search_snippet =
1980
+ if search_method == "find" && search_snippet. starts_with ( "|&" ) {
1981
+ Some ( search_snippet. replacen ( '&' , "" , 1 ) )
1982
+ } else {
1983
+ None
1984
+ } ;
1978
1985
// add note if not multi-line
1979
1986
span_note_and_lint (
1980
1987
cx,
@@ -1983,8 +1990,9 @@ fn lint_search_is_some<'a, 'tcx>(
1983
1990
& msg,
1984
1991
expr. span ,
1985
1992
& format ! (
1986
- "replace `{0}({1}).is_some()` with `any({1})`" ,
1987
- search_method, search_snippet
1993
+ "replace `{0}({1}).is_some()` with `any({2})`" ,
1994
+ search_method, search_snippet,
1995
+ any_search_snippet. as_ref( ) . map_or( & * search_snippet, String :: as_str)
1988
1996
) ,
1989
1997
) ;
1990
1998
} else {
You can’t perform that action at this time.
0 commit comments