Skip to content

Commit 382438a

Browse files
committed
Make it clear that or_fun_call can be a false-positive
Also change its category to `style` so it's clear that it's not always a performance lint. Fixes #8574.
1 parent 4f1698d commit 382438a

File tree

1 file changed

+9
-11
lines changed
  • clippy_lints/src/methods

1 file changed

+9
-11
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -832,28 +832,26 @@ declare_clippy_lint! {
832832
/// etc. instead.
833833
///
834834
/// ### 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.
837837
///
838838
/// ### 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.
841844
///
842845
/// ### Example
843846
/// ```rust
844847
/// # let foo = Some(String::new());
845-
/// foo.unwrap_or(String::new());
848+
/// foo.unwrap_or(String::from("empty"));
846849
/// ```
847850
///
848851
/// Use instead:
849852
/// ```rust
850853
/// # 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"));
857855
/// ```
858856
#[clippy::version = "pre 1.29.0"]
859857
pub OR_FUN_CALL,

0 commit comments

Comments
 (0)