@@ -1986,27 +1986,25 @@ impl<'tcx> TyCtxt<'tcx> {
19861986 . filter ( |item| item. kind == AssocKind :: Fn && item. defaultness . has_value ( ) )
19871987 }
19881988
1989- fn item_name_from_hir ( self , def_id : DefId ) -> Option < Ident > {
1990- self . hir ( ) . get_if_local ( def_id) . and_then ( |node| node. ident ( ) )
1991- }
1992-
1993- fn item_name_from_def_id ( self , def_id : DefId ) -> Option < Symbol > {
1989+ fn opt_item_name ( self , def_id : DefId ) -> Option < Symbol > {
19941990 if def_id. index == CRATE_DEF_INDEX {
19951991 Some ( self . crate_name ( def_id. krate ) )
19961992 } else {
19971993 let def_key = self . def_key ( def_id) ;
19981994 match def_key. disambiguated_data . data {
19991995 // The name of a constructor is that of its parent.
2000- rustc_hir:: definitions:: DefPathData :: Ctor => self . item_name_from_def_id ( DefId {
2001- krate : def_id. krate ,
2002- index : def_key. parent . unwrap ( ) ,
2003- } ) ,
2004- _ => def_key. disambiguated_data . data . get_opt_name ( ) ,
1996+ rustc_hir:: definitions:: DefPathData :: Ctor => self
1997+ . opt_item_name ( DefId { krate : def_id. krate , index : def_key. parent . unwrap ( ) } ) ,
1998+ // The name of opaque types only exists in HIR.
1999+ rustc_hir:: definitions:: DefPathData :: ImplTrait
2000+ if let Some ( def_id) = def_id. as_local ( ) =>
2001+ self . hir ( ) . opt_name ( self . hir ( ) . local_def_id_to_hir_id ( def_id) ) ,
2002+ _ => def_key. get_opt_name ( ) ,
20052003 }
20062004 }
20072005 }
20082006
2009- /// Look up the name of an item across crates. This does not look at HIR.
2007+ /// Look up the name of a definition across crates. This does not look at HIR.
20102008 ///
20112009 /// When possible, this function should be used for cross-crate lookups over
20122010 /// [`opt_item_name`] to avoid invalidating the incremental cache. If you
@@ -2018,18 +2016,21 @@ impl<'tcx> TyCtxt<'tcx> {
20182016 pub fn item_name ( self , id : DefId ) -> Symbol {
20192017 // Look at cross-crate items first to avoid invalidating the incremental cache
20202018 // unless we have to.
2021- self . item_name_from_def_id ( id) . unwrap_or_else ( || {
2019+ self . opt_item_name ( id) . unwrap_or_else ( || {
20222020 bug ! ( "item_name: no name for {:?}" , self . def_path( id) ) ;
20232021 } )
20242022 }
20252023
2026- /// Look up the name and span of an item or [`Node`] .
2024+ /// Look up the name and span of a definition .
20272025 ///
20282026 /// See [`item_name`][Self::item_name] for more information.
2029- pub fn opt_item_name ( self , def_id : DefId ) -> Option < Ident > {
2030- // Look at the HIR first so the span will be correct if this is a local item.
2031- self . item_name_from_hir ( def_id)
2032- . or_else ( || self . item_name_from_def_id ( def_id) . map ( Ident :: with_dummy_span) )
2027+ pub fn opt_item_ident ( self , def_id : DefId ) -> Option < Ident > {
2028+ let def = self . opt_item_name ( def_id) ?;
2029+ let span = def_id
2030+ . as_local ( )
2031+ . and_then ( |id| self . def_ident_span ( id) )
2032+ . unwrap_or ( rustc_span:: DUMMY_SP ) ;
2033+ Some ( Ident :: new ( def, span) )
20332034 }
20342035
20352036 pub fn opt_associated_item ( self , def_id : DefId ) -> Option < & ' tcx AssocItem > {
0 commit comments