Skip to content

Commit de439bc

Browse files
committed
Cleanup
1 parent e6f6d95 commit de439bc

File tree

6 files changed

+147
-79
lines changed

6 files changed

+147
-79
lines changed

godot-codegen/src/generator/builtins.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,16 @@ fn make_special_builtin_methods(class_name: &TyName, _ctx: &Context) -> TokenStr
163163
}
164164
}
165165

166-
/// Get the safety docs of a method if it should be unsafe
166+
/// Get the safety docs of an unsafe method, or `None` if it is safe.
167167
fn method_safety_doc(class_name: &TyName, method: &BuiltinMethod) -> Option<TokenStream> {
168-
if class_name.godot_ty == "Array" {
169-
if &method.return_value().type_tokens().to_string() == "VariantArray" {
170-
return Some(quote! {
171-
#[doc = "# Safety"]
172-
#[doc = ""]
173-
#[doc = "You must ensure that the returned array fulfils the safety invariants of [`Array`](crate::builtin::Array)"]
174-
});
175-
}
168+
if class_name.godot_ty == "Array"
169+
&& &method.return_value().type_tokens().to_string() == "VariantArray"
170+
{
171+
return Some(quote! {
172+
/// # Safety
173+
///
174+
/// You must ensure that the returned array fulfils the safety invariants of [`Array`](crate::builtin::Array).
175+
});
176176
}
177177

178178
None

godot-codegen/src/generator/classes.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,18 @@ fn make_class(class: &Class, ctx: &mut Context, view: &ApiView) -> GeneratedClas
139139
let instance_id = rtti.check_type::<Self>();
140140
Some(instance_id)
141141
}
142+
143+
#[doc(hidden)]
144+
pub fn __object_ptr(&self) -> sys::GDExtensionObjectPtr {
145+
self.object_ptr
146+
}
142147
};
143148

149+
let inherits_macro_safety_doc = format!(
150+
"The provided class must be a subclass of all the superclasses of [`{}`]",
151+
class_name.rust_ty
152+
);
153+
144154
// mod re_export needed, because class should not appear inside the file module, and we can't re-export private struct as pub.
145155
let imports = util::make_imports();
146156
let tokens = quote! {
@@ -197,7 +207,7 @@ fn make_class(class: &Class, ctx: &mut Context, view: &ApiView) -> GeneratedClas
197207

198208
/// # Safety
199209
///
200-
#[doc = concat!("The provided class must be a subclass of all the superclasses of ", stringify!(#class_name))]
210+
#[doc = #inherits_macro_safety_doc]
201211
#[macro_export]
202212
#[allow(non_snake_case)]
203213
macro_rules! #inherits_macro {

0 commit comments

Comments
 (0)