Make use of or_patterns
feature
This commit is contained in:
parent
8fd7e31d1b
commit
548c417ec4
@ -320,7 +320,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
|
||||
fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId, ty: Ty<'cc>) -> Option<Constant> {
|
||||
let res = self.tables.qpath_res(qpath, id);
|
||||
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 = if self.substs.is_empty() {
|
||||
substs
|
||||
|
@ -106,10 +106,8 @@ impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> {
|
||||
ExprKind::Match(ref e, arms, _) => {
|
||||
self.visit_expr(e);
|
||||
for arm in arms {
|
||||
if let Some(ref guard) = arm.guard {
|
||||
match guard {
|
||||
Guard::If(if_expr) => self.visit_expr(if_expr),
|
||||
}
|
||||
if let Some(Guard::If(if_expr)) = arm.guard {
|
||||
self.visit_expr(if_expr)
|
||||
}
|
||||
// make sure top level arm expressions aren't linted
|
||||
self.maybe_walk_expr(&*arm.body);
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#![feature(box_syntax)]
|
||||
#![feature(box_patterns)]
|
||||
#![feature(or_patterns)]
|
||||
#![feature(rustc_private)]
|
||||
#![feature(stmt_expr_attributes)]
|
||||
#![allow(clippy::missing_docs_in_private_items, clippy::must_use_candidate)]
|
||||
|
@ -346,7 +346,7 @@ impl<'v, 't> RefVisitor<'v, 't> {
|
||||
{
|
||||
let hir_id = ty.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);
|
||||
for _ in generics.params.as_slice() {
|
||||
self.record(&None);
|
||||
|
@ -1780,7 +1780,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
|
||||
}
|
||||
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 {
|
||||
self.indexed_indirectly.insert(seqvar.segments[0].ident.name, None);
|
||||
}
|
||||
|
@ -1755,9 +1755,7 @@ fn lint_expect_fun_call(
|
||||
)
|
||||
}),
|
||||
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, _) => {
|
||||
true
|
||||
},
|
||||
hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static, _) => true,
|
||||
_ => false,
|
||||
},
|
||||
_ => false,
|
||||
|
@ -69,7 +69,7 @@ fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
|
||||
if let ExprKind::Path(ref qpath) = callee.kind {
|
||||
let res = qpath_res(cx, qpath, callee.hir_id);
|
||||
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))
|
||||
},
|
||||
_ => false,
|
||||
|
@ -191,7 +191,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst {
|
||||
|
||||
// Make sure it is a const item.
|
||||
match qpath_res(cx, qpath, expr.hir_id) {
|
||||
Res::Def(DefKind::Const, _) | Res::Def(DefKind::AssocConst, _) => {},
|
||||
Res::Def(DefKind::Const | DefKind::AssocConst, _) => {},
|
||||
_ => return,
|
||||
};
|
||||
|
||||
|
@ -315,7 +315,7 @@ pub fn get_trait_def_id(cx: &LateContext<'_, '_>, path: &[&str]) -> Option<DefId
|
||||
};
|
||||
|
||||
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),
|
||||
_ => 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> {
|
||||
let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id);
|
||||
match cx.tcx.hir().find(parent_id) {
|
||||
Some(Node::Item(&Item { ref ident, .. })) => Some(ident.name),
|
||||
Some(Node::TraitItem(&TraitItem { ident, .. })) | Some(Node::ImplItem(&ImplItem { ident, .. })) => {
|
||||
Some(ident.name)
|
||||
},
|
||||
Some(
|
||||
Node::Item(Item { ident, .. })
|
||||
| Node::TraitItem(TraitItem { ident, .. })
|
||||
| Node::ImplItem(ImplItem { ident, .. }),
|
||||
) => Some(ident.name),
|
||||
_ => 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 {
|
||||
let res = cx.tables.qpath_res(qp, fun.hir_id);
|
||||
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),
|
||||
_ => false,
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user