Skip to content

Commit 1a881a4

Browse files
committed
Introduce opt_ident.
1 parent 64b6c32 commit 1a881a4

File tree

1 file changed

+12
-13
lines changed
  • compiler/rustc_middle/src/hir/map

1 file changed

+12
-13
lines changed

compiler/rustc_middle/src/hir/map/mod.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -910,8 +910,10 @@ impl<'hir> Map<'hir> {
910910
}
911911
}
912912

913-
pub(super) fn opt_ident_span(self, id: HirId) -> Option<Span> {
914-
let ident = match self.get(id) {
913+
#[inline]
914+
fn opt_ident(self, id: HirId) -> Option<Ident> {
915+
match self.get(id) {
916+
Node::Binding(&Pat { kind: PatKind::Binding(_, _, ident, _), .. }) => Some(ident),
915917
// A `Ctor` doesn't have an identifier itself, but its parent
916918
// struct/variant does. Compare with `hir::Map::opt_span`.
917919
Node::Ctor(..) => match self.find(self.get_parent_node(id))? {
@@ -920,20 +922,17 @@ impl<'hir> Map<'hir> {
920922
_ => unreachable!(),
921923
},
922924
node => node.ident(),
923-
};
924-
ident.map(|ident| ident.span)
925+
}
925926
}
926927

928+
#[inline]
929+
pub(super) fn opt_ident_span(self, id: HirId) -> Option<Span> {
930+
self.opt_ident(id).map(|ident| ident.span)
931+
}
932+
933+
#[inline]
927934
pub fn opt_name(self, id: HirId) -> Option<Symbol> {
928-
match self.get(id) {
929-
Node::Binding(&Pat { kind: PatKind::Binding(_, _, l, _), .. }) => Some(l.name),
930-
Node::Ctor(..) => match self.find(self.get_parent_node(id))? {
931-
Node::Item(item) => Some(item.ident.name),
932-
Node::Variant(variant) => Some(variant.ident.name),
933-
_ => unreachable!(),
934-
},
935-
node => node.ident().map(|i| i.name),
936-
}
935+
self.opt_ident(id).map(|ident| ident.name)
937936
}
938937

939938
pub fn name(self, id: HirId) -> Symbol {

0 commit comments

Comments
 (0)