Skip to content

Commit 935b45d

Browse files
authored
Rollup merge of rust-lang#5409 - dtolnay:letunit, r=flip1995
Downgrade let_unit_value to pedantic Given that the false positive in rust-lang#1502 is marked E-hard and I don't have much hope of it getting fixed, I think it would be wise to disable this lint by default. I have had to suppress this lint in every substantial codebase (\>100k line) I have worked in. Any time this lint is being triggered, it's always the false positive case. The motivation for this lint is documented as: > A unit value cannot usefully be used anywhere. So binding one is kind of pointless. with this example: > ```rust > let x = { > 1; > }; > ``` Sure, but the author would find this out via an unused_variable warning or from `x` not being the type that they need further down. If there ends up being a type error on `x`, clippy's advice isn't going to help get the code compiling because it can only run if the code already compiles. changelog: Remove let_unit_value from default set of enabled lints
2 parents 46337cb + adcaa1b commit 935b45d

File tree

8 files changed

+7
-10
lines changed

8 files changed

+7
-10
lines changed

clippy_lints/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11311131
LintId::of(&types::CAST_PRECISION_LOSS),
11321132
LintId::of(&types::CAST_SIGN_LOSS),
11331133
LintId::of(&types::INVALID_UPCAST_COMPARISONS),
1134+
LintId::of(&types::LET_UNIT_VALUE),
11341135
LintId::of(&types::LINKEDLIST),
11351136
LintId::of(&types::OPTION_OPTION),
11361137
LintId::of(&unicode::NON_ASCII_LITERAL),
@@ -1382,7 +1383,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
13821383
LintId::of(&types::FN_TO_NUMERIC_CAST),
13831384
LintId::of(&types::FN_TO_NUMERIC_CAST_WITH_TRUNCATION),
13841385
LintId::of(&types::IMPLICIT_HASHER),
1385-
LintId::of(&types::LET_UNIT_VALUE),
13861386
LintId::of(&types::REDUNDANT_ALLOCATION),
13871387
LintId::of(&types::TYPE_COMPLEXITY),
13881388
LintId::of(&types::UNIT_ARG),
@@ -1495,7 +1495,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
14951495
LintId::of(&types::FN_TO_NUMERIC_CAST),
14961496
LintId::of(&types::FN_TO_NUMERIC_CAST_WITH_TRUNCATION),
14971497
LintId::of(&types::IMPLICIT_HASHER),
1498-
LintId::of(&types::LET_UNIT_VALUE),
14991498
LintId::of(&unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME),
15001499
LintId::of(&write::PRINTLN_EMPTY_STRING),
15011500
LintId::of(&write::PRINT_LITERAL),

clippy_lints/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ declare_clippy_lint! {
593593
/// };
594594
/// ```
595595
pub LET_UNIT_VALUE,
596-
style,
596+
pedantic,
597597
"creating a `let` binding to a value of unit type, which usually can't be used afterwards"
598598
}
599599

src/lintlist/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
999999
},
10001000
Lint {
10011001
name: "let_unit_value",
1002-
group: "style",
1002+
group: "pedantic",
10031003
desc: "creating a `let` binding to a value of unit type, which usually can\'t be used afterwards",
10041004
deprecation: None,
10051005
module: "types",

tests/ui/doc_unsafe.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ very_unsafe!();
8888
// we don't lint code from external macros
8989
undocd_unsafe!();
9090

91-
#[allow(clippy::let_unit_value)]
9291
fn main() {
9392
unsafe {
9493
you_dont_see_me();

tests/ui/redundant_pattern_matching.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#![warn(clippy::all)]
44
#![warn(clippy::redundant_pattern_matching)]
5-
#![allow(clippy::unit_arg, clippy::let_unit_value, unused_must_use)]
5+
#![allow(clippy::unit_arg, unused_must_use)]
66

77
fn main() {
88
Ok::<i32, i32>(42).is_ok();

tests/ui/redundant_pattern_matching.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#![warn(clippy::all)]
44
#![warn(clippy::redundant_pattern_matching)]
5-
#![allow(clippy::unit_arg, clippy::let_unit_value, unused_must_use)]
5+
#![allow(clippy::unit_arg, unused_must_use)]
66

77
fn main() {
88
if let Ok(_) = Ok::<i32, i32>(42) {}

tests/ui/uninit.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use std::mem::MaybeUninit;
44

5-
#[allow(clippy::let_unit_value)]
65
fn main() {
76
let _: usize = unsafe { MaybeUninit::uninit().assume_init() };
87

tests/ui/uninit.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error: this call for this type may be undefined behavior
2-
--> $DIR/uninit.rs:7:29
2+
--> $DIR/uninit.rs:6:29
33
|
44
LL | let _: usize = unsafe { MaybeUninit::uninit().assume_init() };
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `#[deny(clippy::uninit_assumed_init)]` on by default
88

99
error: this call for this type may be undefined behavior
10-
--> $DIR/uninit.rs:10:31
10+
--> $DIR/uninit.rs:9:31
1111
|
1212
LL | let _: [u8; 0] = unsafe { MaybeUninit::uninit().assume_init() };
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)