Patchwork [2,of,2] rust: leverage .expect() in place of .unwrap() + inline comment

login
register
mail settings
Submitter Yuya Nishihara
Date May 25, 2020, 2:27 p.m.
Message ID <a5b88a7c25d3d8a02cbb.1590416861@mimosa>
Download mbox | patch
Permalink /patch/46372/
State Accepted
Headers show

Comments

Yuya Nishihara - May 25, 2020, 2:27 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1590415610 -32400
#      Mon May 25 23:06:50 2020 +0900
# Node ID a5b88a7c25d3d8a02cbb2c1b9293200ddb0e06ac
# Parent  261fbbdabb261a44c0f82537f10abbcc0d85ace1
rust: leverage .expect() in place of .unwrap() + inline comment

For a better error indication in case we made a mistake.
Augie Fackler - June 3, 2020, 1:50 a.m.
On Mon, May 25, 2020 at 11:27:41PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1590415610 -32400
> #      Mon May 25 23:06:50 2020 +0900
> # Node ID a5b88a7c25d3d8a02cbb2c1b9293200ddb0e06ac
> # Parent  261fbbdabb261a44c0f82537f10abbcc0d85ace1
> rust: leverage .expect() in place of .unwrap() + inline comment

queued, thanks

Patch

diff --git a/rust/hg-core/src/dirstate/status.rs b/rust/hg-core/src/dirstate/status.rs
--- a/rust/hg-core/src/dirstate/status.rs
+++ b/rust/hg-core/src/dirstate/status.rs
@@ -257,11 +257,9 @@  fn walk_explicit<'a>(
                     } else {
                         if file_type.is_dir() {
                             if options.collect_traversed_dirs {
-                                // The receiver always outlives the sender,
-                                // so unwrap.
                                 traversed_sender
                                     .send(normalized.to_owned())
-                                    .unwrap()
+                                    .expect("receiver should outlive sender");
                             }
                             Some(Ok((
                                 normalized,
@@ -471,8 +469,9 @@  fn traverse_dir<'a>(
     let directory = directory.as_ref();
 
     if options.collect_traversed_dirs {
-        // The receiver always outlives the sender, so unwrap.
-        traversed_sender.send(directory.to_owned()).unwrap()
+        traversed_sender
+            .send(directory.to_owned())
+            .expect("receiver should outlive sender");
     }
 
     let visit_entries = match matcher.visit_children_set(directory) {