diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index d23f04fb861f..1bc9359e4b7c 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -1426,6 +1426,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&types::UNNECESSARY_CAST), LintId::of(&types::VEC_BOX), LintId::of(&unicode::ZERO_WIDTH_SPACE), + LintId::of(&unintentional_unit_return::UNINTENTIONAL_UNIT_RETURN), LintId::of(&unnamed_address::FN_ADDRESS_COMPARISONS), LintId::of(&unnamed_address::VTABLE_ADDRESS_COMPARISONS), LintId::of(&unnecessary_sort_by::UNNECESSARY_SORT_BY), @@ -1681,6 +1682,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&types::CAST_REF_TO_MUT), LintId::of(&types::UNIT_CMP), LintId::of(&unicode::ZERO_WIDTH_SPACE), + LintId::of(&unintentional_unit_return::UNINTENTIONAL_UNIT_RETURN), LintId::of(&unnamed_address::FN_ADDRESS_COMPARISONS), LintId::of(&unnamed_address::VTABLE_ADDRESS_COMPARISONS), LintId::of(&unused_io_amount::UNUSED_IO_AMOUNT), @@ -1730,7 +1732,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&path_buf_push_overwrite::PATH_BUF_PUSH_OVERWRITE), LintId::of(&redundant_pub_crate::REDUNDANT_PUB_CRATE), LintId::of(&transmute::USELESS_TRANSMUTE), - LintId::of(&unintentional_unit_return::UNINTENTIONAL_UNIT_RETURN), LintId::of(&use_self::USE_SELF), ]); } diff --git a/clippy_lints/src/unintentional_unit_return.rs b/clippy_lints/src/unintentional_unit_return.rs index 00e7cd8ffe62..08ba112e0dff 100644 --- a/clippy_lints/src/unintentional_unit_return.rs +++ b/clippy_lints/src/unintentional_unit_return.rs @@ -10,12 +10,13 @@ use rustc_span::{BytePos, Span}; declare_clippy_lint! { /// **What it does:** Checks for functions that expect closures of type - /// Fn(...) -> Ord where the implemented closure has a semi-colon - /// at the end of the last statement. + /// Fn(...) -> Ord where the implemented closure returns the unit type. + /// The lint also suggests to remove the semi-colon at the end of the statement if present. /// - /// **Why is this bad?** Likely the semi-colon is unintentional which - /// returns () instead of the result of last statement. Since () implements Ord - /// it doesn't cause a compilation error + /// **Why is this bad?** Likely, returning the unit type is unintentional, and + /// could simply be caused by an extra semi-colon. Since () implements Ord + /// it doesn't cause a compilation error. + /// This is the same reasoning behind the unit_cmp lint. /// /// **Known problems:** If returning unit is intentional, then there is no /// way of specifying this without triggering needless_return lint @@ -27,8 +28,8 @@ declare_clippy_lint! { /// twins.sort_by_key(|x| { x.1; }); /// ``` pub UNINTENTIONAL_UNIT_RETURN, - nursery, - "fn arguments of type Fn(...) -> Once having last statements with a semi-colon, suggesting to remove the semi-colon if it is unintentional." + correctness, + "fn arguments of type Fn(...) -> Ord returning the unit type ()." } declare_lint_pass!(UnintentionalUnitReturn => [UNINTENTIONAL_UNIT_RETURN]); diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index a9e7951c8fcf..6c2ae6ba017e 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -2252,8 +2252,8 @@ pub static ref ALL_LINTS: Vec = vec![ }, Lint { name: "unintentional_unit_return", - group: "nursery", - desc: "fn arguments of type Fn(...) -> Once having last statements with a semi-colon, suggesting to remove the semi-colon if it is unintentional.", + group: "correctness", + desc: "fn arguments of type Fn(...) -> Ord returning the unit type ().", deprecation: None, module: "unintentional_unit_return", },