Open nyurik opened 7 months ago
This errors more eagerly on 0.12.0-alpha.0, as even if you run cargo check
you will get something like:
Compiling test_extension v0.0.0 (/home/jubilee/tcdi/test_extension)
error[E0277]: the trait bound `fn(u32) -> String: FunctionMetadata<_>` is not satisfied
--> src/lib.rs:6:1
|
6 | fn hello_postile(value: u32) -> String {
| ^^ the trait `FunctionMetadata<_>` is not implemented for `fn(u32) -> String`
|
= help: the following other types implement trait `FunctionMetadata<A>`:
<unsafe fn(T0) -> R as FunctionMetadata<(T0,)>>
<unsafe fn(T0, T1) -> R as FunctionMetadata<(T0, T1)>>
<unsafe fn(T0, T1, T2) -> R as FunctionMetadata<(T0, T1, T2)>>
<unsafe fn(T0, T1, T2, T3) -> R as FunctionMetadata<(T0, T1, T2, T3)>>
<unsafe fn(T0, T1, T2, T3, T4) -> R as FunctionMetadata<(T0, T1, T2, T3, T4)>>
<unsafe fn(T0, T1, T2, T3, T4, T5) -> R as FunctionMetadata<(T0, T1, T2, T3, T4, T5)>>
<unsafe fn(T0, T1, T2, T3, T4, T5, T6) -> R as FunctionMetadata<(T0, T1, T2, T3, T4, T5, T6)>>
<unsafe fn(T0, T1, T2, T3, T4, T5, T6, T7) -> R as FunctionMetadata<(T0, T1, T2, T3, T4, T5, T6, T7)>>
and 25 others
error[E0599]: the method `entity` exists for struct `PhantomData<u32>`, but its trait bounds were not satisfied
--> src/lib.rs:5:1
|
5 | #[pg_extern]
| ^^^^^^^^^^^^ method cannot be called on `PhantomData<u32>` due to unsatisfied trait bounds
|
::: /home/jubilee/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/marker.rs:809:1
|
809 | pub struct PhantomData<T: ?Sized>;
| --------------------------------- doesn't satisfy `PhantomData<u32>: PhantomDataExt`
|
= note: the following trait bounds were not satisfied:
`u32: SqlTranslatable`
which is required by `PhantomData<u32>: PhantomDataExt`
And while "PhantomDataExt???" is probably confounding, PhantomDataExt will likely not exist soon, but the same bounds will have to be satisfied, which will leave the obvious unsatisfied trait bounds as just fn(u32) -> String: FunctionMetadata
and u32: SqlTranslatable
.
And there is, indeed, no uint4
type as far as I'm aware.
It is not terribly obvious how to generate significantly better messages than that, or how to make u32s "just work", considering the constraints, although there are ways, but they get increasingly hacky.
Oh, the one free improvement is being more diligent about passing through spans so that the error message points directly to the u32 arg.
It is not terribly obvious how to generate significantly better messages than that, considering the constraints, although there are ways, but they get increasingly hacky.
Some options for making u32 work:
i32::MAX
get serialized as negative numbers.None of these really "spark joy".
This example produces an un-reasonably complex error, and only during
cargo pgrx test
phase. I also tried it withOption<u32>
Expected
u32
is an invalid type parameter, compilation should failActual results
The last line is the closest indication to the cause, and pretty bad at that.