@@ -231,8 +231,7 @@ impl<'hir> Map<'hir> {
231231 }
232232
233233 pub fn opt_def_kind ( & self , local_def_id : LocalDefId ) -> Option < DefKind > {
234- let hir_id = self . local_def_id_to_hir_id ( local_def_id) ;
235- let def_kind = match self . find ( hir_id) ? {
234+ let def_kind = match self . find_by_def_id ( local_def_id) ? {
236235 Node :: Item ( item) => match item. kind {
237236 ItemKind :: Static ( ..) => DefKind :: Static ,
238237 ItemKind :: Const ( ..) => DefKind :: Const ,
@@ -272,6 +271,7 @@ impl<'hir> Map<'hir> {
272271 // FIXME(eddyb) is this even possible, if we have a `Node::Ctor`?
273272 assert_ne ! ( variant_data. ctor_hir_id( ) , None ) ;
274273
274+ let hir_id = self . local_def_id_to_hir_id ( local_def_id) ;
275275 let ctor_of = match self . find ( self . get_parent_node ( hir_id) ) {
276276 Some ( Node :: Item ( ..) ) => def:: CtorOf :: Struct ,
277277 Some ( Node :: Variant ( ..) ) => def:: CtorOf :: Variant ,
@@ -280,6 +280,7 @@ impl<'hir> Map<'hir> {
280280 DefKind :: Ctor ( ctor_of, def:: CtorKind :: from_hir ( variant_data) )
281281 }
282282 Node :: AnonConst ( _) => {
283+ let hir_id = self . local_def_id_to_hir_id ( local_def_id) ;
283284 let inline = match self . find ( self . get_parent_node ( hir_id) ) {
284285 Some ( Node :: Expr ( & Expr {
285286 kind : ExprKind :: ConstBlock ( ref anon_const) , ..
@@ -292,7 +293,10 @@ impl<'hir> Map<'hir> {
292293 Node :: Expr ( expr) => match expr. kind {
293294 ExprKind :: Closure ( .., None ) => DefKind :: Closure ,
294295 ExprKind :: Closure ( .., Some ( _) ) => DefKind :: Generator ,
295- _ => bug ! ( "def_kind: unsupported node: {}" , self . node_to_string( hir_id) ) ,
296+ _ => {
297+ let hir_id = self . local_def_id_to_hir_id ( local_def_id) ;
298+ bug ! ( "def_kind: unsupported node: {}" , self . node_to_string( hir_id) )
299+ }
296300 } ,
297301 Node :: GenericParam ( param) => match param. kind {
298302 GenericParamKind :: Lifetime { .. } => DefKind :: LifetimeParam ,
@@ -352,7 +356,12 @@ impl<'hir> Map<'hir> {
352356 /// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found.
353357 #[ inline]
354358 pub fn find_by_def_id ( & self , id : LocalDefId ) -> Option < Node < ' hir > > {
355- self . find ( self . local_def_id_to_hir_id ( id) )
359+ let owner = self . tcx . hir_owner ( id) ;
360+ match owner {
361+ MaybeOwner :: Owner ( o) => Some ( o. node . into ( ) ) ,
362+ MaybeOwner :: NonOwner ( hir_id) => self . find ( hir_id) ,
363+ MaybeOwner :: Phantom => bug ! ( "No HirId for {:?}" , id) ,
364+ }
356365 }
357366
358367 /// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
@@ -367,7 +376,7 @@ impl<'hir> Map<'hir> {
367376 }
368377
369378 pub fn get_if_local ( & self , id : DefId ) -> Option < Node < ' hir > > {
370- id. as_local ( ) . and_then ( |id| self . find ( self . local_def_id_to_hir_id ( id ) ) )
379+ id. as_local ( ) . and_then ( |id| self . find_by_def_id ( id ) )
371380 }
372381
373382 pub fn get_generics ( & self , id : LocalDefId ) -> Option < & ' hir Generics < ' hir > > {
0 commit comments