@@ -1986,27 +1986,25 @@ impl<'tcx> TyCtxt<'tcx> {
1986
1986
. filter ( |item| item. kind == AssocKind :: Fn && item. defaultness . has_value ( ) )
1987
1987
}
1988
1988
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 > {
1994
1990
if def_id. index == CRATE_DEF_INDEX {
1995
1991
Some ( self . crate_name ( def_id. krate ) )
1996
1992
} else {
1997
1993
let def_key = self . def_key ( def_id) ;
1998
1994
match def_key. disambiguated_data . data {
1999
1995
// 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 ( ) ,
2005
2003
}
2006
2004
}
2007
2005
}
2008
2006
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.
2010
2008
///
2011
2009
/// When possible, this function should be used for cross-crate lookups over
2012
2010
/// [`opt_item_name`] to avoid invalidating the incremental cache. If you
@@ -2018,18 +2016,21 @@ impl<'tcx> TyCtxt<'tcx> {
2018
2016
pub fn item_name ( self , id : DefId ) -> Symbol {
2019
2017
// Look at cross-crate items first to avoid invalidating the incremental cache
2020
2018
// unless we have to.
2021
- self . item_name_from_def_id ( id) . unwrap_or_else ( || {
2019
+ self . opt_item_name ( id) . unwrap_or_else ( || {
2022
2020
bug ! ( "item_name: no name for {:?}" , self . def_path( id) ) ;
2023
2021
} )
2024
2022
}
2025
2023
2026
- /// Look up the name and span of an item or [`Node`] .
2024
+ /// Look up the name and span of a definition .
2027
2025
///
2028
2026
/// 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) )
2033
2034
}
2034
2035
2035
2036
pub fn opt_associated_item ( self , def_id : DefId ) -> Option < & ' tcx AssocItem > {
0 commit comments