File tree 2 files changed +11
-13
lines changed
2 files changed +11
-13
lines changed Original file line number Diff line number Diff line change @@ -832,32 +832,30 @@ declare_clippy_lint! {
832
832
/// etc. instead.
833
833
///
834
834
/// ### Why is this bad?
835
- /// The function will always be called and potentially
836
- /// allocate an object acting as the default .
835
+ /// The function will always be called. This is only bad if it allocates or
836
+ /// does some non-trivial amount of work .
837
837
///
838
838
/// ### Known problems
839
- /// If the function has side-effects, not calling it will
840
- /// change the semantic of the program, but you shouldn't rely on that anyway.
839
+ /// If the function has side-effects, not calling it will change the
840
+ /// semantic of the program, but you shouldn't rely on that.
841
+ ///
842
+ /// The lint also cannot figure out whether the function you call is
843
+ /// actually expensive to call or not.
841
844
///
842
845
/// ### Example
843
846
/// ```rust
844
847
/// # let foo = Some(String::new());
845
- /// foo.unwrap_or(String::new( ));
848
+ /// foo.unwrap_or(String::from("empty" ));
846
849
/// ```
847
850
///
848
851
/// Use instead:
849
852
/// ```rust
850
853
/// # let foo = Some(String::new());
851
- /// foo.unwrap_or_else(String::new);
852
- ///
853
- /// // or
854
- ///
855
- /// # let foo = Some(String::new());
856
- /// foo.unwrap_or_default();
854
+ /// foo.unwrap_or_else(|| String::from("empty"));
857
855
/// ```
858
856
#[ clippy:: version = "pre 1.29.0" ]
859
857
pub OR_FUN_CALL ,
860
- perf ,
858
+ nursery ,
861
859
"using any `*or` method with a function call, which suggests `*or_else`"
862
860
}
863
861
Original file line number Diff line number Diff line change 1
- #![ warn( clippy:: all) ]
1
+ #![ warn( clippy:: all, clippy :: or_fun_call ) ]
2
2
3
3
fn main ( ) {
4
4
let s = Some ( String :: from ( "test string" ) ) . unwrap_or ( "Fail" . to_string ( ) ) . len ( ) ;
You can’t perform that action at this time.
0 commit comments