Bug 1497356 - make NsresultExt.to_result() return Result<(), nsresult> r=froydnj
authorMyk Melez <myk@mykzilla.org>
Mon, 29 Oct 2018 22:35:23 +0000
changeset 502668 54f29ffc8f71f66f765a1e44284db4e936e1e972
parent 502667 9de1bee6adc25d2559d9adec09458b8fb866eb1e
child 502669 19bab79602bd40e59b6c92f1f500e2779b88c0f3
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1497356
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1497356 - make NsresultExt.to_result() return Result<(), nsresult> r=froydnj NsresultExt.to_result() is called by Rust code, so it would be more idiomatic for it to return Result<(), nsresult>, i.e. to return Ok(()) when the nsresult is NS_OK. This change makes it do so. MozReview-Commit-ID: EaMEKfonHhC Differential Revision: https://phabricator.services.mozilla.com/D10127
xpcom/rust/nserror/src/lib.rs
--- a/xpcom/rust/nserror/src/lib.rs
+++ b/xpcom/rust/nserror/src/lib.rs
@@ -9,37 +9,37 @@ use nsstring::{nsCString, nsACString};
 #[allow(non_camel_case_types)]
 #[derive(Clone, Copy, Debug)]
 pub struct nsresult(pub u32);
 
 /// An extension trait that adds methods to `nsresult` types.
 pub trait NsresultExt {
     fn failed(self) -> bool;
     fn succeeded(self) -> bool;
-    fn to_result(self) -> Result<nsresult, nsresult>;
+    fn to_result(self) -> Result<(), nsresult>;
 
     /// Get a printable name for the nsresult error code. This function returns
     /// a nsCString<'static>, which implements `Display`.
     fn error_name(self) -> nsCString;
 }
 
 impl NsresultExt for nsresult {
     fn failed(self) -> bool {
         (self.0 >> 31) != 0
     }
 
     fn succeeded(self) -> bool {
         !self.failed()
     }
 
-    fn to_result(self) -> Result<nsresult, nsresult> {
+    fn to_result(self) -> Result<(), nsresult> {
         if self.failed() {
             Err(self)
         } else {
-            Ok(self)
+            Ok(())
         }
     }
 
     fn error_name(self) -> nsCString {
         let mut cstr = nsCString::new();
         unsafe {
             Gecko_GetErrorName(self, &mut *cstr);
         }