changeset 53171:aedbc69082a0

rust-annotate: change FileId let-else to match This changes all the let-else statements on FileId to instead use an exhaustive match to make it more clear that the "else" case is Wdir.
author Mitchell Kember <mkember@janestreet.com>
date Mon, 07 Apr 2025 15:34:41 -0400
parents 04bc2087a7e5
children 54e7fb504f88
files rust/hg-core/src/operations/annotate.rs
diffstat 1 files changed, 26 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/operations/annotate.rs	Mon Apr 07 13:12:54 2025 -0400
+++ b/rust/hg-core/src/operations/annotate.rs	Mon Apr 07 15:34:41 2025 -0400
@@ -272,21 +272,25 @@
         follow_copies: bool,
     ) -> Result<(Vec<FileId>, Option<Vec<u8>>), HgError> {
         let mut parents = Vec::<FileId>::with_capacity(2);
-        let FileId::Rev(id) = id else {
-            // If a file in the working directory is copied/renamed, its parent
-            // is the copy source (just as it will be after committing).
-            let path = state
-                .dirstate_map()
-                .copy_map_get(base_path)?
-                .unwrap_or(base_path);
-            for rev in state.dirstate_parents() {
-                if let Some(id) =
-                    self.open_at_changelog_rev(state, path, rev)?
-                {
-                    parents.push(FileId::Rev(id));
+        let id = match id {
+            FileId::Rev(id) => id,
+            FileId::Wdir => {
+                // If a file in the working directory is copied/renamed, its
+                // parent is the copy source (just as it will be after
+                // committing).
+                let path = state
+                    .dirstate_map()
+                    .copy_map_get(base_path)?
+                    .unwrap_or(base_path);
+                for rev in state.dirstate_parents() {
+                    if let Some(id) =
+                        self.open_at_changelog_rev(state, path, rev)?
+                    {
+                        parents.push(FileId::Rev(id));
+                    }
                 }
+                return Ok((parents, None));
             }
-            return Ok((parents, None));
         };
         let filelog = &self.get(id.index).filelog;
         let revisions =
@@ -441,8 +445,9 @@
     graph.0.par_iter_mut().try_for_each(
         |(&id, info)| -> Result<(), HgError> {
             if let AnnotatedFileState::None = info.file {
-                let FileId::Rev(id) = id else {
-                    unreachable!("only the base file can be wdir");
+                let id = match id {
+                    FileId::Rev(id) => id,
+                    FileId::Wdir => unreachable!("only base file can be wdir"),
                 };
                 info.file = AnnotatedFileState::Read(OwnedLines::split(
                     fls.read(id)?,
@@ -629,8 +634,9 @@
     id: FileId,
     ancestors: &mut AncestorsIterator<&Changelog>,
 ) -> Result<Option<RevisionOrWdir>, HgError> {
-    let FileId::Rev(id) = id else {
-        return Ok(Some(RevisionOrWdir::wdir()));
+    let id = match id {
+        FileId::Rev(id) => id,
+        FileId::Wdir => return Ok(Some(RevisionOrWdir::wdir())),
     };
     let FilelogSetItem { filelog, .. } = fls.get(id.index);
     let linkrev = filelog
@@ -650,8 +656,9 @@
     descendant: RevisionOrWdir,
     id: FileId,
 ) -> Result<RevisionOrWdir, HgError> {
-    let FileId::Rev(id) = id else {
-        return Ok(RevisionOrWdir::wdir());
+    let id = match id {
+        FileId::Rev(id) => id,
+        FileId::Wdir => return Ok(RevisionOrWdir::wdir()),
     };
     let FilelogSetItem { filelog, path } = fls.get(id.index);
     let linkrev = filelog