Skip to content

Commit 9ced8dc

Browse files
authored
Rollup merge of rust-lang#79826 - LingMan:match_if, r=lcnr
Simplify visit_{foreign,trait}_item Using an `if` seems like a better semantic fit and saves a few lines. Noticed while looking at rust-lang#79752, but that's already merged. r? `@lcnr,` cc `@cjgillot` `@rustbot` modify labels +C-cleanup +T-compiler
2 parents 666d1a8 + 7654b12 commit 9ced8dc

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

compiler/rustc_passes/src/dead.rs

+10-20
Original file line numberDiff line numberDiff line change
@@ -423,15 +423,11 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
423423
}
424424

425425
fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) {
426-
match trait_item.kind {
427-
hir::TraitItemKind::Const(_, Some(_))
428-
| hir::TraitItemKind::Fn(_, hir::TraitFn::Provided(_)) => {
429-
if has_allow_dead_code_or_lang_attr(self.tcx, trait_item.hir_id, &trait_item.attrs)
430-
{
431-
self.worklist.push(trait_item.hir_id);
432-
}
433-
}
434-
_ => {}
426+
use hir::TraitItemKind::{Const, Fn};
427+
if matches!(trait_item.kind, Const(_, Some(_)) | Fn(_, hir::TraitFn::Provided(_)))
428+
&& has_allow_dead_code_or_lang_attr(self.tcx, trait_item.hir_id, &trait_item.attrs)
429+
{
430+
self.worklist.push(trait_item.hir_id);
435431
}
436432
}
437433

@@ -440,17 +436,11 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
440436
}
441437

442438
fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) {
443-
match foreign_item.kind {
444-
hir::ForeignItemKind::Static(..) | hir::ForeignItemKind::Fn(..) => {
445-
if has_allow_dead_code_or_lang_attr(
446-
self.tcx,
447-
foreign_item.hir_id,
448-
&foreign_item.attrs,
449-
) {
450-
self.worklist.push(foreign_item.hir_id);
451-
}
452-
}
453-
_ => {}
439+
use hir::ForeignItemKind::{Fn, Static};
440+
if matches!(foreign_item.kind, Static(..) | Fn(..))
441+
&& has_allow_dead_code_or_lang_attr(self.tcx, foreign_item.hir_id, &foreign_item.attrs)
442+
{
443+
self.worklist.push(foreign_item.hir_id);
454444
}
455445
}
456446
}

0 commit comments

Comments
 (0)