1
Fork 0

use matches!() macro in more places

This commit is contained in:
Matthias Krüger 2020-12-24 02:55:21 +01:00
parent c34c015fe2
commit d12a358673
34 changed files with 138 additions and 270 deletions

View file

@ -23,18 +23,18 @@ use rustc_span::symbol::{sym, Symbol};
// function, then we should explore its block to check for codes that
// may need to be marked as live.
fn should_explore(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool {
match tcx.hir().find(hir_id) {
matches!(
tcx.hir().find(hir_id),
Some(
Node::Item(..)
| Node::ImplItem(..)
| Node::ForeignItem(..)
| Node::TraitItem(..)
| Node::Variant(..)
| Node::AnonConst(..)
| Node::Pat(..),
) => true,
_ => false,
}
| Node::ImplItem(..)
| Node::ForeignItem(..)
| Node::TraitItem(..)
| Node::Variant(..)
| Node::AnonConst(..)
| Node::Pat(..),
)
)
}
struct MarkSymbolVisitor<'tcx> {
@ -500,16 +500,16 @@ struct DeadVisitor<'tcx> {
impl DeadVisitor<'tcx> {
fn should_warn_about_item(&mut self, item: &hir::Item<'_>) -> bool {
let should_warn = match item.kind {
let should_warn = matches!(
item.kind,
hir::ItemKind::Static(..)
| hir::ItemKind::Const(..)
| hir::ItemKind::Fn(..)
| hir::ItemKind::TyAlias(..)
| hir::ItemKind::Enum(..)
| hir::ItemKind::Struct(..)
| hir::ItemKind::Union(..) => true,
_ => false,
};
| hir::ItemKind::Const(..)
| hir::ItemKind::Fn(..)
| hir::ItemKind::TyAlias(..)
| hir::ItemKind::Enum(..)
| hir::ItemKind::Struct(..)
| hir::ItemKind::Union(..)
);
should_warn && !self.symbol_is_live(item.hir_id)
}

View file

@ -367,10 +367,7 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
}
fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) {
let is_shorthand = match param.pat.kind {
rustc_hir::PatKind::Struct(..) => true,
_ => false,
};
let is_shorthand = matches!(param.pat.kind, rustc_hir::PatKind::Struct(..));
param.pat.each_binding(|_bm, hir_id, _x, ident| {
let var = if is_shorthand {
Local(LocalInfo { id: hir_id, name: ident.name, is_shorthand: true })