Cargo expand is not expanding macros

I have ran cargo expand but this command still leaves some macros unexpanded. This is the crate I am trying to expand: https://github.com/paritytech/substrate/tree/master/srml/support/src

And here is the proof that it is not working :

niko@lap:~/sub/substrate/srml/support/src$ cargo expand | grep macro_rules
Checking srml-support v2.0.0 (/home/niko/sub/substrate/srml/support)
Finished dev [unoptimized + debuginfo] target(s) in 0.58s

macro_rules! decl_module((
macro_rules! impl_outer_dispatch((
macro_rules! __dispatch_impl_metadata((
macro_rules! __call_to_functions((
macro_rules! __functions_to_metadata((
macro_rules! __function_to_metadata((
    macro_rules! storage_items((
    macro_rules! __storage_items_internal((
    macro_rules! __handle_wrap_internal((
macro_rules! decl_event((
macro_rules! __decl_generic_event((
macro_rules! __events_to_metadata((
macro_rules! impl_outer_event((
macro_rules! __impl_outer_event_json_metadata((
macro_rules! impl_outer_origin((
macro_rules! impl_runtime_metadata((
macro_rules! __runtime_modules_to_metadata((
macro_rules! __runtime_modules_to_metadata_calls_call((
macro_rules! __runtime_modules_to_metadata_calls_event((
macro_rules! __runtime_modules_to_metadata_calls_storagename((
macro_rules! __runtime_modules_to_metadata_calls_storage((
macro_rules! construct_runtime((
macro_rules! __create_decl_macro((
                                 macro_rules ! $ macro_name {
macro_rules! __decl_outer_event((
macro_rules! __decl_outer_origin((
macro_rules! __decl_all_modules((
macro_rules! __decl_outer_dispatch((
macro_rules! __decl_runtime_metadata((
macro_rules! __decl_outer_log((
macro_rules! __decl_outer_config((
macro_rules! __decl_outer_inherent((
macro_rules! __decl_instance_import((
macro_rules! __impl_outer_validate_unsigned((
macro_rules! impl_outer_inherent((
macro_rules! impl_outer_validate_unsigned((
macro_rules! fail(( $ y : expr ) => { { return Err ( $ y ) ; } });
macro_rules! ensure(( $ x : expr , $ y : expr ) => {
macro_rules! assert_noop(( $ x : expr , $ y : expr ) => {
macro_rules! assert_err(( $ x : expr , $ y : expr ) => {
macro_rules! assert_ok(( $ x : expr ) => { assert_eq ! ( $ x , Ok ( (  ) ) ) ;
macro_rules! assert_eq_uvec(( $ x : expr , $ y : expr ) => {
macro_rules! __assert_eq_uvec(( $ x : expr , $ y : expr ) => {
macro_rules! for_each_tuple(( $ m : ident ) => {
niko@lap:~/sub/substrate/srml/support/src$ 

So , how do you really-really expand macros ?

I believe macro_rules! is not really a macro and cannot be expanded to any meaningful Rust code.

For me cargo expand did not yield any macro_rules! (pastebin)

macro_rules! is the definition of a macro.
For example :

macro_rules! __call_to_functions(( 

What I want to get is that all places where __call_to_functions() appear in the source being replaced with the actual source code after expanding the macro. Is this possible ?

how did you do it ???
did you ran cargo expand on the full sources or just the directory I was referring to?

$ git clone https://github.com/paritytech/substrate
$ cd substrate/srml/support
$ cargo expand

Some metadata:

$ uname -a
Linux ship 4.10.0-38-generic #42~16.04.1-Ubuntu SMP
$ cargo -V
cargo 1.35.0 (6f3e9c367 2019-04-04)
$ cargo expand -V
cargo-expand 0.4.9

Thanks, with your help I was able to find what was wrong. The rustfmt command wasn’t installed on my distro for the nighly build. After installing

rustup component add rustfmt --toolchain nightly

I got it expanded correctly.

3 Likes