diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-03-16 13:16:45 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-16 13:16:45 +0100 |
| commit | d8dbb3c0413afe1cad58515295273c89d82176e5 (patch) | |
| tree | c094dea10880b240fb45bf36cb8f4905edfdb2fa | |
| parent | 8872d9057230e46f4bf35af5880cc6095a06e744 (diff) | |
| parent | 2c2d41dc000714ed3b8b734e608862ff6c74a8d4 (diff) | |
| download | rust-d8dbb3c0413afe1cad58515295273c89d82176e5.tar.gz rust-d8dbb3c0413afe1cad58515295273c89d82176e5.zip | |
Rollup merge of #70036 - mark-i-m:describe-it-4, r=eddyb
Make article_and_description primarily use def_kind r? @eddyb cc @matthewjasper
| -rw-r--r-- | src/librustc/ty/context.rs | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 611a2dc20b4..d6f6788697c 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -1520,20 +1520,21 @@ impl<'tcx> TyCtxt<'tcx> { /// Returns a displayable description and article for the given `def_id` (e.g. `("a", "struct")`). pub fn article_and_description(&self, def_id: DefId) -> (&'static str, &'static str) { - match self.def_key(def_id).disambiguated_data.data { - DefPathData::TypeNs(..) | DefPathData::ValueNs(..) | DefPathData::MacroNs(..) => { - let kind = self.def_kind(def_id).unwrap(); - (kind.article(), kind.descr(def_id)) - } - DefPathData::ClosureExpr => match self.generator_kind(def_id) { - None => ("a", "closure"), - Some(rustc_hir::GeneratorKind::Async(..)) => ("an", "async closure"), - Some(rustc_hir::GeneratorKind::Gen) => ("a", "generator"), - }, - DefPathData::LifetimeNs(..) => ("a", "lifetime"), - DefPathData::Impl => ("an", "implementation"), - _ => bug!("article_and_description called on def_id {:?}", def_id), - } + self.def_kind(def_id) + .map(|def_kind| (def_kind.article(), def_kind.descr(def_id))) + .unwrap_or_else(|| match self.def_key(def_id).disambiguated_data.data { + DefPathData::ClosureExpr => match self.generator_kind(def_id) { + None => ("a", "closure"), + Some(rustc_hir::GeneratorKind::Async(..)) => ("an", "async closure"), + Some(rustc_hir::GeneratorKind::Gen) => ("a", "generator"), + }, + DefPathData::LifetimeNs(..) => ("a", "lifetime"), + DefPathData::Impl => ("an", "implementation"), + DefPathData::TypeNs(..) | DefPathData::ValueNs(..) | DefPathData::MacroNs(..) => { + unreachable!() + } + _ => bug!("article_and_description called on def_id {:?}", def_id), + }) } } |
