Skip to content

Commit afc657b

Browse files
authored
Merge pull request #1084 from godot-rust/qol/godot-convert-diagnostics
Add diagnostic hints for missing `ToGodot`/`FromGodot` traits
2 parents 280ddae + bb976e3 commit afc657b

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

godot-core/src/meta/args/as_arg.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ use std::ffi::CStr;
4949
/// custom types. Classes are already supported through upcasting and [`AsObjectArg`][crate::meta::AsObjectArg].
5050
#[diagnostic::on_unimplemented(
5151
message = "Argument of type `{Self}` cannot be passed to an `impl AsArg<{T}>` parameter",
52-
note = "If you pass by value, consider borrowing instead.",
52+
note = "if you pass by value, consider borrowing instead.",
5353
note = "GString/StringName/NodePath aren't implicitly convertible for performance reasons; use their `arg()` method.",
54-
note = "See also `AsArg` docs: https://godot-rust.github.io/docs/gdext/master/godot/meta/trait.AsArg.html"
54+
note = "see also `AsArg` docs: https://godot-rust.github.io/docs/gdext/master/godot/meta/trait.AsArg.html"
5555
)]
5656
pub trait AsArg<T: ParamType>
5757
where

godot-core/src/meta/args/object_arg.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ use std::ptr;
4646
/// | (null literal) | | `Gd::null_arg()` |
4747
#[diagnostic::on_unimplemented(
4848
message = "Argument of type `{Self}` cannot be passed to an `impl AsObjectArg<{T}>` parameter",
49-
note = "If you pass by value, consider borrowing instead.",
50-
note = "See also `AsObjectArg` docs: https://godot-rust.github.io/docs/gdext/master/godot/meta/trait.AsObjectArg.html"
49+
note = "if you pass by value, consider borrowing instead.",
50+
note = "see also `AsObjectArg` docs: https://godot-rust.github.io/docs/gdext/master/godot/meta/trait.AsObjectArg.html"
5151
)]
5252
pub trait AsObjectArg<T>
5353
where

godot-core/src/meta/godot_convert/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ pub trait GodotConvert {
4242
/// Please read the [`godot::meta` module docs][crate::meta] for further information about conversions.
4343
///
4444
/// This trait can be derived using the [`#[derive(GodotConvert)]`](../register/derive.GodotConvert.html) macro.
45+
#[diagnostic::on_unimplemented(
46+
message = "passing type `{Self}` to Godot requires `ToGodot` trait, which is usually provided by the library",
47+
note = "ToGodot is implemented for built-in types (i32, Vector2, GString, …). For objects, use Gd<T> instead of T.",
48+
note = "if you really need a custom representation (for non-class types), implement ToGodot manually or use #[derive(GodotConvert)].",
49+
note = "see also: https://godot-rust.github.io/docs/gdext/master/godot/meta"
50+
)]
4551
pub trait ToGodot: Sized + GodotConvert {
4652
/// Target type of [`to_godot()`](ToGodot::to_godot), which can differ from [`Via`][GodotConvert::Via] for pass-by-reference types.
4753
///
@@ -76,6 +82,12 @@ pub trait ToGodot: Sized + GodotConvert {
7682
/// Please read the [`godot::meta` module docs][crate::meta] for further information about conversions.
7783
///
7884
/// This trait can be derived using the [`#[derive(GodotConvert)]`](../register/derive.GodotConvert.html) macro.
85+
#[diagnostic::on_unimplemented(
86+
message = "receiving type `{Self}` from Godot requires `FromGodot` trait, which is usually provided by the library",
87+
note = "FromGodot is implemented for built-in types (i32, Vector2, GString, …). For objects, use Gd<T> instead of T.",
88+
note = "if you really need a custom representation (for non-class types), implement FromGodot manually or use #[derive(GodotConvert)]",
89+
note = "see also: https://godot-rust.github.io/docs/gdext/master/godot/meta"
90+
)]
7991
pub trait FromGodot: Sized + GodotConvert {
8092
/// Converts the Godot representation to this type, returning `Err` on failure.
8193
fn try_from_godot(via: Self::Via) -> Result<Self, ConvertError>;

godot-core/src/obj/traits.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use godot_ffi as sys;
2121
/// Normally, you don't need to implement this trait yourself; use [`#[derive(GodotClass)]`](../register/derive.GodotClass.html) instead.
2222
// Above intra-doc link to the derive-macro only works as HTML, not as symbol link.
2323
#[diagnostic::on_unimplemented(
24-
message = "Only classes registered with Godot are allowed in this context",
24+
message = "only classes registered with Godot are allowed in this context",
2525
note = "you can use `#[derive(GodotClass)]` to register your own structs with Godot",
2626
note = "see also: https://godot-rust.github.io/book/register/classes.html"
2727
)]
@@ -262,7 +262,7 @@ pub trait IndexEnum: EngineEnum {
262262
#[diagnostic::on_unimplemented(
263263
message = "Class `{Self}` requires a `Base<T>` field",
264264
label = "missing field `_base: Base<...>` in struct declaration",
265-
note = "A base field is required to access the base from within `self`, as well as for #[signal], #[rpc] and #[func(virtual)]",
265+
note = "a base field is required to access the base from within `self`, as well as for #[signal], #[rpc] and #[func(virtual)]",
266266
note = "see also: https://godot-rust.github.io/book/register/classes.html#the-base-field"
267267
)]
268268
pub trait WithBaseField: GodotClass + Bounds<Declarer = bounds::DeclUser> {
@@ -527,8 +527,8 @@ pub mod cap {
527527
#[diagnostic::on_unimplemented(
528528
message = "Class `{Self}` requires either an `init` constructor, or explicit opt-out",
529529
label = "needs `init`",
530-
note = "To provide a default constructor, use `#[class(init)]` or implement an `init` method",
531-
note = "To opt out, use `#[class(no_init)]`",
530+
note = "to provide a default constructor, use `#[class(init)]` or implement an `init` method",
531+
note = "to opt out, use `#[class(no_init)]`",
532532
note = "see also: https://godot-rust.github.io/book/register/constructors.html"
533533
)]
534534
pub trait GodotDefault: GodotClass {

0 commit comments

Comments
 (0)