Skip to content

Commit 67f2afd

Browse files
committed
Use Box::leak instead of Box:into_raw
It is better being explicit in your intentions. So, when the following criteria are met, use Box::leak instead of Box::into_raw: - ownership is already transfered by some other means, - value of Box::into_raw is not used, i.e. it looks like a statement rather than as an expression. This is my personal opinion, and it is based absolutely on nothing.
1 parent 67f2e23 commit 67f2afd

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

qmetaobject/src/qtdeclarative.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ pub fn qml_register_type<T: QObject + Default + Sized>(
383383
unsafe {
384384
T::qml_construct(&b, c, ed);
385385
}
386-
std::boxed::Box::into_raw(b);
386+
Box::leak(b);
387387
};
388388
let creator_fn: extern "C" fn(c: *mut c_void) = creator_fn::<T>;
389389

@@ -481,7 +481,7 @@ pub fn qml_register_singleton_type<T: QObject + QSingletonInit + Sized + Default
481481
let obj_box: Box<RefCell<T>> = Box::new(RefCell::new(T::default()));
482482
let obj_ptr = unsafe { T::cpp_construct(&obj_box) };
483483
obj_box.borrow_mut().init();
484-
Box::into_raw(obj_box);
484+
Box::leak(obj_box);
485485
obj_ptr
486486
}));
487487
match result {
@@ -570,7 +570,7 @@ pub fn qml_register_singleton_instance<T: QObject + Sized + Default>(
570570

571571
let obj_box = Box::new(RefCell::new(obj));
572572
let obj_ptr = unsafe { T::cpp_construct(&obj_box) };
573-
Box::into_raw(obj_box);
573+
Box::leak(obj_box);
574574

575575
cpp!(unsafe [
576576
uri_ptr as "char*",

0 commit comments

Comments
 (0)