Skip to content

Commit 4e98406

Browse files
committed
WIP: combine almost_complete_letter range and almost_complete_digit_range
1 parent 31ad701 commit 4e98406

12 files changed

+69
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3875,6 +3875,7 @@ Released 2018-09-13
38753875
[`alloc_instead_of_core`]: https://rust-lang.github.io/rust-clippy/master/index.html#alloc_instead_of_core
38763876
[`allow_attributes_without_reason`]: https://rust-lang.github.io/rust-clippy/master/index.html#allow_attributes_without_reason
38773877
[`almost_complete_letter_range`]: https://rust-lang.github.io/rust-clippy/master/index.html#almost_complete_letter_range
3878+
[`almost_complete_range`]: https://rust-lang.github.io/rust-clippy/master/index.html#almost_complete_range
38783879
[`almost_swapped`]: https://rust-lang.github.io/rust-clippy/master/index.html#almost_swapped
38793880
[`approx_constant`]: https://rust-lang.github.io/rust-clippy/master/index.html#approx_constant
38803881
[`arithmetic_side_effects`]: https://rust-lang.github.io/rust-clippy/master/index.html#arithmetic_side_effects

clippy_lints/src/almost_complete_letter_range.rs renamed to clippy_lints/src/almost_complete_range.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use rustc_span::Span;
1010

