Make use of or_patterns feature

This commit is contained in:
Philipp Hansch
2020-03-16 07:23:03 +01:00
parent 8fd7e31d1b
commit 548c417ec4
9 changed files with 16 additions and 18 deletions

View File

@@ -320,7 +320,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId, ty: Ty<'cc>) -> Option<Constant> { fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId, ty: Ty<'cc>) -> Option<Constant> {
let res = self.tables.qpath_res(qpath, id); let res = self.tables.qpath_res(qpath, id);
match res { match res {
Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssocConst, def_id) => { Res::Def(DefKind::Const | DefKind::AssocConst, def_id) => {
let substs = self.tables.node_substs(id); let substs = self.tables.node_substs(id);
let substs = if self.substs.is_empty() { let substs = if self.substs.is_empty() {
substs substs

View File

@@ -106,10 +106,8 @@ impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> {
ExprKind::Match(ref e, arms, _) => { ExprKind::Match(ref e, arms, _) => {
self.visit_expr(e); self.visit_expr(e);
for arm in arms { for arm in arms {
if let Some(ref guard) = arm.guard { if let Some(Guard::If(if_expr)) = arm.guard {
match guard { self.visit_expr(if_expr)
Guard::If(if_expr) => self.visit_expr(if_expr),
}
} }
// make sure top level arm expressions aren't linted // make sure top level arm expressions aren't linted
self.maybe_walk_expr(&*arm.body); self.maybe_walk_expr(&*arm.body);

View File

@@ -2,6 +2,7 @@
#![feature(box_syntax)] #![feature(box_syntax)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(or_patterns)]
#![feature(rustc_private)] #![feature(rustc_private)]
#![feature(stmt_expr_attributes)] #![feature(stmt_expr_attributes)]
#![allow(clippy::missing_docs_in_private_items, clippy::must_use_candidate)] #![allow(clippy::missing_docs_in_private_items, clippy::must_use_candidate)]

View File

@@ -346,7 +346,7 @@ impl<'v, 't> RefVisitor<'v, 't> {
{ {
let hir_id = ty.hir_id; let hir_id = ty.hir_id;
match self.cx.tables.qpath_res(qpath, hir_id) { match self.cx.tables.qpath_res(qpath, hir_id) {
Res::Def(DefKind::TyAlias, def_id) | Res::Def(DefKind::Struct, def_id) => { Res::Def(DefKind::TyAlias | DefKind::Struct, def_id) => {
let generics = self.cx.tcx.generics_of(def_id); let generics = self.cx.tcx.generics_of(def_id);
for _ in generics.params.as_slice() { for _ in generics.params.as_slice() {
self.record(&None); self.record(&None);

View File

@@ -1780,7 +1780,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
} }
return false; // no need to walk further *on the variable* return false; // no need to walk further *on the variable*
} }
Res::Def(DefKind::Static, ..) | Res::Def(DefKind::Const, ..) => { Res::Def(DefKind::Static | DefKind::Const, ..) => {
if indexed_indirectly { if indexed_indirectly {
self.indexed_indirectly.insert(seqvar.segments[0].ident.name, None); self.indexed_indirectly.insert(seqvar.segments[0].ident.name, None);
} }

View File

@@ -1755,9 +1755,7 @@ fn lint_expect_fun_call(
) )
}), }),
hir::ExprKind::Path(ref p) => match cx.tables.qpath_res(p, arg.hir_id) { hir::ExprKind::Path(ref p) => match cx.tables.qpath_res(p, arg.hir_id) {
hir::def::Res::Def(hir::def::DefKind::Const, _) | hir::def::Res::Def(hir::def::DefKind::Static, _) => { hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static, _) => true,
true
},
_ => false, _ => false,
}, },
_ => false, _ => false,

View File

@@ -69,7 +69,7 @@ fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
if let ExprKind::Path(ref qpath) = callee.kind { if let ExprKind::Path(ref qpath) = callee.kind {
let res = qpath_res(cx, qpath, callee.hir_id); let res = qpath_res(cx, qpath, callee.hir_id);
match res { match res {
Res::Def(DefKind::Struct, ..) | Res::Def(DefKind::Variant, ..) | Res::Def(DefKind::Ctor(..), _) => { Res::Def(DefKind::Struct | DefKind::Variant | DefKind::Ctor(..), ..) => {
!has_drop(cx, cx.tables.expr_ty(expr)) && args.iter().all(|arg| has_no_effect(cx, arg)) !has_drop(cx, cx.tables.expr_ty(expr)) && args.iter().all(|arg| has_no_effect(cx, arg))
}, },
_ => false, _ => false,

View File

@@ -191,7 +191,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst {
// Make sure it is a const item. // Make sure it is a const item.
match qpath_res(cx, qpath, expr.hir_id) { match qpath_res(cx, qpath, expr.hir_id) {
Res::Def(DefKind::Const, _) | Res::Def(DefKind::AssocConst, _) => {}, Res::Def(DefKind::Const | DefKind::AssocConst, _) => {},
_ => return, _ => return,
}; };

View File

@@ -315,7 +315,7 @@ pub fn get_trait_def_id(cx: &LateContext<'_, '_>, path: &[&str]) -> Option<DefId
}; };
match res { match res {
Res::Def(DefKind::Trait, trait_id) | Res::Def(DefKind::TraitAlias, trait_id) => Some(trait_id), Res::Def(DefKind::Trait | DefKind::TraitAlias, trait_id) => Some(trait_id),
Res::Err => unreachable!("this trait resolution is impossible: {:?}", &path), Res::Err => unreachable!("this trait resolution is impossible: {:?}", &path),
_ => None, _ => None,
} }
@@ -448,10 +448,11 @@ pub fn is_entrypoint_fn(cx: &LateContext<'_, '_>, def_id: DefId) -> bool {
pub fn get_item_name(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option<Name> { pub fn get_item_name(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option<Name> {
let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id); let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id);
match cx.tcx.hir().find(parent_id) { match cx.tcx.hir().find(parent_id) {
Some(Node::Item(&Item { ref ident, .. })) => Some(ident.name), Some(
Some(Node::TraitItem(&TraitItem { ident, .. })) | Some(Node::ImplItem(&ImplItem { ident, .. })) => { Node::Item(Item { ident, .. })
Some(ident.name) | Node::TraitItem(TraitItem { ident, .. })
}, | Node::ImplItem(ImplItem { ident, .. }),
) => Some(ident.name),
_ => None, _ => None,
} }
} }
@@ -925,7 +926,7 @@ pub fn is_ctor_or_promotable_const_function(cx: &LateContext<'_, '_>, expr: &Exp
if let ExprKind::Path(ref qp) = fun.kind { if let ExprKind::Path(ref qp) = fun.kind {
let res = cx.tables.qpath_res(qp, fun.hir_id); let res = cx.tables.qpath_res(qp, fun.hir_id);
return match res { return match res {
def::Res::Def(DefKind::Variant, ..) | Res::Def(DefKind::Ctor(..), _) => true, def::Res::Def(DefKind::Variant | DefKind::Ctor(..), ..) => true,
def::Res::Def(_, def_id) => cx.tcx.is_promotable_const_fn(def_id), def::Res::Def(_, def_id) => cx.tcx.is_promotable_const_fn(def_id),
_ => false, _ => false,
}; };