Skip to content

Commit 4948307

Browse files
committed
Fix cases of match_wildcard_for_single_variants lint when it is spanned on Option
1 parent 0ad9f7d commit 4948307

File tree

7 files changed

+13
-9
lines changed

7 files changed

+13
-9
lines changed

clippy_lints/src/consts.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ impl Constant {
139139
.find(|r| r.map_or(true, |o| o != Ordering::Equal))
140140
.unwrap_or_else(|| Some(l.len().cmp(&r.len()))),
141141
(&Self::Repeat(ref lv, ref ls), &Self::Repeat(ref rv, ref rs)) => {
142+
#[allow(clippy::match_wildcard_for_single_variants)]
142143
match Self::partial_cmp(tcx, cmp_type, lv, rv) {
143144
Some(Equal) => Some(ls.cmp(rs)),
144145
x => x,
@@ -354,14 +355,14 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
354355
(Some(Constant::Vec(vec)), Some(Constant::Int(index))) => match vec.get(index as usize) {
355356
Some(Constant::F32(x)) => Some(Constant::F32(*x)),
356357
Some(Constant::F64(x)) => Some(Constant::F64(*x)),
357-
_ => None,
358+
Some(_) | None => None,
358359
},
359360
(Some(Constant::Vec(vec)), _) => {
360361
if !vec.is_empty() && vec.iter().all(|x| *x == vec[0]) {
361362
match vec.get(0) {
362363
Some(Constant::F32(x)) => Some(Constant::F32(*x)),
363364
Some(Constant::F64(x)) => Some(Constant::F64(*x)),
364-
_ => None,
365+
Some(_) | None => None,
365366
}
366367
} else {
367368
None
@@ -532,7 +533,7 @@ pub fn miri_to_const(result: &ty::Const<'_>) -> Option<Constant> {
532533
})
533534
.collect::<Option<Vec<Constant>>>()
534535
.map(Constant::Vec),
535-
_ => None,
536+
Some(_) | None => None,
536537
},
537538
ty::Float(FloatTy::F64) => match miri_to_const(len) {
538539
Some(Constant::Int(len)) => alloc
@@ -546,7 +547,7 @@ pub fn miri_to_const(result: &ty::Const<'_>) -> Option<Constant> {
546547
})
547548
.collect::<Option<Vec<Constant>>>()
548549
.map(Constant::Vec),
549-
_ => None,
550+
Some(_) | None => None,
550551
},
551552
// FIXME: implement other array type conversions.
552553
_ => None,

clippy_lints/src/escape.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal {
9595
fn is_argument(map: rustc_middle::hir::map::Map<'_>, id: HirId) -> bool {
9696
match map.find(id) {
9797
Some(Node::Binding(_)) => (),
98-
_ => return false,
98+
Some(_) | None => return false,
9999
}
100100

101101
match map.find(map.get_parent_node(id)) {
102102
Some(Node::Param(_)) => true,
103-
_ => false,
103+
Some(_) | None => false,
104104
}
105105
}
106106

clippy_lints/src/floating_point_arithmetic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ fn is_zero(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
410410
Some(Constant::Int(i)) => i == 0,
411411
Some(Constant::F32(f)) => f == 0.0,
412412
Some(Constant::F64(f)) => f == 0.0,
413-
_ => false,
413+
Some(_) | None => false,
414414
}
415415
}
416416

clippy_lints/src/loops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2154,7 +2154,7 @@ fn is_loop_nested(cx: &LateContext<'_, '_>, loop_expr: &Expr<'_>, iter_expr: &Ex
21542154
}
21552155
},
21562156
Some(Node::Stmt(_)) => (),
2157-
_ => {
2157+
Some(_) | None => {
21582158
return false;
21592159
},
21602160
}

clippy_lints/src/misc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ fn is_allowed<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> boo
509509
Constant::F64(f) => *f == 0.0 || (*f).is_infinite(),
510510
_ => false,
511511
}),
512-
_ => false,
512+
Some(_) | None => false,
513513
}
514514
}
515515

clippy_lints/src/modulo_arithmetic.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct OperandInfo {
3737
}
3838

3939
fn analyze_operand(operand: &Expr<'_>, cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option<OperandInfo> {
40+
#[allow(clippy::match_wildcard_for_single_variants)]
4041
match constant(cx, cx.tables, operand) {
4142
Some((Constant::Int(v), _)) => match cx.tables.expr_ty(expr).kind {
4243
ty::Int(ity) => {

clippy_lints/src/utils/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ pub fn trait_ref_of_method<'tcx>(cx: &LateContext<'_, 'tcx>, hir_id: HirId) -> O
370370

371371
/// Checks whether this type implements `Drop`.
372372
pub fn has_drop<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool {
373+
#[allow(clippy::match_wildcard_for_single_variants)]
373374
match ty.ty_adt_def() {
374375
Some(def) => def.has_dtor(cx.tcx),
375376
_ => false,
@@ -444,6 +445,7 @@ pub fn is_entrypoint_fn(cx: &LateContext<'_, '_>, def_id: DefId) -> bool {
444445
/// Gets the name of the item the expression is in, if available.
445446
pub fn get_item_name(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option<Name> {
446447
let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id);
448+
#[allow(clippy::match_wildcard_for_single_variants)]
447449
match cx.tcx.hir().find(parent_id) {
448450
Some(
449451
Node::Item(Item { ident, .. })

0 commit comments

Comments
 (0)