Bug 1527769 - Silence snake case name warning for Rust implemented XPCOM methods r=froydnj
authorMichael Cooper <mcooper@mozilla.com>
Fri, 15 Feb 2019 17:23:15 +0000
changeset 459570 ff158458cf306218b77d2ae1dcf86d7b1ce4783f
parent 459569 382c65f3c2434dd096b9d917907fe6c83c5156fb
child 459571 03a8e747b572f03d0edb9ad5a194ea1058353643
push id35563
push userccoroiu@mozilla.com
push dateSat, 16 Feb 2019 09:36:04 +0000
treeherdermozilla-central@1cfd69d05aa1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1527769
milestone67.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 1527769 - Silence snake case name warning for Rust implemented XPCOM methods r=froydnj Differential Revision: https://phabricator.services.mozilla.com/D19715
xpcom/rust/xpcom/src/method.rs
--- a/xpcom/rust/xpcom/src/method.rs
+++ b/xpcom/rust/xpcom/src/method.rs
@@ -89,19 +89,25 @@ use nserror::{nsresult, NS_ERROR_NULL_PO
 ///
 /// This macro assumes that all non-null pointer arguments are valid!
 /// It does ensure that they aren't null, returning NS_ERROR_NULL_POINTER
 /// for null pointers.  But it doesn't otherwise check their validity.
 /// That makes the function unsafe, so callers must ensure that they only
 /// call it with valid pointer arguments.
 #[macro_export]
 macro_rules! xpcom_method {
+    // `#[allow(non_snake_case)]` is used for each method because `$xpcom_name`
+    // is almost always UpperCamelCase, and Rust gives a warning that it should
+    // be snake_case. It isn't reasonable to rename the XPCOM methods, so
+    // silence the warning.
+
     // A method whose return value is a *mut *const nsISomething type.
     // Example: foo => Foo(bar: *const nsACString, baz: bool) -> *const nsIVariant
     ($rust_name:ident => $xpcom_name:ident($($param_name:ident: $param_type:ty),*) -> *const $retval:ty) => {
+        #[allow(non_snake_case)]
         unsafe fn $xpcom_name(&self, $($param_name: $param_type,)* retval: *mut *const $retval) -> nsresult {
             $(ensure_param!($param_name);)*
             match self.$rust_name($($param_name, )*) {
                 Ok(val) => {
                     val.forget(&mut *retval);
                     NS_OK
                 }
                 Err(error) => {
@@ -109,16 +115,17 @@ macro_rules! xpcom_method {
                 }
             }
         }
     };
 
     // A method whose return value is a *mut nsAString type.
     // Example: foo => Foo(bar: *const nsACString, baz: bool) -> nsAString
     ($rust_name:ident => $xpcom_name:ident($($param_name:ident: $param_type:ty),*) -> nsAString) => {
+        #[allow(non_snake_case)]
         unsafe fn $xpcom_name(&self, $($param_name: $param_type,)* retval: *mut nsAString) -> nsresult {
             $(ensure_param!($param_name);)*
             match self.$rust_name($($param_name, )*) {
                 Ok(val) => {
                     (*retval).assign(&val);
                     NS_OK
                 }
                 Err(error) => {
@@ -126,16 +133,17 @@ macro_rules! xpcom_method {
                 }
             }
         }
     };
 
     // A method whose return value is a *mut nsACString type.
     // Example: foo => Foo(bar: *const nsACString, baz: bool) -> nsACString
     ($rust_name:ident => $xpcom_name:ident($($param_name:ident: $param_type:ty),*) -> nsACString) => {
+        #[allow(non_snake_case)]
         unsafe fn $xpcom_name(&self, $($param_name: $param_type,)* retval: *mut nsACString) -> nsresult {
             $(ensure_param!($param_name);)*
             match self.$rust_name($($param_name, )*) {
                 Ok(val) => {
                     (*retval).assign(&val);
                     NS_OK
                 }
                 Err(error) => {
@@ -143,16 +151,17 @@ macro_rules! xpcom_method {
                 }
             }
         }
     };
 
     // A method whose return value is a non-nsA[C]String *mut type.
     // Example: foo => Foo(bar: *const nsACString, baz: bool) -> bool
     ($rust_name:ident => $xpcom_name:ident($($param_name:ident: $param_type:ty),*) -> $retval:ty) => {
+        #[allow(non_snake_case)]
         unsafe fn $xpcom_name(&self, $($param_name: $param_type,)* retval: *mut $retval) -> nsresult {
             $(ensure_param!($param_name);)*
             match self.$rust_name($($param_name, )*) {
                 Ok(val) => {
                     *retval = val;
                     NS_OK
                 }
                 Err(error) => {
@@ -160,16 +169,17 @@ macro_rules! xpcom_method {
                 }
             }
         }
     };
 
     // A method that doesn't have a return value.
     // Example: foo => Foo(bar: *const nsACString, baz: bool)
     ($rust_name:ident => $xpcom_name:ident($($param_name:ident: $param_type:ty),*)) => {
+        #[allow(non_snake_case)]
         unsafe fn $xpcom_name(&self, $($param_name: $param_type,)*) -> nsresult {
             $(ensure_param!($param_name);)*
             match self.$rust_name($($param_name, )*) {
                 Ok(_) => NS_OK,
                 Err(error) => {
                     error.into()
                 }
             }