about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <huyuumi.dev@gmail.com>2021-03-23 10:15:42 +0900
committerGitHub <noreply@github.com>2021-03-23 10:15:42 +0900
commit20006b1891dbacb974dbe73af6c98c751b4dfcdb (patch)
tree6a7beb3688984159bf539c42025a3b2d13e25e7e
parenta34cc6bbabefbc8e5dee9343f770b61016d4c6af (diff)
parentf820fd2bc05afa4f5a7d6003c2c847bf85725cca (diff)
downloadrust-20006b1891dbacb974dbe73af6c98c751b4dfcdb.tar.gz
rust-20006b1891dbacb974dbe73af6c98c751b4dfcdb.zip
Rollup merge of #83356 - camelid:rustdoc-option-to-enum, r=GuillaumeGomez
rustdoc: Replace pair of `Option`s with an enum

They are never both `None` or both `Some`, so it makes more sense to use
an enum so that we "make impossible states impossible".
-rw-r--r--src/librustdoc/html/markdown.rs19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs
index 1505fe0369d..b39f9f87892 100644
--- a/src/librustdoc/html/markdown.rs
+++ b/src/librustdoc/html/markdown.rs
@@ -690,25 +690,29 @@ crate fn find_testable_code<T: doctest::Tester>(
 }
 
 crate struct ExtraInfo<'tcx> {
-    hir_id: Option<HirId>,
-    item_did: Option<DefId>,
+    id: ExtraInfoId,
     sp: Span,
     tcx: TyCtxt<'tcx>,
 }
 
+enum ExtraInfoId {
+    Hir(HirId),
+    Def(DefId),
+}
+
 impl<'tcx> ExtraInfo<'tcx> {
     crate fn new(tcx: TyCtxt<'tcx>, hir_id: HirId, sp: Span) -> ExtraInfo<'tcx> {
-        ExtraInfo { hir_id: Some(hir_id), item_did: None, sp, tcx }
+        ExtraInfo { id: ExtraInfoId::Hir(hir_id), sp, tcx }
     }
 
     crate fn new_did(tcx: TyCtxt<'tcx>, did: DefId, sp: Span) -> ExtraInfo<'tcx> {
-        ExtraInfo { hir_id: None, item_did: Some(did), sp, tcx }
+        ExtraInfo { id: ExtraInfoId::Def(did), sp, tcx }
     }
 
     fn error_invalid_codeblock_attr(&self, msg: &str, help: &str) {
-        let hir_id = match (self.hir_id, self.item_did) {
-            (Some(h), _) => h,
-            (None, Some(item_did)) => {
+        let hir_id = match self.id {
+            ExtraInfoId::Hir(hir_id) => hir_id,
+            ExtraInfoId::Def(item_did) => {
                 match item_did.as_local() {
                     Some(item_did) => self.tcx.hir().local_def_id_to_hir_id(item_did),
                     None => {
@@ -717,7 +721,6 @@ impl<'tcx> ExtraInfo<'tcx> {
                     }
                 }
             }
-            (None, None) => return,
         };
         self.tcx.struct_span_lint_hir(
             crate::lint::INVALID_CODEBLOCK_ATTRIBUTES,