Skip to content

Commit 2c2d41d

Browse files
committed
make article_and_description primarily use def_kind
1 parent 131772c commit 2c2d41d

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/librustc/ty/context.rs

+15-14
Original file line numberDiff line numberDiff line change
@@ -1515,20 +1515,21 @@ impl<'tcx> TyCtxt<'tcx> {
15151515

15161516
/// Returns a displayable description and article for the given `def_id` (e.g. `("a", "struct")`).
15171517
pub fn article_and_description(&self, def_id: DefId) -> (&'static str, &'static str) {
1518-
match self.def_key(def_id).disambiguated_data.data {
1519-
DefPathData::TypeNs(..) | DefPathData::ValueNs(..) | DefPathData::MacroNs(..) => {
1520-
let kind = self.def_kind(def_id).unwrap();
1521-
(kind.article(), kind.descr(def_id))
1522-
}
1523-
DefPathData::ClosureExpr => match self.generator_kind(def_id) {
1524-
None => ("a", "closure"),
1525-
Some(rustc_hir::GeneratorKind::Async(..)) => ("an", "async closure"),
1526-
Some(rustc_hir::GeneratorKind::Gen) => ("a", "generator"),
1527-
},
1528-
DefPathData::LifetimeNs(..) => ("a", "lifetime"),
1529-
DefPathData::Impl => ("an", "implementation"),
1530-
_ => bug!("article_and_description called on def_id {:?}", def_id),
1531-
}
1518+
self.def_kind(def_id)
1519+
.map(|def_kind| (def_kind.article(), def_kind.descr(def_id)))
1520+
.unwrap_or_else(|| match self.def_key(def_id).disambiguated_data.data {
1521+
DefPathData::ClosureExpr => match self.generator_kind(def_id) {
1522+
None => ("a", "closure"),
1523+
Some(rustc_hir::GeneratorKind::Async(..)) => ("an", "async closure"),
1524+
Some(rustc_hir::GeneratorKind::Gen) => ("a", "generator"),
1525+
},
1526+
DefPathData::LifetimeNs(..) => ("a", "lifetime"),
1527+
DefPathData::Impl => ("an", "implementation"),
1528+
DefPathData::TypeNs(..) | DefPathData::ValueNs(..) | DefPathData::MacroNs(..) => {
1529+
unreachable!()
1530+
}
1531+
_ => bug!("article_and_description called on def_id {:?}", def_id),
1532+
})
15321533
}
15331534
}
15341535

0 commit comments

Comments
 (0)