Skip to content

Commit 55fdd1e

Browse files
committed
replace reference with value
1 parent de92da2 commit 55fdd1e

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

clippy_lints/src/manual_is_ascii_check.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::{diagnostics::span_lint_and_sugg, higher, in_constant, macros:
33
use rustc_ast::ast::RangeLimits;
44
use rustc_ast::LitKind::{Byte, Char};
55
use rustc_errors::Applicability;
6-
use rustc_hir::{Expr, ExprKind, PatKind, RangeEnd};
6+
use rustc_hir::{BorrowKind, Expr, ExprKind, PatKind, RangeEnd};
77
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_session::{declare_tool_lint, impl_lint_pass};
99
use rustc_span::{def_id::DefId, sym, Span};
@@ -86,8 +86,12 @@ impl<'tcx> LateLintPass<'tcx> for ManualIsAsciiCheck {
8686
&& path.ident.name == sym!(contains)
8787
&& let Some(higher::Range { start: Some(start), end: Some(end), limits: RangeLimits::Closed })
8888
= higher::Range::hir(receiver) {
89-
let range = check_range(start, end);
89+
let range = check_range(start, end);
90+
if let ExprKind::AddrOf(BorrowKind::Ref, _, e) = arg.kind {
91+
check_is_ascii(cx, expr.span, e, &range);
92+
} else {
9093
check_is_ascii(cx, expr.span, arg, &range);
94+
}
9195
}
9296
}
9397

tests/ui/manual_is_ascii_check.fixed

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ fn main() {
1616

1717
assert!(matches!('x', 'A'..='Z' | 'a'..='z' | '_'));
1818

19-
assert!(&b'0'.is_ascii_digit());
20-
assert!(&b'a'.is_ascii_lowercase());
21-
assert!(&b'A'.is_ascii_uppercase());
19+
assert!(b'0'.is_ascii_digit());
20+
assert!(b'a'.is_ascii_lowercase());
21+
assert!(b'A'.is_ascii_uppercase());
2222

23-
assert!(&'0'.is_ascii_digit());
24-
assert!(&'a'.is_ascii_lowercase());
25-
assert!(&'A'.is_ascii_uppercase());
23+
assert!('0'.is_ascii_digit());
24+
assert!('a'.is_ascii_lowercase());
25+
assert!('A'.is_ascii_uppercase());
2626
}
2727

2828
#[clippy::msrv = "1.23"]

tests/ui/manual_is_ascii_check.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,37 +46,37 @@ error: manual check for common ascii range
4646
--> $DIR/manual_is_ascii_check.rs:19:13
4747
|
4848
LL | assert!((b'0'..=b'9').contains(&b'0'));
49-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&b'0'.is_ascii_digit()`
49+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'0'.is_ascii_digit()`
5050

5151
error: manual check for common ascii range
5252
--> $DIR/manual_is_ascii_check.rs:20:13
5353
|
5454
LL | assert!((b'a'..=b'z').contains(&b'a'));
55-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&b'a'.is_ascii_lowercase()`
55+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'a'.is_ascii_lowercase()`
5656

5757
error: manual check for common ascii range
5858
--> $DIR/manual_is_ascii_check.rs:21:13
5959
|
6060
LL | assert!((b'A'..=b'Z').contains(&b'A'));
61-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&b'A'.is_ascii_uppercase()`
61+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'A'.is_ascii_uppercase()`
6262

6363
error: manual check for common ascii range
6464
--> $DIR/manual_is_ascii_check.rs:23:13
6565
|
6666
LL | assert!(('0'..='9').contains(&'0'));
67-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'0'.is_ascii_digit()`
67+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'0'.is_ascii_digit()`
6868

6969
error: manual check for common ascii range
7070
--> $DIR/manual_is_ascii_check.rs:24:13
7171
|
7272
LL | assert!(('a'..='z').contains(&'a'));
73-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a'.is_ascii_lowercase()`
73+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'a'.is_ascii_lowercase()`
7474

7575
error: manual check for common ascii range
7676
--> $DIR/manual_is_ascii_check.rs:25:13
7777
|
7878
LL | assert!(('A'..='Z').contains(&'A'));
79-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'A'.is_ascii_uppercase()`
79+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'A'.is_ascii_uppercase()`
8080

8181
error: manual check for common ascii range
8282
--> $DIR/manual_is_ascii_check.rs:37:13

0 commit comments

Comments
 (0)