Fix cases of match_wildcard_for_single_variants lint when it is spanned on Option

This commit is contained in:
Vardan Margaryan 2020-05-10 18:34:29 +03:00
parent 0ad9f7d651
commit 4948307977
7 changed files with 13 additions and 9 deletions

View file

@ -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,
@ -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
@ -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
@ -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,

View file

@ -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,
}
}

View file

@ -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,
}
}

View file

@ -2154,7 +2154,7 @@ fn is_loop_nested(cx: &LateContext<'_, '_>, loop_expr: &Expr<'_>, iter_expr: &Ex
}
},
Some(Node::Stmt(_)) => (),
_ => {
Some(_) | None => {
return false;
},
}

View file

@ -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,
}
}

View file

@ -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) => {

View file

@ -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,
@ -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, .. })