Skip to content

Commit 789576b

Browse files
committed
Early migration warning for editor-placeholder change
1 parent 80d1e09 commit 789576b

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

godot-core/src/classes/class_runtime.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ where
330330
/// Panic emitted when `bind()` / `bind_mut()` is called on a placeholder instance (runtime class accessed in the editor).
331331
#[track_caller]
332332
pub(crate) fn panic_placeholder_bind<T>(method: &str) -> ! {
333+
crate::warn_editor_placeholder_v06!(id: "EditorPlaceholderV06Bind", surface: "Gd::bind/bind_mut");
333334
panic!(
334335
"Gd::{method}() called on a placeholder instance of `{name}`.\n\
335336
A non-tool class does not have a real instance in the editor.\n\

godot-core/src/private.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,39 @@ pub fn is_class_runtime(is_tool: bool) -> bool {
227227
global_config.tool_only_in_editor
228228
}
229229

230+
/// Emits a one-shot startup warning when an editor code path is about to diverge from v0.6 default behavior.
231+
///
232+
/// Expands to a per-call-site `static Once` plus an `is_editor()` check, so each call site fires at most once.
233+
/// All ids share the `EditorPlaceholderV06` prefix and are individually suppressible via
234+
/// `GDRUST_SUPPRESSED_WARNINGS=<id>,...`.
235+
#[cfg(not(feature = "upcoming-editor-placeholders"))]
236+
#[macro_export]
237+
#[doc(hidden)]
238+
macro_rules! warn_editor_placeholder_v06 {
239+
(id: $id:literal, surface: $surface:literal) => {{
240+
static WARNED: std::sync::Once = std::sync::Once::new();
241+
if $crate::sys::is_editor() {
242+
WARNED.call_once(|| {
243+
::godot_ffi::defer_startup_warn!(
244+
id: $id,
245+
"godot-rust v0.6 will change editor behavior for non-`#[class(tool)]` runtime classes.\n\
246+
Your code currently relies on old behavior for {}.\n\
247+
Opt in early via the `upcoming-editor-placeholders` feature.",
248+
$surface,
249+
);
250+
});
251+
}
252+
}};
253+
}
254+
255+
/// No-op stub when the feature is enabled, so call sites stay unconditional.
256+
#[cfg(feature = "upcoming-editor-placeholders")]
257+
#[macro_export]
258+
#[doc(hidden)]
259+
macro_rules! warn_editor_placeholder_v06 {
260+
(id: $id:literal, surface: $surface:literal) => {{}};
261+
}
262+
230263
/// Converts a default parameter value to a runtime-immutable `Variant`.
231264
///
232265
/// This function is used internally by the `#[opt(default)]` attribute to:

godot-core/src/registry/callbacks.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ pub unsafe extern "C" fn get_virtual<T: cap::ImplementsGodotVirtual>(
214214
name: sys::GDExtensionConstStringNamePtr,
215215
hash: u32,
216216
) -> sys::GDExtensionClassCallVirtual {
217+
crate::warn_editor_placeholder_v06!(id: "EditorPlaceholderV06Virtual", surface: "virtual callbacks (ready, notification, on_property_get_revert, ...)");
218+
217219
unsafe {
218220
// This string is not ours, so we cannot call the destructor on it.
219221
let borrowed_string = StringName::borrow_string_sys(name);
@@ -228,6 +230,8 @@ pub unsafe extern "C" fn get_virtual<T: cap::ImplementsGodotVirtual>(
228230
_class_user_data: *mut std::ffi::c_void,
229231
name: sys::GDExtensionConstStringNamePtr,
230232
) -> sys::GDExtensionClassCallVirtual {
233+
crate::warn_editor_placeholder_v06!(id: "EditorPlaceholderV06Virtual", surface: "virtual callbacks (ready, notification, on_property_get_revert, ...)");
234+
231235
// This string is not ours, so we cannot call the destructor on it.
232236
let borrowed_string = StringName::borrow_string_sys(name);
233237
let method_name = borrowed_string.to_string();
@@ -299,6 +303,8 @@ pub unsafe extern "C" fn get_property<T: cap::GodotGet>(
299303
name: sys::GDExtensionConstStringNamePtr,
300304
ret: sys::GDExtensionVariantPtr,
301305
) -> sys::GDExtensionBool {
306+
crate::warn_editor_placeholder_v06!(id: "EditorPlaceholderV06Property", surface: "#[var] accessors and IObject::on_get/on_set");
307+
302308
unsafe {
303309
let storage = as_storage::<T>(instance);
304310
let instance = T::Recv::instance(storage);
@@ -319,6 +325,8 @@ pub unsafe extern "C" fn set_property<T: cap::GodotSet>(
319325
name: sys::GDExtensionConstStringNamePtr,
320326
value: sys::GDExtensionConstVariantPtr,
321327
) -> sys::GDExtensionBool {
328+
crate::warn_editor_placeholder_v06!(id: "EditorPlaceholderV06Property", surface: "#[var] accessors and IObject::on_get/on_set");
329+
322330
unsafe {
323331
let storage = as_storage::<T>(instance);
324332
let instance = T::Recv::instance(storage);

0 commit comments

Comments
 (0)