D3454: Assign to result from block.

kevincox (Kevin Cox) phabricator at mercurial-scm.org
Sun May 6 08:17:40 UTC 2018


kevincox created this revision.
kevincox added a reviewer: indygreg.
Herald added subscribers: mercurial-devel, durin42.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This is more idiomatic because you don't have uninitialized variables and has less typing.

REPOSITORY
  rHG Mercurial

BRANCH
  arcpatch-D3447 (bookmark) on default (branch)

REVISION DETAIL
  https://phab.mercurial-scm.org/D3454

AFFECTED FILES
  rust/hgcli/src/main.rs

CHANGE DETAILS

diff --git a/rust/hgcli/src/main.rs b/rust/hgcli/src/main.rs
--- a/rust/hgcli/src/main.rs
+++ b/rust/hgcli/src/main.rs
@@ -177,8 +177,7 @@
         python27_sys::PySys_SetArgvEx(args.len() as c_int, argv.as_ptr() as *mut *mut i8, 0);
     }
 
-    let result;
-    {
+    let result = {
         // These need to be dropped before we call Py_Finalize(). Hence the
         // block.
         let gil = Python::acquire_gil();
@@ -189,7 +188,7 @@
         // TODO this may cause issues on Windows due to the CRT mismatch.
         // Investigate if we can intercept sys.exit() or SystemExit() to
         // ensure we handle process exit.
-        result = match run_py(&env, py) {
+        match run_py(&env, py) {
             // Print unhandled exceptions and exit code 1, as this is what
             // `python` does.
             Err(err) => {
@@ -205,8 +204,8 @@
                 };
                 Err(code)
             }
-        };
-    }
+        }
+    };
 
     unsafe {
         python27_sys::Py_Finalize();



To: kevincox, indygreg, #hg-reviewers
Cc: durin42, mercurial-devel


More information about the Mercurial-devel mailing list