Skip to content

Commit a94e9dc

Browse files
bors[bot]Bromeon
andauthored
Merge #650
650: Feature/call error description r=toasteater a=Bromeon Slightly more expressive error message when calls to Rust fail due to `&mut` aliasing. Looks as follows: ![grafik](https://user-images.githubusercontent.com/708488/103409399-e70bf500-4b66-11eb-97a5-1741e1f58866.png) I wonder if there's another place where this should be mentioned. Maybe in the `Node::call()` doc, as that's a likely source of re-entrancy? Co-authored-by: Jan Haller <[email protected]>
2 parents 57973d7 + a61ac5a commit a94e9dc

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

gdnative-core/src/core_types/access.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ where
3333
///
3434
/// This trait is sealed and has no public members.
3535
#[allow(clippy::len_without_is_empty)]
36-
pub unsafe trait Guard: Drop + private::Sealed {
36+
pub unsafe trait Guard: private::Sealed {
3737
#[doc(hidden)]
3838
type Target;
3939

gdnative-core/src/nativescript/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ macro_rules! godot_wrap_method_inner {
204204
<$retty as $crate::core_types::OwnedToVariant>::owned_to_variant(ret)
205205
})
206206
.unwrap_or_else(|err| {
207-
$crate::godot_error!("gdnative-core: method call failed with error: {:?}", err);
207+
$crate::godot_error!("gdnative-core: method call failed with error: {}", err);
208208
$crate::godot_error!("gdnative-core: check module level documentation on gdnative::user_data for more information");
209209
$crate::core_types::Variant::new()
210210
});

gdnative-core/src/nativescript/user_data.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ pub type DefaultUserData<T> = LocalCellData<T>;
153153
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
154154
pub enum Infallible {}
155155

156+
impl std::fmt::Display for Infallible {
157+
#[inline]
158+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
159+
write!(f, "Operation that can't fail just failed")
160+
}
161+
}
162+
156163
/// Policies to deal with potential deadlocks
157164
///
158165
/// As Godot allows mutable pointer aliasing, doing certain things in exported method bodies may
@@ -526,7 +533,11 @@ mod local_cell {
526533
"Accessing from the wrong thread, expected {:?} found {:?}",
527534
original, current
528535
),
529-
LocalCellError::BorrowFailed => write!(f, "Borrow Failed"),
536+
LocalCellError::BorrowFailed => write!(
537+
f,
538+
"Borrow failed; a &mut reference was requested, but one already exists. Cause is likely a re-entrant call \
539+
(e.g. a GDNative Rust method calls to GDScript, which again calls a Rust method on the same object)."
540+
),
530541
}
531542
}
532543
}

0 commit comments

Comments
 (0)