Skip to content

Commit 230e8b9

Browse files
committed
Simplify impl_of_method
1 parent a7a1618 commit 230e8b9

File tree

1 file changed

+4
-14
lines changed
  • compiler/rustc_middle/src/ty

1 file changed

+4
-14
lines changed

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,25 +1992,15 @@ impl<'tcx> TyCtxt<'tcx> {
19921992
/// returns the `DefId` of the trait that the trait item belongs to;
19931993
/// otherwise, returns `None`.
19941994
pub fn trait_of_item(self, def_id: DefId) -> Option<DefId> {
1995-
if let DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy = self.def_kind(def_id) {
1996-
let parent = self.parent(def_id);
1997-
if let DefKind::Trait | DefKind::TraitAlias = self.def_kind(parent) {
1998-
return Some(parent);
1999-
}
2000-
}
2001-
None
1995+
self.opt_parent(def_id)
1996+
.filter(|parent| matches!(self.def_kind(parent), DefKind::Trait | DefKind::TraitAlias))
20021997
}
20031998

20041999
/// If the given `DefId` describes a method belonging to an impl, returns the
20052000
/// `DefId` of the impl that the method belongs to; otherwise, returns `None`.
20062001
pub fn impl_of_method(self, def_id: DefId) -> Option<DefId> {
2007-
if let DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy = self.def_kind(def_id) {
2008-
let parent = self.parent(def_id);
2009-
if let DefKind::Impl { .. } = self.def_kind(parent) {
2010-
return Some(parent);
2011-
}
2012-
}
2013-
None
2002+
self.opt_parent(def_id)
2003+
.filter(|parent| matches!(self.def_kind(parent), DefKind::Impl { .. }))
20142004
}
20152005

20162006
pub fn is_exportable(self, def_id: DefId) -> bool {

0 commit comments

Comments
 (0)