1111
declare_clippy_lint! {
1212
/// ### What it does
13-
/// Checks for ranges which almost include the entire range of letters from 'a' to 'z', but
14-
/// don't because they're a half open range.
13+
/// Checks for ranges which almost include the entire range of letters from 'a' to 'z'
14+
/// or digits from '0' to '9', but don't because they're a half open range.
1515
///
1616
/// ### Why is this bad?
1717
/// This (`'a'..'z'`) is almost certainly a typo meant to include all letters.
@@ -25,21 +25,21 @@ declare_clippy_lint! {
2525
/// let _ = 'a'..='z';
2626
/// ```
2727
#[clippy::version = "1.63.0"]
28-
pub ALMOST_COMPLETE_LETTER_RANGE,
28+
pub ALMOST_COMPLETE_RANGE,
2929
suspicious,
30-
"almost complete letter range"
30+
"almost complete range"
3131
}
32-
impl_lint_pass!(AlmostCompleteLetterRange => [ALMOST_COMPLETE_LETTER_RANGE]);
32+
impl_lint_pass!(AlmostCompleteRange => [ALMOST_COMPLETE_RANGE]);
3333

34-
pub struct AlmostCompleteLetterRange {
34+
pub struct AlmostCompleteRange {
3535
msrv: Msrv,
3636
}
37-
impl AlmostCompleteLetterRange {
37+
impl AlmostCompleteRange {
3838
pub fn new(msrv: Msrv) -> Self {
3939
Self { msrv }
4040
}
4141
}
42-
impl EarlyLintPass for AlmostCompleteLetterRange {
42+
impl EarlyLintPass for AlmostCompleteRange {
4343
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) {
4444
if let ExprKind::Range(Some(start), Some(end), RangeLimits::HalfOpen) = &e.kind {
4545
let ctxt = e.span.ctxt();
@@ -87,14 +87,18 @@ fn check_range(cx: &EarlyContext<'_>, span: Span, start: &Expr, end: &Expr, sugg
8787
Ok(LitKind::Byte(b'A') | LitKind::Char('A')),
8888
Ok(LitKind::Byte(b'Z') | LitKind::Char('Z')),
8989
)
90+
| (
91+
Ok(LitKind::Byte(b'0') | LitKind::Char('0')),
92+
Ok(LitKind::Byte(b'9') | LitKind::Char('9')),
93+
)
9094
)
9195
&& !in_external_macro(cx.sess(), span)
9296
{
9397
span_lint_and_then(
9498
cx,
95-
ALMOST_COMPLETE_LETTER_RANGE,
99+
ALMOST_COMPLETE_RANGE,
96100
span,
97-
"almost complete ascii letter range",
101+
"almost complete ascii range",
98102
|diag| {
99103
if let Some((span, sugg)) = sugg {
100104
diag.span_suggestion(

clippy_lints/src/declared_lints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
3535
crate::utils::internal_lints::produce_ice::PRODUCE_ICE_INFO,
3636
#[cfg(feature = "internal")]
3737
crate::utils::internal_lints::unnecessary_def_path::UNNECESSARY_DEF_PATH_INFO,
38-
crate::almost_complete_letter_range::ALMOST_COMPLETE_LETTER_RANGE_INFO,
38+
crate::almost_complete_range::ALMOST_COMPLETE_RANGE_INFO,
3939
crate::approx_const::APPROX_CONSTANT_INFO,
4040
crate::as_conversions::AS_CONVERSIONS_INFO,
4141
crate::asm_syntax::INLINE_ASM_X86_ATT_SYNTAX_INFO,

clippy_lints/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ mod declared_lints;
6666
mod renamed_lints;
6767

6868
// begin lints modules, do not remove this comment, it’s used in `update_lints`
69-
mod almost_complete_letter_range;
69+
mod almost_complete_range;
7070
mod approx_const;
7171
mod as_conversions;
7272
mod asm_syntax;
@@ -859,7 +859,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
859859
store.register_late_pass(|_| Box::new(rc_clone_in_vec_init::RcCloneInVecInit));
860860
store.register_early_pass(|| Box::<duplicate_mod::DuplicateMod>::default());
861861
store.register_early_pass(|| Box::new(unused_rounding::UnusedRounding));
862-
store.register_early_pass(move || Box::new(almost_complete_letter_range::AlmostCompleteLetterRange::new(msrv())));
862+
store.register_early_pass(move || Box::new(almost_complete_range::AlmostCompleteRange::new(msrv())));
863863
store.register_late_pass(|_| Box::new(swap_ptr_to_ref::SwapPtrToRef));
864864
store.register_late_pass(|_| Box::new(mismatching_type_param_order::TypeParamMismatch));
865865
store.register_late_pass(|_| Box::new(read_zero_byte_vec::ReadZeroByteVec));

clippy_lints/src/renamed_lints.rs

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

33
#[rustfmt::skip]
44
pub static RENAMED_LINTS: &[(&str, &str)] = &[
5+
("clippy::almost_complete_letter_range", "clippy::almost_complete_range"),
56
("clippy::blacklisted_name", "clippy::disallowed_names"),
67
("clippy::block_in_if_condition_expr", "clippy::blocks_in_if_conditions"),
78
("clippy::block_in_if_condition_stmt", "clippy::blocks_in_if_conditions"),

tests/ui/almost_complete_letter_range.fixed renamed to tests/ui/almost_complete_range.fixed

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

55
#![feature(exclusive_range_pattern)]
66
#![feature(stmt_expr_attributes)]
7-
#![warn(clippy::almost_complete_letter_range)]
7+
#![warn(clippy::almost_complete_range)]
88
#![allow(ellipsis_inclusive_range_patterns)]
99
#![allow(clippy::needless_parens_on_range_literals)]
1010

tests/ui/almost_complete_letter_range.rs renamed to tests/ui/almost_complete_range.rs

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#![feature(exclusive_range_pattern)]
66
#![feature(stmt_expr_attributes)]
7-
#![warn(clippy::almost_complete_letter_range)]
7+
#![warn(clippy::almost_complete_range)]
88
#![allow(ellipsis_inclusive_range_patterns)]
99
#![allow(clippy::needless_parens_on_range_literals)]
1010

@@ -16,64 +16,96 @@ macro_rules! a {
1616
'a'
1717
};
1818
}
19+
macro_rules! A {
20+
() => {
21+
'A'
22+
};
23+
}
24+
macro_rules! zero {
25+
() => {
26+
'0'
27+
};
28+
}
1929

2030
macro_rules! b {
2131
() => {
2232
let _ = 'a'..'z';
2333
};
34+
() => {
35+
let _ = 'A'..'Z';
36+
};
37+
() => {
38+
let _ = '0'..'9';
39+
};
2440
}
2541

2642
fn main() {
2743
#[rustfmt::skip]
2844
{
2945
let _ = ('a') ..'z';
3046
let _ = 'A' .. ('Z');
47+
let _ = ((('0'))) .. ('9');
3148
}
3249

3350
let _ = 'b'..'z';
3451
let _ = 'B'..'Z';
52+
let _ = '1'..'9';
3553

3654
let _ = (b'a')..(b'z');
3755
let _ = b'A'..b'Z';
56+
let _ = b'0'..b'9';
3857

3958
let _ = b'b'..b'z';
4059
let _ = b'B'..b'Z';
60+
let _ = b'1'..b'9';
4161

4262
let _ = a!()..'z';
63+
let _ = A!()..'Z';
64+
let _ = zero!()..'9';
4365

4466
let _ = match 0u8 {
4567
b'a'..b'z' if true => 1,
4668
b'A'..b'Z' if true => 2,
47-
b'b'..b'z' => 3,
48-
b'B'..b'Z' => 4,
49-
_ => 5,
69+
b'0'..b'9' if true => 3,
70+
b'b'..b'z' => 4,
71+
b'B'..b'Z' => 5,
72+
b'1'..b'9' => 6,
73+
_ => 7,
5074
};
5175

5276
let _ = match 'x' {
5377
'a'..'z' if true => 1,
5478
'A'..'Z' if true => 2,
55-
'b'..'z' => 3,
56-
'B'..'Z' => 4,
57-
_ => 5,
79+
'0'..'9' if true => 3,
80+
'b'..'z' => 4,
81+
'B'..'Z' => 5,
82+
'1'..'9' => 6,
83+
_ => 7,
5884
};
5985

60-
almost_complete_letter_range!();
86+
almost_complete_range!();
6187
b!();
6288
}
6389

6490
#[clippy::msrv = "1.25"]
6591
fn _under_msrv() {
6692
let _ = match 'a' {
6793
'a'..'z' => 1,
68-
_ => 2,
94+
'A'..'Z' => 2,
95+
'0'..'9' => 3,
96+
_ => 4,
6997
};
7098
}
7199

72100
#[clippy::msrv = "1.26"]
73101
fn _meets_msrv() {
74102
let _ = 'a'..'z';
103+
let _ = 'A'..'Z';
104+
let _ = '0'..'9';
75105
let _ = match 'a' {
76106
'a'..'z' => 1,
77-
_ => 2,
107+
'A'..'Z' => 1,
108+
'0'..'9' => 3,
109+
_ => 4,
78110
};
79111
}

tests/ui/auxiliary/macro_rules.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,10 @@ macro_rules! equatable_if_let {
142142
}
143143

144144
#[macro_export]
145-
macro_rules! almost_complete_letter_range {
145+
macro_rules! almost_complete_range {
146146
() => {
147147
let _ = 'a'..'z';
148+
let _ = 'A'..'Z';
149+
let _ = '0'..'9';
148150
};
149151
}

tests/ui/needless_parens_on_range_literals.fixed

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

44
#![warn(clippy::needless_parens_on_range_literals)]
5-
#![allow(clippy::almost_complete_letter_range)]
5+
#![allow(clippy::almost_complete_range)]
66

77
fn main() {
88
let _ = 'a'..='z';

0 commit comments

Comments
 (0)