mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 23:20:39 +00:00
also check for rest pat in redundant_pattern_matching
This commit is contained in:
parent
7a870aef1a
commit
e8726b20b2
5 changed files with 25 additions and 12 deletions
|
@ -170,7 +170,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Index is a constant uint.
|
// Index is a constant uint.
|
||||||
if let Some(..) = constant(cx, cx.typeck_results(), index) {
|
if constant(cx, cx.typeck_results(), index).is_some() {
|
||||||
// Let rustc's `const_err` lint handle constant `usize` indexing on arrays.
|
// Let rustc's `const_err` lint handle constant `usize` indexing on arrays.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,8 +63,11 @@ fn find_sugg_for_if_let<'tcx>(
|
||||||
// Determine which function should be used, and the type contained by the corresponding
|
// Determine which function should be used, and the type contained by the corresponding
|
||||||
// variant.
|
// variant.
|
||||||
let (good_method, inner_ty) = match check_pat.kind {
|
let (good_method, inner_ty) = match check_pat.kind {
|
||||||
PatKind::TupleStruct(ref qpath, [sub_pat], _) => {
|
PatKind::TupleStruct(ref qpath, args, rest) => {
|
||||||
if let PatKind::Wild = sub_pat.kind {
|
let is_wildcard = matches!(args.first().map(|p| &p.kind), Some(PatKind::Wild));
|
||||||
|
let is_rest = matches!((args, rest.as_opt_usize()), ([], Some(_)));
|
||||||
|
|
||||||
|
if is_wildcard || is_rest {
|
||||||
let res = cx.typeck_results().qpath_res(qpath, check_pat.hir_id);
|
let res = cx.typeck_results().qpath_res(qpath, check_pat.hir_id);
|
||||||
let Some(id) = res.opt_def_id().map(|ctor_id| cx.tcx.parent(ctor_id)) else { return };
|
let Some(id) = res.opt_def_id().map(|ctor_id| cx.tcx.parent(ctor_id)) else { return };
|
||||||
let lang_items = cx.tcx.lang_items();
|
let lang_items = cx.tcx.lang_items();
|
||||||
|
|
|
@ -54,6 +54,8 @@ fn main() {
|
||||||
} else {
|
} else {
|
||||||
3
|
3
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if gen_opt().is_some() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gen_opt() -> Option<()> {
|
fn gen_opt() -> Option<()> {
|
||||||
|
|
|
@ -63,6 +63,8 @@ fn main() {
|
||||||
} else {
|
} else {
|
||||||
3
|
3
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if let Some(..) = gen_opt() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gen_opt() -> Option<()> {
|
fn gen_opt() -> Option<()> {
|
||||||
|
|
|
@ -89,31 +89,37 @@ LL | } else if let None = gen_opt() {
|
||||||
| -------^^^^------------ help: try this: `if gen_opt().is_none()`
|
| -------^^^^------------ help: try this: `if gen_opt().is_none()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_some()`
|
error: redundant pattern matching, consider using `is_some()`
|
||||||
--> $DIR/redundant_pattern_matching_option.rs:80:12
|
--> $DIR/redundant_pattern_matching_option.rs:67:12
|
||||||
|
|
|
||||||
|
LL | if let Some(..) = gen_opt() {}
|
||||||
|
| -------^^^^^^^^------------ help: try this: `if gen_opt().is_some()`
|
||||||
|
|
||||||
|
error: redundant pattern matching, consider using `is_some()`
|
||||||
|
--> $DIR/redundant_pattern_matching_option.rs:82:12
|
||||||
|
|
|
|
||||||
LL | if let Some(_) = Some(42) {}
|
LL | if let Some(_) = Some(42) {}
|
||||||
| -------^^^^^^^----------- help: try this: `if Some(42).is_some()`
|
| -------^^^^^^^----------- help: try this: `if Some(42).is_some()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_none()`
|
error: redundant pattern matching, consider using `is_none()`
|
||||||
--> $DIR/redundant_pattern_matching_option.rs:82:12
|
--> $DIR/redundant_pattern_matching_option.rs:84:12
|
||||||
|
|
|
|
||||||
LL | if let None = None::<()> {}
|
LL | if let None = None::<()> {}
|
||||||
| -------^^^^------------- help: try this: `if None::<()>.is_none()`
|
| -------^^^^------------- help: try this: `if None::<()>.is_none()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_some()`
|
error: redundant pattern matching, consider using `is_some()`
|
||||||
--> $DIR/redundant_pattern_matching_option.rs:84:15
|
--> $DIR/redundant_pattern_matching_option.rs:86:15
|
||||||
|
|
|
|
||||||
LL | while let Some(_) = Some(42) {}
|
LL | while let Some(_) = Some(42) {}
|
||||||
| ----------^^^^^^^----------- help: try this: `while Some(42).is_some()`
|
| ----------^^^^^^^----------- help: try this: `while Some(42).is_some()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_none()`
|
error: redundant pattern matching, consider using `is_none()`
|
||||||
--> $DIR/redundant_pattern_matching_option.rs:86:15
|
--> $DIR/redundant_pattern_matching_option.rs:88:15
|
||||||
|
|
|
|
||||||
LL | while let None = None::<()> {}
|
LL | while let None = None::<()> {}
|
||||||
| ----------^^^^------------- help: try this: `while None::<()>.is_none()`
|
| ----------^^^^------------- help: try this: `while None::<()>.is_none()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_some()`
|
error: redundant pattern matching, consider using `is_some()`
|
||||||
--> $DIR/redundant_pattern_matching_option.rs:88:5
|
--> $DIR/redundant_pattern_matching_option.rs:90:5
|
||||||
|
|
|
|
||||||
LL | / match Some(42) {
|
LL | / match Some(42) {
|
||||||
LL | | Some(_) => true,
|
LL | | Some(_) => true,
|
||||||
|
@ -122,7 +128,7 @@ LL | | };
|
||||||
| |_____^ help: try this: `Some(42).is_some()`
|
| |_____^ help: try this: `Some(42).is_some()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_none()`
|
error: redundant pattern matching, consider using `is_none()`
|
||||||
--> $DIR/redundant_pattern_matching_option.rs:93:5
|
--> $DIR/redundant_pattern_matching_option.rs:95:5
|
||||||
|
|
|
|
||||||
LL | / match None::<()> {
|
LL | / match None::<()> {
|
||||||
LL | | Some(_) => false,
|
LL | | Some(_) => false,
|
||||||
|
@ -131,16 +137,16 @@ LL | | };
|
||||||
| |_____^ help: try this: `None::<()>.is_none()`
|
| |_____^ help: try this: `None::<()>.is_none()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_none()`
|
error: redundant pattern matching, consider using `is_none()`
|
||||||
--> $DIR/redundant_pattern_matching_option.rs:101:12
|
--> $DIR/redundant_pattern_matching_option.rs:103:12
|
||||||
|
|
|
|
||||||
LL | if let None = *(&None::<()>) {}
|
LL | if let None = *(&None::<()>) {}
|
||||||
| -------^^^^----------------- help: try this: `if (&None::<()>).is_none()`
|
| -------^^^^----------------- help: try this: `if (&None::<()>).is_none()`
|
||||||
|
|
||||||
error: redundant pattern matching, consider using `is_none()`
|
error: redundant pattern matching, consider using `is_none()`
|
||||||
--> $DIR/redundant_pattern_matching_option.rs:102:12
|
--> $DIR/redundant_pattern_matching_option.rs:104:12
|
||||||
|
|
|
|
||||||
LL | if let None = *&None::<()> {}
|
LL | if let None = *&None::<()> {}
|
||||||
| -------^^^^--------------- help: try this: `if (&None::<()>).is_none()`
|
| -------^^^^--------------- help: try this: `if (&None::<()>).is_none()`
|
||||||
|
|
||||||
error: aborting due to 21 previous errors
|
error: aborting due to 22 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue