SpacetimeDB
SpacetimeDB copied to clipboard
`#[table]` macro has bad error message when invoked inside function
With a unique column or index. Repro:
fn broken() {
#[spacetimedb::table(name = users)]
struct User {
#[primary_key]
id: u32,
}
}
Error:
$ cargo build --target wasm32-unknown-unknown
Compiling spacetime-module v0.1.0 (F:\clockwork\broken)
error[E0412]: cannot find type `users__TableHandle` in this scope
--> src\lib.rs:2:33
|
2 | #[spacetimedb::table(name = users)]
| ^^^^^ not found in this scope
For more information about this error, try `rustc --explain E0412`.
error: could not compile `spacetime-module` (lib) due to 1 previous error
This mainly shows up in doctests, which are secretly wrapped in a function scope. Not sure it's possible to get a better error message, but maybe.
(To work around in doctests, just wrap the whole doctest in:
/// ```no_run
/// # mod demo {
/// // doctest code...
/// }
/// ```
)
Is the no_run necessary, or just the mod demo part?
Is there anything we can do about this?