I’m getting a weird compiler warning from using a macro that I wrote:

warning: unnecessary parentheses around type
--> crates/apub/src/activities/community/announce.rs:43:19
|
43 | #[activity_handler(LemmyContext)]
|                   ^            ^
|
= note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
|
43 - #[activity_handler(LemmyContext)]
43 + #[activity_handlerLemmyContext]
| 

Here is the code that it is warning about:

#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
#[serde(untagged)]
#[activity_handler(LemmyContext)]
pub enum AnnouncableActivities {
  CreateOrUpdateComment(CreateOrUpdateComment),
  CreateOrUpdatePost(Box<CreateOrUpdatePost>),
    ...
}

Macro definition is here.

The warning is clearly wrong, because the code compiles, but if after applying the suggested fix, it breaks. I also can’t find any info about this problem, or how to fix it. In general there seems to be a real lack of resources for Rust macros.

So does anyone here know how to get rid of the warning, without explicitly ignoring it?

  • Support Trans People@lemmy.ml
    link
    fedilink
    arrow-up
    1
    arrow-down
    1
    ·
    3 years ago

    after searching the github issues it looks like rust does report “unnecessary parentheses” a lot more than it should

    due to the buggy nature of macros, opening an issue on github is probably the best way to solve (i suspect there is nothing wrong with the code itself)