@@ -1520,20 +1520,21 @@ impl<'tcx> TyCtxt<'tcx> {
15201520
15211521 /// Returns a displayable description and article for the given `def_id` (e.g. `("a", "struct")`).
15221522 pub fn article_and_description ( & self , def_id : DefId ) -> ( & ' static str , & ' static str ) {
1523- match self . def_key ( def_id) . disambiguated_data . data {
1524- DefPathData :: TypeNs ( ..) | DefPathData :: ValueNs ( ..) | DefPathData :: MacroNs ( ..) => {
1525- let kind = self . def_kind ( def_id) . unwrap ( ) ;
1526- ( kind. article ( ) , kind. descr ( def_id) )
1527- }
1528- DefPathData :: ClosureExpr => match self . generator_kind ( def_id) {
1529- None => ( "a" , "closure" ) ,
1530- Some ( rustc_hir:: GeneratorKind :: Async ( ..) ) => ( "an" , "async closure" ) ,
1531- Some ( rustc_hir:: GeneratorKind :: Gen ) => ( "a" , "generator" ) ,
1532- } ,
1533- DefPathData :: LifetimeNs ( ..) => ( "a" , "lifetime" ) ,
1534- DefPathData :: Impl => ( "an" , "implementation" ) ,
1535- _ => bug ! ( "article_and_description called on def_id {:?}" , def_id) ,
1536- }
1523+ self . def_kind ( def_id)
1524+ . map ( |def_kind| ( def_kind. article ( ) , def_kind. descr ( def_id) ) )
1525+ . unwrap_or_else ( || match self . def_key ( def_id) . disambiguated_data . data {
1526+ DefPathData :: ClosureExpr => match self . generator_kind ( def_id) {
1527+ None => ( "a" , "closure" ) ,
1528+ Some ( rustc_hir:: GeneratorKind :: Async ( ..) ) => ( "an" , "async closure" ) ,
1529+ Some ( rustc_hir:: GeneratorKind :: Gen ) => ( "a" , "generator" ) ,
1530+ } ,
1531+ DefPathData :: LifetimeNs ( ..) => ( "a" , "lifetime" ) ,
1532+ DefPathData :: Impl => ( "an" , "implementation" ) ,
1533+ DefPathData :: TypeNs ( ..) | DefPathData :: ValueNs ( ..) | DefPathData :: MacroNs ( ..) => {
1534+ unreachable ! ( )
1535+ }
1536+ _ => bug ! ( "article_and_description called on def_id {:?}" , def_id) ,
1537+ } )
15371538 }
15381539}
15391540
0 commit comments