mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 07:44:10 +00:00
Make it clear that or_fun_call
can be a false-positive
Also move it to nursery so that the false-positives can be dealt with. CC #8574
This commit is contained in:
parent
4f1698db60
commit
243661b739
@ -832,32 +832,30 @@ declare_clippy_lint! {
|
|||||||
/// etc. instead.
|
/// etc. instead.
|
||||||
///
|
///
|
||||||
/// ### Why is this bad?
|
/// ### Why is this bad?
|
||||||
/// The function will always be called and potentially
|
/// The function will always be called. This is only bad if it allocates or
|
||||||
/// allocate an object acting as the default.
|
/// does some non-trivial amount of work.
|
||||||
///
|
///
|
||||||
/// ### Known problems
|
/// ### Known problems
|
||||||
/// If the function has side-effects, not calling it will
|
/// If the function has side-effects, not calling it will change the
|
||||||
/// change the semantic of the program, but you shouldn't rely on that anyway.
|
/// semantic of the program, but you shouldn't rely on that.
|
||||||
|
///
|
||||||
|
/// The lint also cannot figure out whether the function you call is
|
||||||
|
/// actually expensive to call or not.
|
||||||
///
|
///
|
||||||
/// ### Example
|
/// ### Example
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # let foo = Some(String::new());
|
/// # let foo = Some(String::new());
|
||||||
/// foo.unwrap_or(String::new());
|
/// foo.unwrap_or(String::from("empty"));
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # let foo = Some(String::new());
|
/// # let foo = Some(String::new());
|
||||||
/// foo.unwrap_or_else(String::new);
|
/// foo.unwrap_or_else(|| String::from("empty"));
|
||||||
///
|
|
||||||
/// // or
|
|
||||||
///
|
|
||||||
/// # let foo = Some(String::new());
|
|
||||||
/// foo.unwrap_or_default();
|
|
||||||
/// ```
|
/// ```
|
||||||
#[clippy::version = "pre 1.29.0"]
|
#[clippy::version = "pre 1.29.0"]
|
||||||
pub OR_FUN_CALL,
|
pub OR_FUN_CALL,
|
||||||
perf,
|
nursery,
|
||||||
"using any `*or` method with a function call, which suggests `*or_else`"
|
"using any `*or` method with a function call, which suggests `*or_else`"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#![warn(clippy::all)]
|
#![warn(clippy::all, clippy::or_fun_call)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len();
|
let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len();
|
||||||
|
Loading…
Reference in New Issue
Block a user