具有类似于底层框架的源代码:
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我得到了:
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创建自定义规则的警告?
发布于 2021-05-21 17:10:07
我猜测这是由于From<Event> for ()实现中的单元造成的。这可以解决这个问题:
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)]https://stackoverflow.com/questions/67625287
复制相似问题