首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当使用衬底的decl_event时,我如何隐藏来自Clippy的关于“不需要的单元表达式”的警告?

当使用衬底的decl_event时,我如何隐藏来自Clippy的关于“不需要的单元表达式”的警告?
EN

Stack Overflow用户
提问于 2021-05-21 01:27:37
回答 1查看 88关注 0票数 0

具有类似于底层框架的源代码:

代码语言:javascript
复制
decl_event!(
    pub enum Event<T>
    where
        AccountId = <T as frame_system::Config>::AccountId,
        ChipBalance = <T as Config>::ChipBalance,
    {
        /// Buy chips event
        BuyChips(AccountId, ChipBalance),
        /// Redemption amount with chips event
        Redemption(AccountId, ChipBalance),
        /// Pledge chips
        Reserve(AccountId, ChipBalance),
        /// Cancel pledge chips
        Unreserve(AccountId, ChipBalance),
        /// Transfer the chips in the pledge to others
        RepatriateReserved(AccountId, AccountId, ChipBalance),
    }
);

cargo clippy我得到了:

代码语言:javascript
复制
warning: unneeded unit expression
  --> pallets/gamecenter/src/lib.rs:58:1
   |
58 | / decl_event!(
59 | |     pub enum Event<T>
60 | |     where
61 | |         AccountId = <T as frame_system::Config>::AccountId,
...  |
66 | |     }
67 | | );
   | |__^
   |
   = note: `#[warn(clippy::unused_unit)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit
   = note: this warning originates in the macro `$crate::__decl_generic_event` (in Nightly builds, run with -Z macro-backtrace for more info)

有没有更好的解决方案来隐藏为Clippy lints创建自定义规则的警告?

EN

回答 1

Stack Overflow用户

发布于 2021-05-21 17:10:07

我猜测这是由于From<Event> for ()实现中的单元造成的。这可以解决这个问题:

代码语言:javascript
复制
diff --git a/frame/support/procedural/src/pallet/expand/event.rs b/frame/support/procedural/src/pallet/expand/event.rs
index c4f7aeffa7..ec38c83b8b 100644
--- a/frame/support/procedural/src/pallet/expand/event.rs
+++ b/frame/support/procedural/src/pallet/expand/event.rs
@@ -133,7 +133,7 @@ pub fn expand_event(def: &mut Def) -> proc_macro2::TokenStream {
                #deposit_event
 
                impl<#event_impl_gen> From<#event_ident<#event_use_gen>> for () #event_where_clause {
-                       fn from(_: #event_ident<#event_use_gen>) -> () { () }
+                       fn from(_: #event_ident<#event_use_gen>) -> () {}
                }
 
                impl<#event_impl_gen> #event_ident<#event_use_gen> #event_where_clause {
diff --git a/frame/support/src/event.rs b/frame/support/src/event.rs
index eb666b6f02..b11166d1c6 100644
--- a/frame/support/src/event.rs
+++ b/frame/support/src/event.rs
@@ -140,7 +140,7 @@ macro_rules! decl_event {
                        )*
                }
                impl From<Event> for () {
-                       fn from(_: Event) -> () { () }
+                       fn from(_: Event) -> () {}
                }
                impl Event {
                        #[allow(dead_code)]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67625287

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档