Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Commit 34b8df4

Browse files
authored
Merge pull request #491 from GuillaumeGomez/warnings
Fix dyn and import warnings
2 parents 35b259b + dcf716c commit 34b8df4

File tree

7 files changed

+45
-29
lines changed

7 files changed

+45
-29
lines changed

src/byte_array.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ impl ByteArray {
107107
pub fn sort<F: FnMut(&u8, &u8) -> Ordering>(&self, compare_func: F) {
108108
unsafe {
109109
let mut func = compare_func;
110-
let func_obj: &mut (FnMut(&u8, &u8) -> Ordering) = &mut func;
110+
let func_obj: &mut (dyn FnMut(&u8, &u8) -> Ordering) = &mut func;
111111
let func_ptr =
112-
&func_obj as *const &mut (FnMut(&u8, &u8) -> Ordering) as glib_sys::gpointer;
112+
&func_obj as *const &mut (dyn FnMut(&u8, &u8) -> Ordering) as glib_sys::gpointer;
113113

114114
glib_sys::g_byte_array_sort_with_data(
115115
self.to_glib_none().0,
@@ -125,7 +125,7 @@ unsafe extern "C" fn compare_func_trampoline(
125125
b: glib_sys::gconstpointer,
126126
func: glib_sys::gpointer,
127127
) -> i32 {
128-
let func = func as *mut &mut (FnMut(&u8, &u8) -> Ordering);
128+
let func = func as *mut &mut (dyn FnMut(&u8, &u8) -> Ordering);
129129

130130
let a = &*(a as *const u8);
131131
let b = &*(b as *const u8);

src/closure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl Closure {
8383
}
8484

8585
#[allow(clippy::redundant_closure)]
86-
pub fn invoke(&self, values: &[&ToValue]) -> Option<Value> {
86+
pub fn invoke(&self, values: &[&dyn ToValue]) -> Option<Value> {
8787
let mut result = unsafe { Value::uninitialized() };
8888

8989
let v_args: Vec<Value>;

src/object.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ glib_object_wrapper!(@object
858858
);
859859

860860
impl Object {
861-
pub fn new(type_: Type, properties: &[(&str, &ToValue)]) -> Result<Object, BoolError> {
861+
pub fn new(type_: Type, properties: &[(&str, &dyn ToValue)]) -> Result<Object, BoolError> {
862862
use std::ffi::CString;
863863

864864
if !type_.is_a(&Object::static_type()) {
@@ -898,7 +898,7 @@ pub trait ObjectExt: ObjectType {
898898
fn get_type(&self) -> Type;
899899
fn get_object_class(&self) -> &ObjectClass;
900900

901-
fn set_property<'a, N: Into<&'a str>>(&self, property_name: N, value: &ToValue) -> Result<(), BoolError>;
901+
fn set_property<'a, N: Into<&'a str>>(&self, property_name: N, value: &dyn ToValue) -> Result<(), BoolError>;
902902
fn get_property<'a, N: Into<&'a str>>(&self, property_name: N) -> Result<Value, BoolError>;
903903
fn has_property<'a, N: Into<&'a str>>(&self, property_name: N, type_: Option<Type>) -> Result<(), BoolError>;
904904
fn get_property_type<'a, N: Into<&'a str>>(&self, property_name: N) -> Option<Type>;
@@ -913,7 +913,7 @@ pub trait ObjectExt: ObjectType {
913913
where N: Into<&'a str>, F: Fn(&[Value]) -> Option<Value> + Send + Sync + 'static;
914914
unsafe fn connect_unsafe<'a, N, F>(&self, signal_name: N, after: bool, callback: F) -> Result<SignalHandlerId, BoolError>
915915
where N: Into<&'a str>, F: Fn(&[Value]) -> Option<Value>;
916-
fn emit<'a, N: Into<&'a str>>(&self, signal_name: N, args: &[&ToValue]) -> Result<Option<Value>, BoolError>;
916+
fn emit<'a, N: Into<&'a str>>(&self, signal_name: N, args: &[&dyn ToValue]) -> Result<Option<Value>, BoolError>;
917917
fn disconnect(&self, handler_id: SignalHandlerId);
918918

919919
fn connect_notify<F: Fn(&Self, &::ParamSpec) + Send + Sync + 'static>(&self, name: Option<&str>, f: F) -> SignalHandlerId;
@@ -945,7 +945,7 @@ impl<T: ObjectType> ObjectExt for T {
945945
}
946946
}
947947

948-
fn set_property<'a, N: Into<&'a str>>(&self, property_name: N, value: &ToValue) -> Result<(), BoolError> {
948+
fn set_property<'a, N: Into<&'a str>>(&self, property_name: N, value: &dyn ToValue) -> Result<(), BoolError> {
949949
let property_name = property_name.into();
950950
let mut property_value = value.to_value();
951951

@@ -1195,7 +1195,7 @@ impl<T: ObjectType> ObjectExt for T {
11951195
}
11961196
}
11971197

1198-
fn emit<'a, N: Into<&'a str>>(&self, signal_name: N, args: &[&ToValue]) -> Result<Option<Value>, BoolError> {
1198+
fn emit<'a, N: Into<&'a str>>(&self, signal_name: N, args: &[&dyn ToValue]) -> Result<Option<Value>, BoolError> {
11991199
let signal_name: &str = signal_name.into();
12001200
unsafe {
12011201
let type_ = self.get_type();

src/source_futures.rs

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,17 @@ impl<T, F> Drop for SourceFuture<T, F> {
104104
/// Create a `Future` that will resolve after the given number of milliseconds.
105105
///
106106
/// The `Future` must be spawned on an `Executor` backed by a `glib::MainContext`.
107-
pub fn timeout_future(value: u32) -> Box<Future<Output = ()> + std::marker::Unpin + Send> {
107+
pub fn timeout_future(value: u32) -> Box<dyn Future<Output = ()> + std::marker::Unpin + Send> {
108108
timeout_future_with_priority(::PRIORITY_DEFAULT, value)
109109
}
110110

111111
/// Create a `Future` that will resolve after the given number of milliseconds.
112112
///
113113
/// The `Future` must be spawned on an `Executor` backed by a `glib::MainContext`.
114-
pub fn timeout_future_with_priority(priority: Priority, value: u32) -> Box<Future<Output = ()> + std::marker::Unpin + Send> {
114+
pub fn timeout_future_with_priority(
115+
priority: Priority,
116+
value: u32,
117+
) -> Box<dyn Future<Output = ()> + std::marker::Unpin + Send> {
115118
Box::new(SourceFuture::new(move |send| {
116119
let mut send = Some(send);
117120
::timeout_source_new(value, None, priority, move || {
@@ -124,7 +127,9 @@ pub fn timeout_future_with_priority(priority: Priority, value: u32) -> Box<Futur
124127
/// Create a `Future` that will resolve after the given number of seconds.
125128
///
126129
/// The `Future` must be spawned on an `Executor` backed by a `glib::MainContext`.
127-
pub fn timeout_future_seconds(value: u32) -> Box<Future<Output = ()> + std::marker::Unpin + Send> {
130+
pub fn timeout_future_seconds(
131+
value: u32,
132+
) -> Box<dyn Future<Output = ()> + std::marker::Unpin + Send> {
128133
timeout_future_seconds_with_priority(::PRIORITY_DEFAULT, value)
129134
}
130135

@@ -134,7 +139,7 @@ pub fn timeout_future_seconds(value: u32) -> Box<Future<Output = ()> + std::mark
134139
pub fn timeout_future_seconds_with_priority(
135140
priority: Priority,
136141
value: u32,
137-
) -> Box<Future<Output = ()> + std::marker::Unpin + Send> {
142+
) -> Box<dyn Future<Output = ()> + std::marker::Unpin + Send> {
138143
Box::new(SourceFuture::new(move |send| {
139144
let mut send = Some(send);
140145
::timeout_source_new_seconds(value, None, priority, move || {
@@ -149,7 +154,9 @@ pub fn timeout_future_seconds_with_priority(
149154
/// The `Future` will resolve to the pid of the child process and the exit code.
150155
///
151156
/// The `Future` must be spawned on an `Executor` backed by a `glib::MainContext`.
152-
pub fn child_watch_future(pid: ::Pid) -> Box<Future<Output = (::Pid, i32)> + std::marker::Unpin + Send> {
157+
pub fn child_watch_future(
158+
pid: ::Pid,
159+
) -> Box<dyn Future<Output = (::Pid, i32)> + std::marker::Unpin + Send> {
153160
child_watch_future_with_priority(::PRIORITY_DEFAULT, pid)
154161
}
155162

@@ -161,7 +168,7 @@ pub fn child_watch_future(pid: ::Pid) -> Box<Future<Output = (::Pid, i32)> + std
161168
pub fn child_watch_future_with_priority(
162169
priority: Priority,
163170
pid: ::Pid,
164-
) -> Box<Future<Output = (::Pid, i32)> + std::marker::Unpin + Send> {
171+
) -> Box<dyn Future<Output = (::Pid, i32)> + std::marker::Unpin + Send> {
165172
Box::new(SourceFuture::new(move |send| {
166173
let mut send = Some(send);
167174
::child_watch_source_new(pid, None, priority, move |pid, code| {
@@ -174,15 +181,18 @@ pub fn child_watch_future_with_priority(
174181
/// Create a `Future` that will resolve once the given UNIX signal is raised
175182
///
176183
/// The `Future` must be spawned on an `Executor` backed by a `glib::MainContext`.
177-
pub fn unix_signal_future(signum: i32) -> Box<Future<Output = ()> + std::marker::Unpin + Send> {
184+
pub fn unix_signal_future(signum: i32) -> Box<dyn Future<Output = ()> + std::marker::Unpin + Send> {
178185
unix_signal_future_with_priority(::PRIORITY_DEFAULT, signum)
179186
}
180187

181188
#[cfg(any(unix, feature = "dox"))]
182189
/// Create a `Future` that will resolve once the given UNIX signal is raised
183190
///
184191
/// The `Future` must be spawned on an `Executor` backed by a `glib::MainContext`.
185-
pub fn unix_signal_future_with_priority(priority: Priority, signum: i32) -> Box<Future<Output = ()> + std::marker::Unpin + Send> {
192+
pub fn unix_signal_future_with_priority(
193+
priority: Priority,
194+
signum: i32,
195+
) -> Box<dyn Future<Output = ()> + std::marker::Unpin + Send> {
186196
Box::new(SourceFuture::new(move |send| {
187197
let mut send = Some(send);
188198
::unix_signal_source_new(signum, None, priority, move || {
@@ -283,14 +293,17 @@ impl<T, F> Drop for SourceStream<T, F> {
283293
/// Create a `Stream` that will provide a value every given number of milliseconds.
284294
///
285295
/// The `Future` must be spawned on an `Executor` backed by a `glib::MainContext`.
286-
pub fn interval_stream(value: u32) -> Box<Stream<Item = ()> + std::marker::Unpin + Send> {
296+
pub fn interval_stream(value: u32) -> Box<dyn Stream<Item = ()> + std::marker::Unpin + Send> {
287297
interval_stream_with_priority(::PRIORITY_DEFAULT, value)
288298
}
289299

290300
/// Create a `Stream` that will provide a value every given number of milliseconds.
291301
///
292302
/// The `Future` must be spawned on an `Executor` backed by a `glib::MainContext`.
293-
pub fn interval_stream_with_priority(priority: Priority, value: u32) -> Box<Stream<Item = ()> + std::marker::Unpin + Send> {
303+
pub fn interval_stream_with_priority(
304+
priority: Priority,
305+
value: u32,
306+
) -> Box<dyn Stream<Item = ()> + std::marker::Unpin + Send> {
294307
Box::new(SourceStream::new(move |send| {
295308
::timeout_source_new(value, None, priority, move || {
296309
if send.unbounded_send(()).is_err() {
@@ -305,7 +318,9 @@ pub fn interval_stream_with_priority(priority: Priority, value: u32) -> Box<Stre
305318
/// Create a `Stream` that will provide a value every given number of seconds.
306319
///
307320
/// The `Stream` must be spawned on an `Executor` backed by a `glib::MainContext`.
308-
pub fn interval_stream_seconds(value: u32) -> Box<Stream<Item = ()> + std::marker::Unpin + Send> {
321+
pub fn interval_stream_seconds(
322+
value: u32,
323+
) -> Box<dyn Stream<Item = ()> + std::marker::Unpin + Send> {
309324
interval_stream_seconds_with_priority(::PRIORITY_DEFAULT, value)
310325
}
311326

@@ -315,7 +330,7 @@ pub fn interval_stream_seconds(value: u32) -> Box<Stream<Item = ()> + std::marke
315330
pub fn interval_stream_seconds_with_priority(
316331
priority: Priority,
317332
value: u32,
318-
) -> Box<Stream<Item = ()> + std::marker::Unpin + Send> {
333+
) -> Box<dyn Stream<Item = ()> + std::marker::Unpin + Send> {
319334
Box::new(SourceStream::new(move |send| {
320335
::timeout_source_new_seconds(value, None, priority, move || {
321336
if send.unbounded_send(()).is_err() {
@@ -331,15 +346,18 @@ pub fn interval_stream_seconds_with_priority(
331346
/// Create a `Stream` that will provide a value whenever the given UNIX signal is raised
332347
///
333348
/// The `Stream` must be spawned on an `Executor` backed by a `glib::MainContext`.
334-
pub fn unix_signal_stream(signum: i32) -> Box<Stream<Item = ()> + std::marker::Unpin + Send> {
349+
pub fn unix_signal_stream(signum: i32) -> Box<dyn Stream<Item = ()> + std::marker::Unpin + Send> {
335350
unix_signal_stream_with_priority(::PRIORITY_DEFAULT, signum)
336351
}
337352

338353
#[cfg(any(unix, feature = "dox"))]
339354
/// Create a `Stream` that will provide a value whenever the given UNIX signal is raised
340355
///
341356
/// The `Stream` must be spawned on an `Executor` backed by a `glib::MainContext`.
342-
pub fn unix_signal_stream_with_priority(priority: Priority, signum: i32) -> Box<Stream<Item = ()> + std::marker::Unpin + Send> {
357+
pub fn unix_signal_stream_with_priority(
358+
priority: Priority,
359+
signum: i32,
360+
) -> Box<dyn Stream<Item = ()> + std::marker::Unpin + Send> {
343361
Box::new(SourceStream::new(move |send| {
344362
::unix_signal_source_new(signum, None, priority, move || {
345363
if send.unbounded_send(()).is_err() {

src/translate.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,6 @@ fn path_to_c(path: &Path) -> CString {
401401
// Paths on UNIX must not contain NUL bytes, in which case the conversion
402402
// to a CString would fail. The only thing we can do then is to panic, as passing
403403
// NULL or the empty string to GLib would cause undefined behaviour.
404-
use std::os::unix::ffi::OsStrExt;
405404
CString::new(path.as_os_str().as_bytes())
406405
.expect("Invalid path with NUL bytes")
407406
}
@@ -440,7 +439,6 @@ fn os_str_to_c(s: &OsStr) -> CString {
440439
// OS string on UNIX must not contain NUL bytes, in which case the conversion
441440
// to a CString would fail. The only thing we can do then is to panic, as passing
442441
// NULL or the empty string to GLib would cause undefined behaviour.
443-
use std::os::unix::ffi::OsStrExt;
444442
CString::new(s.as_bytes())
445443
.expect("Invalid OS String with NUL bytes")
446444
}

src/value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl<'a> ToGlibPtrMut<'a, *mut gobject_sys::GValue> for Value {
290290
}
291291

292292
#[doc(hidden)]
293-
impl<'a> ToGlibPtr<'a, *mut gobject_sys::GValue> for &'a [&'a ToValue] {
293+
impl<'a> ToGlibPtr<'a, *mut gobject_sys::GValue> for &'a [&'a dyn ToValue] {
294294
type Storage = ValueArray;
295295

296296
fn to_glib_none(&'a self) -> Stash<'a, *mut gobject_sys::GValue, Self> {

src/value_array.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ impl ValueArray {
6464
pub fn sort_with_data<F: FnMut(&Value, &Value) -> Ordering>(&mut self, compare_func: F) {
6565
unsafe {
6666
let mut func = compare_func;
67-
let func_obj: &mut (FnMut(&Value, &Value) -> Ordering) = &mut func;
68-
let func_ptr = &func_obj as *const &mut (FnMut(&Value, &Value) -> Ordering) as glib_sys::gpointer;
67+
let func_obj: &mut (dyn FnMut(&Value, &Value) -> Ordering) = &mut func;
68+
let func_ptr = &func_obj as *const &mut (dyn FnMut(&Value, &Value) -> Ordering) as glib_sys::gpointer;
6969

7070
gobject_sys::g_value_array_sort_with_data(self.to_glib_none_mut().0, Some(compare_func_trampoline), func_ptr);
7171
}
@@ -92,7 +92,7 @@ impl ops::DerefMut for ValueArray {
9292

9393
unsafe extern "C" fn compare_func_trampoline(a: glib_sys::gconstpointer, b: glib_sys::gconstpointer, func: glib_sys::gpointer) -> i32
9494
{
95-
let func = func as *mut &mut (FnMut(&Value, &Value) -> Ordering);
95+
let func = func as *mut &mut (dyn FnMut(&Value, &Value) -> Ordering);
9696

9797
let a = &*(a as *const Value);
9898
let b = &*(b as *const Value);

0 commit comments

Comments
 (0)