move expr_requires_coercion to clippy_utils & some other adjustments

This commit is contained in:
J-ZhengLi 2024-09-14 00:11:11 +08:00 committed by J-ZhengLi
parent a2f9861df8
commit 2a4be5365a
5 changed files with 111 additions and 86 deletions

View file

@ -113,7 +113,16 @@ fn main() {
}
// #6811
Some(0).map(|x| vec![x]);
match Some(0) {
Some(x) => Some(vec![x]),
None => None,
};
// Don't lint, coercion
let x: Option<Vec<&[u8]>> = match Some(()) {
Some(_) => Some(vec![b"1234"]),
None => None,
};
option_env!("").map(String::from);

View file

@ -170,6 +170,12 @@ fn main() {
None => None,
};
// Don't lint, coercion
let x: Option<Vec<&[u8]>> = match Some(()) {
Some(_) => Some(vec![b"1234"]),
None => None,
};
match option_env!("") {
Some(x) => Some(String::from(x)),
None => None,

View file

@ -156,16 +156,7 @@ LL | | };
| |_____^ help: try: `Some((String::new(), "test")).as_ref().map(|(x, y)| (y, x))`
error: manual implementation of `Option::map`
--> tests/ui/manual_map_option.rs:168:5
|
LL | / match Some(0) {
LL | | Some(x) => Some(vec![x]),
LL | | None => None,
LL | | };
| |_____^ help: try: `Some(0).map(|x| vec![x])`
error: manual implementation of `Option::map`
--> tests/ui/manual_map_option.rs:173:5
--> tests/ui/manual_map_option.rs:179:5
|
LL | / match option_env!("") {
LL | | Some(x) => Some(String::from(x)),
@ -174,7 +165,7 @@ LL | | };
| |_____^ help: try: `option_env!("").map(String::from)`
error: manual implementation of `Option::map`
--> tests/ui/manual_map_option.rs:193:12
--> tests/ui/manual_map_option.rs:199:12
|
LL | } else if let Some(x) = Some(0) {
| ____________^
@ -185,7 +176,7 @@ LL | | };
| |_____^ help: try: `{ Some(0).map(|x| x + 1) }`
error: manual implementation of `Option::map`
--> tests/ui/manual_map_option.rs:201:12
--> tests/ui/manual_map_option.rs:207:12
|
LL | } else if let Some(x) = Some(0) {
| ____________^
@ -195,5 +186,5 @@ LL | | None
LL | | };
| |_____^ help: try: `{ Some(0).map(|x| x + 1) }`
error: aborting due to 21 previous errors
error: aborting due to 20 previous errors