You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a use case where I want users of my bot to be able to specify the default_member_permissions field for commands considered "admin only". I didn't want to reinvent the poise::command macro, so I wrote the following macro:
However, when invoking this macro with any function arguments that are Option<T>, the poise::command macro no longer recognizes Option and considers Option<T> as a distinct type.
For example:
use poise::serenity_prelude::User;usecrate::Context;super::command! {true;
pubasyncfn poc(ctx: Context<'_>, example: Option<User>) -> Result<()> {
println!("demo user = {:?}", example);
Ok(())}}
produces the following compile error:
error[E0599]: the method `create` exists for reference `&&PhantomData<Option<User>>`, but its trait bounds were not satisfied
--> src/command/poc.rs:5:1
|
5 | / super::command! {
6 | | true;
7 | | pub async fn poc(ctx: Context<'_>, example: Option<User>) -> Result<()> {
8 | | println!("demo user = {:?}", example);
... |
11 | | }
12 | | }
| |_^ method cannot be called on `&&PhantomData<Option<User>>` due to unsatisfied trait bounds
|
::: /nix/store/yv81f5ak2ywr02nryl52mpngii3sc06z-rust-default-1.84.0-nightly-2024-10-28/lib/rustlib/src/rust/library/core/src/option.rs:571:1
|
571 | pub enum Option<T> {
| ------------------ doesn't satisfy `_: ArgumentConvert`, `_: FromStr` or `_: SlashArgument`
|
::: /nix/store/yv81f5ak2ywr02nryl52mpngii3sc06z-rust-default-1.84.0-nightly-2024-10-28/lib/rustlib/src/rust/library/core/src/marker.rs:753:1
|
753 | pub struct PhantomData<T: ?Sized>;
| --------------------------------- doesn't satisfy `_: SlashArgumentHack<Option<User>>`
|
= note: the following trait bounds were not satisfied:
`std::option::Option<poise::serenity_prelude::User>: poise::SlashArgument`
which is required by `&std::marker::PhantomData<std::option::Option<poise::serenity_prelude::User>>: poise::SlashArgumentHack<std::option::Option<poise::serenity_prelude::User>>`
`std::option::Option<poise::serenity_prelude::User>: poise::serenity_prelude::ArgumentConvert`
which is required by `std::marker::PhantomData<std::option::Option<poise::serenity_prelude::User>>: poise::SlashArgumentHack<std::option::Option<poise::serenity_prelude::User>>`
`std::option::Option<poise::serenity_prelude::User>: std::str::FromStr`
which is required by `std::marker::PhantomData<std::option::Option<poise::serenity_prelude::User>>: poise::SlashArgumentHack<std::option::Option<poise::serenity_prelude::User>>`
= note: this error originates in the macro `poise::create_slash_argument` which comes from the expansion of the macro `super::command` (in Nightly builds, run with -Z macro-backtrace for more info)
I poked around in the expanded code using cargo-expand, and saw that the argument type is being set to Option<T> instead of T, and required is being set to true instead of false.
I read through the code that parses the type and I can't figure out why this might be happening. I suspect this is actually a bug in Rust or syn whereby the macro_rules invocation is removing the distinction between generic and simple types but I feel it's right to post it here first and move elsewhere once it's scope has been determined.
Thank you
The text was updated successfully, but these errors were encountered:
I have a use case where I want users of my bot to be able to specify the
default_member_permissions
field for commands considered "admin only". I didn't want to reinvent thepoise::command
macro, so I wrote the following macro:However, when invoking this macro with any function arguments that are
Option<T>
, thepoise::command
macro no longer recognizesOption
and considersOption<T>
as a distinct type.For example:
produces the following compile error:
I poked around in the expanded code using
cargo-expand
, and saw that the argument type is being set toOption<T>
instead ofT
, andrequired
is being set totrue
instead offalse
.I read through the code that parses the type and I can't figure out why this might be happening. I suspect this is actually a bug in Rust or
syn
whereby themacro_rules
invocation is removing the distinction between generic and simple types but I feel it's right to post it here first and move elsewhere once it's scope has been determined.Thank you
The text was updated successfully, but these errors were encountered: