Remove warning and make __PhantomItem unconstructable (#2000)

* Remove warning and make `__PhantomItem` unconstructable

* Switch to unreachable
This commit is contained in:
Bastian Köcher
2019-03-14 21:53:05 +01:00
committed by GitHub
parent 990d368f0d
commit a57f6bbe6a
+7 -5
View File
@@ -27,6 +27,9 @@ pub use srml_metadata::{
FunctionArgumentMetadata, OuterDispatchMetadata, OuterDispatchCall
};
/// A type that can not be instantiated.
pub enum Never {}
/// Result of a module function call; either nothing (functions are only called for "side efeects")
/// or an error message.
pub type Result = result::Result<(), &'static str>;
@@ -615,7 +618,7 @@ macro_rules! decl_module {
$(#[$attr])*
pub enum $call_type<$trait_instance: $trait_name> {
#[doc(hidden)]
__PhantomItem(::std::marker::PhantomData<$trait_instance>),
__PhantomItem(::std::marker::PhantomData<$trait_instance>, $crate::dispatch::Never),
$(
#[allow(non_camel_case_types)]
$(#[doc = $doc_attr])*
@@ -627,7 +630,7 @@ macro_rules! decl_module {
$(#[$attr])*
pub enum $call_type<$trait_instance: $trait_name> {
#[doc(hidden)]
__PhantomItem(::core::marker::PhantomData<$trait_instance>),
__PhantomItem(::core::marker::PhantomData<$trait_instance>, $crate::dispatch::Never),
$(
#[allow(non_camel_case_types)]
$(#[doc = $doc_attr])*
@@ -662,7 +665,7 @@ macro_rules! decl_module {
self_params == ( $( $param_name, )* )
} else {
match *_other {
$call_type::__PhantomItem(_) => unreachable!(),
$call_type::__PhantomItem(_, _) => unreachable!(),
_ => false,
}
}
@@ -704,7 +707,6 @@ macro_rules! decl_module {
impl<$trait_instance: $trait_name> $crate::dispatch::Encode for $call_type<$trait_instance> {
fn encode_to<W: $crate::dispatch::Output>(&self, _dest: &mut W) {
$crate::__impl_encode!(_dest; *self; 0; $call_type; $( fn $fn_name( $( $(#[$codec_attr on type $param])* $param_name ),* ); )*);
if let $call_type::__PhantomItem(_) = *self { unreachable!() }
}
}
impl<$trait_instance: $trait_name> $crate::dispatch::Dispatchable
@@ -723,7 +725,7 @@ macro_rules! decl_module {
)
},
)*
$call_type::__PhantomItem(_) => { panic!("__PhantomItem should never be used.") },
$call_type::__PhantomItem(_, _) => { unreachable!("__PhantomItem should never be used.") },
}
}
}