@@ -140,6 +140,7 @@ use clippy_utils::macros::FormatArgsStorage;
140140use clippy_utils:: ty:: { contains_ty_adt_constructor_opaque, implements_trait, is_copy, is_type_diagnostic_item} ;
141141use clippy_utils:: { contains_return, is_bool, is_trait_method, iter_input_pats, peel_blocks, return_ty} ;
142142pub use path_ends_with_ext:: DEFAULT_ALLOWED_DOTFILES ;
143+ use rustc_ast:: ast;
143144use rustc_data_structures:: fx:: FxHashSet ;
144145use rustc_hir as hir;
145146use rustc_hir:: { Expr , ExprKind , Node , Stmt , StmtKind , TraitItem , TraitItemKind } ;
@@ -3889,6 +3890,8 @@ declare_clippy_lint! {
38893890 /// # let result: Result<usize, ()> = Ok(1);
38903891 /// option.map(|a| a > 10).unwrap_or_default();
38913892 /// result.map(|a| a > 10).unwrap_or_default();
3893+ /// option.map_or(false, |a| a > 10);
3894+ /// result.map_or(false, |a| a > 10);
38923895 /// ```
38933896 /// Use instead:
38943897 /// ```no_run
@@ -3900,7 +3903,7 @@ declare_clippy_lint! {
39003903 #[ clippy:: version = "1.77.0" ]
39013904 pub MANUAL_IS_VARIANT_AND ,
39023905 pedantic,
3903- "using `.map(f).unwrap_or_default()`, which is more succinctly expressed as `is_some_and(f)` or `is_ok_and(f)`"
3906+ "calling `.map(f).unwrap_or_default()` or `.map_or(false, f)` instead of `is_some_and(f)` or `is_ok_and(f)`"
39043907}
39053908
39063909declare_clippy_lint ! {
@@ -4839,6 +4842,11 @@ impl Methods {
48394842 option_map_or_none:: check ( cx, expr, recv, def, map) ;
48404843 manual_ok_or:: check ( cx, expr, recv, def, map) ;
48414844 option_map_or_err_ok:: check ( cx, expr, recv, def, map) ;
4845+ if let ExprKind :: Lit ( lit) = def. kind
4846+ && lit. node == ast:: LitKind :: Bool ( false )
4847+ {
4848+ manual_is_variant_and:: check ( cx, expr, recv, map, span, & self . msrv , true ) ;
4849+ }
48424850 } ,
48434851 ( "map_or_else" , [ def, map] ) => {
48444852 result_map_or_else_none:: check ( cx, expr, recv, def, map) ;
@@ -5052,7 +5060,7 @@ impl Methods {
50525060 } ,
50535061 ( "unwrap_or_default" , [ ] ) => {
50545062 if let Some ( ( "map" , m_recv, [ arg] , span, _) ) = method_call ( recv) {
5055- manual_is_variant_and:: check ( cx, expr, m_recv, arg, span, & self . msrv ) ;
5063+ manual_is_variant_and:: check ( cx, expr, m_recv, arg, span, & self . msrv , false ) ;
50565064 }
50575065 unnecessary_literal_unwrap:: check ( cx, expr, recv, name, args) ;
50585066 } ,
0 commit comments