From 767a63976f05e92343844121212d8953b1f44f68 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 25 Feb 2020 07:44:53 +0000 Subject: [PATCH] Bug 1617369 - Reformat toolkit/crashreporter/ & toolkit/library/rust/ using rustfmt r=gsvelto Depends on D63952 Differential Revision: https://phabricator.services.mozilla.com/D63955 --HG-- extra : moz-landing-system : lando --- toolkit/crashreporter/rust/lib.rs | 9 ++- toolkit/library/rust/shared/lib.rs | 110 ++++++++++++++--------------- tools/lint/rustfmt.yml | 2 + 3 files changed, 63 insertions(+), 58 deletions(-) diff --git a/toolkit/crashreporter/rust/lib.rs b/toolkit/crashreporter/rust/lib.rs index 4e7a474c49f8..81be1300f0ae 100644 --- a/toolkit/crashreporter/rust/lib.rs +++ b/toolkit/crashreporter/rust/lib.rs @@ -12,8 +12,11 @@ use std::ptr; /// /// The resulting pointer should be freed with `free_demangled_name`. #[no_mangle] -pub extern fn rust_demangle(name: *const std::os::raw::c_char) -> *mut std::os::raw::c_char { - let demangled = format!("{:#}", demangle(&unsafe { CStr::from_ptr(name) }.to_string_lossy())); +pub extern "C" fn rust_demangle(name: *const std::os::raw::c_char) -> *mut std::os::raw::c_char { + let demangled = format!( + "{:#}", + demangle(&unsafe { CStr::from_ptr(name) }.to_string_lossy()) + ); CString::new(demangled) .map(|s| s.into_raw()) .unwrap_or(ptr::null_mut()) @@ -21,7 +24,7 @@ pub extern fn rust_demangle(name: *const std::os::raw::c_char) -> *mut std::os:: /// Free a string that was returned from `rust_demangle`. #[no_mangle] -pub extern fn free_rust_demangled_name(demangled: *mut std::os::raw::c_char) { +pub extern "C" fn free_rust_demangled_name(demangled: *mut std::os::raw::c_char) { if demangled != ptr::null_mut() { // Just take ownership here. unsafe { CString::from_raw(demangled) }; diff --git a/toolkit/library/rust/shared/lib.rs b/toolkit/library/rust/shared/lib.rs index f7d766069ace..bd23cfb844ac 100644 --- a/toolkit/library/rust/shared/lib.rs +++ b/toolkit/library/rust/shared/lib.rs @@ -6,49 +6,49 @@ extern crate geckoservo; -extern crate mapped_hyph; -extern crate kvstore; -extern crate mp4parse_capi; -extern crate nsstring; -extern crate nserror; -extern crate xpcom; -extern crate netwerk_helper; -extern crate prefs_parser; -extern crate static_prefs; -#[cfg(feature = "gecko_profiler")] -extern crate profiler_helper; -extern crate mozurl; -#[cfg(feature = "quantum_render")] -extern crate webrender_bindings; +#[cfg(feature = "cubeb-remoting")] +extern crate audioipc_client; +#[cfg(feature = "cubeb-remoting")] +extern crate audioipc_server; +extern crate authenticator; +#[cfg(feature = "bitsdownload")] +extern crate bitsdownload; +#[cfg(feature = "moz_places")] +extern crate bookmark_sync; +#[cfg(feature = "new_cert_storage")] +extern crate cert_storage; +extern crate chardetng_c; +extern crate cosec; #[cfg(feature = "cubeb_coreaudio_rust")] extern crate cubeb_coreaudio; #[cfg(feature = "cubeb_pulse_rust")] extern crate cubeb_pulse; extern crate encoding_glue; -#[cfg(feature = "cubeb-remoting")] -extern crate audioipc_client; -#[cfg(feature = "cubeb-remoting")] -extern crate audioipc_server; extern crate env_logger; -extern crate authenticator; -extern crate gkrust_utils; -extern crate log; -#[cfg(feature = "new_cert_storage")] -extern crate cert_storage; -extern crate cosec; -extern crate rsdparsa_capi; -#[cfg(feature = "new_xulstore")] -extern crate xulstore; -extern crate jsrust_shared; -#[cfg(feature = "bitsdownload")] -extern crate bitsdownload; -extern crate storage; -#[cfg(feature = "moz_places")] -extern crate bookmark_sync; -extern crate shift_or_euc_c; -extern crate chardetng_c; #[cfg(feature = "fogotype")] extern crate fog; +extern crate gkrust_utils; +extern crate jsrust_shared; +extern crate kvstore; +extern crate log; +extern crate mapped_hyph; +extern crate mozurl; +extern crate mp4parse_capi; +extern crate netwerk_helper; +extern crate nserror; +extern crate nsstring; +extern crate prefs_parser; +#[cfg(feature = "gecko_profiler")] +extern crate profiler_helper; +extern crate rsdparsa_capi; +extern crate shift_or_euc_c; +extern crate static_prefs; +extern crate storage; +#[cfg(feature = "quantum_render")] +extern crate webrender_bindings; +extern crate xpcom; +#[cfg(feature = "new_xulstore")] +extern crate xulstore; extern crate audio_thread_priority; @@ -70,16 +70,16 @@ extern crate fluent_langneg_ffi; #[cfg(feature = "remote")] extern crate remote; +#[cfg(target_os = "android")] +use log::Level; +#[cfg(not(target_os = "android"))] +use log::Log; use std::boxed::Box; use std::env; use std::ffi::{CStr, CString}; use std::os::raw::c_char; #[cfg(target_os = "android")] use std::os::raw::c_int; -#[cfg(target_os = "android")] -use log::Level; -#[cfg(not(target_os = "android"))] -use log::Log; extern "C" { fn gfx_critical_note(msg: *const c_char); @@ -88,21 +88,23 @@ extern "C" { } struct GeckoLogger { - logger: env_logger::Logger + logger: env_logger::Logger, } impl GeckoLogger { fn new() -> GeckoLogger { let mut builder = env_logger::Builder::new(); - let default_level = if cfg!(debug_assertions) { "warn" } else { "error" }; + let default_level = if cfg!(debug_assertions) { + "warn" + } else { + "error" + }; let logger = match env::var("RUST_LOG") { Ok(v) => builder.parse_filters(&v).build(), _ => builder.parse_filters(default_level).build(), }; - GeckoLogger { - logger - } + GeckoLogger { logger } } fn init() -> Result<(), log::SetLoggerError> { @@ -113,8 +115,7 @@ impl GeckoLogger { } fn should_log_to_gfx_critical_note(record: &log::Record) -> bool { - if record.level() == log::Level::Error && - record.target().contains("webrender") { + if record.level() == log::Level::Error && record.target().contains("webrender") { true } else { false @@ -140,11 +141,11 @@ impl GeckoLogger { let msg = CString::new(format!("{}", record.args())).unwrap(); let tag = CString::new(record.module_path().unwrap()).unwrap(); let prio = match record.metadata().level() { - Level::Error => 6 /* ERROR */, - Level::Warn => 5 /* WARN */, - Level::Info => 4 /* INFO */, - Level::Debug => 3 /* DEBUG */, - Level::Trace => 2 /* VERBOSE */, + Level::Error => 6, /* ERROR */ + Level::Warn => 5, /* WARN */ + Level::Info => 4, /* INFO */ + Level::Debug => 3, /* DEBUG */ + Level::Trace => 2, /* VERBOSE */ }; // Output log directly to android log, since env_logger can output log // only to stderr or stdout. @@ -165,7 +166,7 @@ impl log::Log for GeckoLogger { self.log_out(record); } - fn flush(&self) { } + fn flush(&self) {} } #[no_mangle] @@ -175,8 +176,7 @@ pub extern "C" fn GkRust_Init() { } #[no_mangle] -pub extern "C" fn GkRust_Shutdown() { -} +pub extern "C" fn GkRust_Shutdown() {} /// Used to implement `nsIDebug2::RustPanic` for testing purposes. #[no_mangle] @@ -186,7 +186,7 @@ pub extern "C" fn intentional_panic(message: *const c_char) { #[cfg(feature = "oom_with_hook")] mod oom_hook { - use std::alloc::{Layout, set_alloc_error_hook}; + use std::alloc::{set_alloc_error_hook, Layout}; extern "C" { fn GeckoHandleOOM(size: usize) -> !; diff --git a/tools/lint/rustfmt.yml b/tools/lint/rustfmt.yml index 19ef1ecffe0c..9aada5189f5d 100644 --- a/tools/lint/rustfmt.yml +++ b/tools/lint/rustfmt.yml @@ -13,6 +13,8 @@ rust: - testing/webdriver/ - testing/webdriver/ - toolkit/components/telemetry/fog/ + - toolkit/crashreporter/ + - toolkit/library/ - tools/fuzzing/rust/ exclude: - dom/media/gtest/