Skip to content

Commit

Permalink
Fix cases of match_wildcard_for_single_variants lint when it is spann…
Browse files Browse the repository at this point in the history
…ed on Option
  • Loading branch information
vtmargaryan committed May 14, 2020
1 parent 0ad9f7d commit 4948307
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 9 deletions.
9 changes: 5 additions & 4 deletions clippy_lints/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ impl Constant {
.find(|r| r.map_or(true, |o| o != Ordering::Equal))
.unwrap_or_else(|| Some(l.len().cmp(&r.len()))),
(&Self::Repeat(ref lv, ref ls), &Self::Repeat(ref rv, ref rs)) => {
#[allow(clippy::match_wildcard_for_single_variants)]
match Self::partial_cmp(tcx, cmp_type, lv, rv) {
Some(Equal) => Some(ls.cmp(rs)),
x => x,
Expand Down Expand Up @@ -354,14 +355,14 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
(Some(Constant::Vec(vec)), Some(Constant::Int(index))) => match vec.get(index as usize) {
Some(Constant::F32(x)) => Some(Constant::F32(*x)),
Some(Constant::F64(x)) => Some(Constant::F64(*x)),
_ => None,
Some(_) | None => None,
},
(Some(Constant::Vec(vec)), _) => {
if !vec.is_empty() && vec.iter().all(|x| *x == vec[0]) {
match vec.get(0) {
Some(Constant::F32(x)) => Some(Constant::F32(*x)),
Some(Constant::F64(x)) => Some(Constant::F64(*x)),
_ => None,
Some(_) | None => None,
}
} else {
None
Expand Down Expand Up @@ -532,7 +533,7 @@ pub fn miri_to_const(result: &ty::Const<'_>) -> Option<Constant> {
})
.collect::<Option<Vec<Constant>>>()
.map(Constant::Vec),
_ => None,
Some(_) | None => None,
},
ty::Float(FloatTy::F64) => match miri_to_const(len) {
Some(Constant::Int(len)) => alloc
Expand All @@ -546,7 +547,7 @@ pub fn miri_to_const(result: &ty::Const<'_>) -> Option<Constant> {
})
.collect::<Option<Vec<Constant>>>()
.map(Constant::Vec),
_ => None,
Some(_) | None => None,
},
// FIXME: implement other array type conversions.
_ => None,
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal {
fn is_argument(map: rustc_middle::hir::map::Map<'_>, id: HirId) -> bool {
match map.find(id) {
Some(Node::Binding(_)) => (),
_ => return false,
Some(_) | None => return false,
}

match map.find(map.get_parent_node(id)) {
Some(Node::Param(_)) => true,
_ => false,
Some(_) | None => false,
}
}

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/floating_point_arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ fn is_zero(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
Some(Constant::Int(i)) => i == 0,
Some(Constant::F32(f)) => f == 0.0,
Some(Constant::F64(f)) => f == 0.0,
_ => false,
Some(_) | None => false,
}
}

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2154,7 +2154,7 @@ fn is_loop_nested(cx: &LateContext<'_, '_>, loop_expr: &Expr<'_>, iter_expr: &Ex
}
},
Some(Node::Stmt(_)) => (),
_ => {
Some(_) | None => {
return false;
},
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ fn is_allowed<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> boo
Constant::F64(f) => *f == 0.0 || (*f).is_infinite(),
_ => false,
}),
_ => false,
Some(_) | None => false,
}
}

Expand Down
1 change: 1 addition & 0 deletions clippy_lints/src/modulo_arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct OperandInfo {
}

fn analyze_operand(operand: &Expr<'_>, cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option<OperandInfo> {
#[allow(clippy::match_wildcard_for_single_variants)]
match constant(cx, cx.tables, operand) {
Some((Constant::Int(v), _)) => match cx.tables.expr_ty(expr).kind {
ty::Int(ity) => {
Expand Down
2 changes: 2 additions & 0 deletions clippy_lints/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ pub fn trait_ref_of_method<'tcx>(cx: &LateContext<'_, 'tcx>, hir_id: HirId) -> O

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

0 comments on commit 4948307

Please sign in to comment.