Auto merge of #11988 - J-ZhengLi:issue11324, r=Alexendoo

fix suggestion error for [`manual_is_ascii_check`] with missing type

fixes: #11324
fixes: #11776

changelog: improve [`manual_is_ascii_check`] to suggest labeling type in closure, fix FP with type generics, and improve linting on ref expressions.
This commit is contained in:
bors 2024-05-01 13:54:24 +00:00
commit 852a64f875
4 changed files with 152 additions and 32 deletions

View file

@ -55,3 +55,30 @@ fn msrv_1_47() {
const FOO: bool = 'x'.is_ascii_digit();
const BAR: bool = 'x'.is_ascii_hexdigit();
}
#[allow(clippy::deref_addrof, clippy::needless_borrow)]
fn with_refs() {
let cool_letter = &&'g';
cool_letter.is_ascii_digit();
cool_letter.is_ascii_lowercase();
}
fn generics() {
fn a<U>(u: &U) -> bool
where
char: PartialOrd<U>,
U: PartialOrd<char> + ?Sized,
{
('A'..='Z').contains(u)
}
fn take_while<Item, F>(cond: F)
where
Item: Sized,
F: Fn(Item) -> bool,
{
}
take_while(|c: char| c.is_ascii_uppercase());
take_while(|c: u8| c.is_ascii_uppercase());
take_while(|c: char| c.is_ascii_uppercase());
}

View file

@ -55,3 +55,30 @@ fn msrv_1_47() {
const FOO: bool = matches!('x', '0'..='9');
const BAR: bool = matches!('x', '0'..='9' | 'a'..='f' | 'A'..='F');
}
#[allow(clippy::deref_addrof, clippy::needless_borrow)]
fn with_refs() {
let cool_letter = &&'g';
('0'..='9').contains(&&cool_letter);
('a'..='z').contains(*cool_letter);
}
fn generics() {
fn a<U>(u: &U) -> bool
where
char: PartialOrd<U>,
U: PartialOrd<char> + ?Sized,
{
('A'..='Z').contains(u)
}
fn take_while<Item, F>(cond: F)
where
Item: Sized,
F: Fn(Item) -> bool,
{
}
take_while(|c| ('A'..='Z').contains(&c));
take_while(|c| (b'A'..=b'Z').contains(&c));
take_while(|c: char| ('A'..='Z').contains(&c));
}

View file

@ -133,5 +133,45 @@ error: manual check for common ascii range
LL | const BAR: bool = matches!('x', '0'..='9' | 'a'..='f' | 'A'..='F');
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_hexdigit()`
error: aborting due to 22 previous errors
error: manual check for common ascii range
--> tests/ui/manual_is_ascii_check.rs:62:5
|
LL | ('0'..='9').contains(&&cool_letter);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cool_letter.is_ascii_digit()`
error: manual check for common ascii range
--> tests/ui/manual_is_ascii_check.rs:63:5
|
LL | ('a'..='z').contains(*cool_letter);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cool_letter.is_ascii_lowercase()`
error: manual check for common ascii range
--> tests/ui/manual_is_ascii_check.rs:81:20
|
LL | take_while(|c| ('A'..='Z').contains(&c));
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
help: try
|
LL | take_while(|c: char| c.is_ascii_uppercase());
| ~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~
error: manual check for common ascii range
--> tests/ui/manual_is_ascii_check.rs:82:20
|
LL | take_while(|c| (b'A'..=b'Z').contains(&c));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: try
|
LL | take_while(|c: u8| c.is_ascii_uppercase());
| ~~~~~ ~~~~~~~~~~~~~~~~~~~~~~
error: manual check for common ascii range
--> tests/ui/manual_is_ascii_check.rs:83:26
|
LL | take_while(|c: char| ('A'..='Z').contains(&c));
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `c.is_ascii_uppercase()`
error: aborting due to 27 previous errors