Skip to content

Commit 64243c6

Browse files
committed
Auto merge of #9484 - Xaeroxe:clamping-without-clamp, r=Alexendoo
Implement `manual_clamp` lint Fixes #9477 Fixes #6751 Identifies common patterns where usage of the `clamp` function would be more succinct and clear, and suggests using the `clamp` function instead. changelog: [`manual_clamp`]: Implement manual_clamp lint
2 parents 9b6b452 + b221184 commit 64243c6

16 files changed

+1479
-19
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3985,6 +3985,7 @@ Released 2018-09-13
39853985
[`manual_assert`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_assert
39863986
[`manual_async_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_async_fn
39873987
[`manual_bits`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_bits
3988+
[`manual_clamp`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_clamp
39883989
[`manual_filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_filter_map
39893990
[`manual_find`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_find
39903991
[`manual_find_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_find_map

clippy_lints/src/lib.register_all.rs

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
125125
LintId::of(main_recursion::MAIN_RECURSION),
126126
LintId::of(manual_async_fn::MANUAL_ASYNC_FN),
127127
LintId::of(manual_bits::MANUAL_BITS),
128+
LintId::of(manual_clamp::MANUAL_CLAMP),
128129
LintId::of(manual_non_exhaustive::MANUAL_NON_EXHAUSTIVE),
129130
LintId::of(manual_rem_euclid::MANUAL_REM_EUCLID),
130131
LintId::of(manual_retain::MANUAL_RETAIN),

clippy_lints/src/lib.register_complexity.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ store.register_group(true, "clippy::complexity", Some("clippy_complexity"), vec!
2222
LintId::of(loops::MANUAL_FLATTEN),
2323
LintId::of(loops::SINGLE_ELEMENT_LOOP),
2424
LintId::of(loops::WHILE_LET_LOOP),
25+
LintId::of(manual_clamp::MANUAL_CLAMP),
2526
LintId::of(manual_rem_euclid::MANUAL_REM_EUCLID),
2627
LintId::of(manual_strip::MANUAL_STRIP),
2728
LintId::of(map_unit_fn::OPTION_MAP_UNIT_FN),

clippy_lints/src/lib.register_lints.rs

+1
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ store.register_lints(&[
245245
manual_assert::MANUAL_ASSERT,
246246
manual_async_fn::MANUAL_ASYNC_FN,
247247
manual_bits::MANUAL_BITS,
248+
manual_clamp::MANUAL_CLAMP,
248249
manual_instant_elapsed::MANUAL_INSTANT_ELAPSED,
249250
manual_non_exhaustive::MANUAL_NON_EXHAUSTIVE,
250251
manual_rem_euclid::MANUAL_REM_EUCLID,

clippy_lints/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ mod main_recursion;
267267
mod manual_assert;
268268
mod manual_async_fn;
269269
mod manual_bits;
270+
mod manual_clamp;
270271
mod manual_instant_elapsed;
271272
mod manual_non_exhaustive;
272273
mod manual_rem_euclid;
@@ -897,6 +898,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
897898
store.register_late_pass(|_| Box::<std_instead_of_core::StdReexports>::default());
898899
store.register_late_pass(|_| Box::new(manual_instant_elapsed::ManualInstantElapsed));
899900
store.register_late_pass(|_| Box::new(partialeq_to_none::PartialeqToNone));
901+
store.register_late_pass(move |_| Box::new(manual_clamp::ManualClamp::new(msrv)));
900902
store.register_late_pass(|_| Box::new(manual_string_new::ManualStringNew));
901903
store.register_late_pass(|_| Box::new(unused_peekable::UnusedPeekable));
902904
store.register_early_pass(|| Box::new(multi_assignments::MultiAssignments));

0 commit comments

Comments
 (0)