this post was submitted on 28 Sep 2021
8 points (100.0% liked)

Rust Programming

8438 readers
26 users here now

founded 5 years ago
MODERATORS
 

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?

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 1 points 3 years ago

I've had this occasionally happen too, clippy lints aren't perfect. Just disable it on that specific line:

https://stackoverflow.com/questions/39269408/how-to-quiet-a-warning-for-a-single-statement-in-rust