Subcommand to show result of macro expansion

Related tags

Build system cargo
Overview

cargo-expand

github crates.io build status

Once installed, the following command prints out the result of macro expansion and #[derive] expansion applied to the current crate.

$ cargo expand

This is a wrapper around the more verbose compiler command:

$ cargo rustc --profile=check -- -Zunstable-options --pretty=expanded

Installation

Install with cargo install cargo-expand.

This command optionally uses rustfmt to format the expanded output. The resulting code is typically much more readable than what you get from the compiler. If rustfmt is not available, the expanded code is not formatted. Install rustfmt with rustup component add rustfmt.

Cargo expand relies on unstable compiler flags so it requires a nightly toolchain to be installed, though does not require nightly to be the default toolchain or the one with which cargo expand itself is executed. If the default toolchain is one other than nightly, running cargo expand will find and use nightly anyway.

Example

$ cat src/main.rs

#[derive(Debug)]
struct S;

fn main() {
    println!("{:?}", S);
}

$ cargo expand

#![feature(prelude_import)]
#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate std;
struct S;
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for S {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match *self {
            S => {
                let mut debug_trait_builder = f.debug_tuple("S");
                debug_trait_builder.finish()
            }
        }
    }
}
fn main() {
    {
        ::std::io::_print(::core::fmt::Arguments::new_v1(
            &["", "\n"],
            &match (&S,) {
                (arg0,) => [::core::fmt::ArgumentV1::new(arg0, ::core::fmt::Debug::fmt)],
            },
        ));
    };
}

Options

See cargo expand --help for a complete list of options, most of which are consistent with other Cargo subcommands. Here are a few that are common in the context of cargo expand.

To expand a particular test target:

$ cargo expand --test test_something

To expand without rustfmt:

$ cargo expand --ugly

To expand a specific module or type or function only:

$ cargo expand path::to::module

cargo expand punctuated::printing cargo expand token::FatArrow

Configuration

The cargo expand command reads the [expand] section of $CARGO_HOME/config if there is one (usually ~/.cargo/config).

Set the default syntax highlighting theme with the theme setting:

[expand]
theme = "TwoDark"

Run cargo expand --themes to print a list of available themes. Use theme = "none" to disable coloring.

Change the default coloring disposition (normally auto) with the color setting:

[expand]
color = "always"

Disclaimer

Be aware that macro expansion to text is a lossy process. This is a debugging aid only. There should be no expectation that the expanded code can be compiled successfully, nor that if it compiles then it behaves the same as the original code.

For instance the following function returns 3 when compiled ordinarily by Rust but the expanded code compiles and returns 4.

fn f() -> i32 {
    let x = 1;

    macro_rules! first_x {
        () => { x }
    }

    let x = 2;

    x + first_x!()
}

Refer to The Book for more on the considerations around macro hygiene.


License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Comments
  • cannot expand single item

    cannot expand single item

    I have an issue expanding a single item. I get the error "cannot expand single item (single::item) without rustfmt" it does give the hint to install rustfmt using "rustup component add rustfmt --toolchain nightly"

    however when i run that it says rustfmt is up to date. Even installing to stable is up to date. to the best I can tell rustfmt is installed fine for all toolchains.

    not sure if there is a bug or I am simply doing something wrong.

    opened by jeffwllms 20
  • Expanding tests

    Expanding tests

    Related to #20, but I can't seem to use the solution given there:

    $ cargo expand -- --test
    error: Invalid value for '<ITEM>': `--test` is not an identifier
    $ cargo expand --version
    cargo-expand 0.4.4
    

    How should I pass arguments to rustc with the addition of the cargo-expand arguments to expand specific items?

    opened by dbeckwith 13
  • `cargo expand` fails with memory allocation errors on Ubuntu 18.04

    `cargo expand` fails with memory allocation errors on Ubuntu 18.04

    I cannot get cargo expand to work at all on Ubuntu 18.04. I have replicated this issue in a VM running Ubuntu 18.04 as well. I am using the default example code

    #[derive(Debug)]
    struct S;
    
    fn main() {
        println!("{:?}", S);
    }
    

    but I have also tried with other code and get the same following result when I run cargo expand:

    vagrant@vagrant:~/prj/src$ cargo expand
        Checking prj v0.1.0 (/home/vagrant/prj)
        Finished check [unoptimized + debuginfo] target(s) in 0.07s
    
    memory allocation of 8391155392347897856 bytes failedAborted (core dumped)
    

    The number of bytes doesn't change between computers or between different code.

    I don't necessarily need $ cargo expand as $ cargo rustc --profile=check -- -Zunstable-options --pretty=expanded works perfectly but figured this was worth investigating.

    opened by tanyav2 11
  • Is it possible to use a pure rust lib rather than onig?

    Is it possible to use a pure rust lib rather than onig?

    Is it possible to use a pure rust lib rather than onig? I'm mostly asking this question so that the answer is documented. When it's not pure rust people can have trouble compiling with gcc on windows on gnu toolchain - it requires more setup and configuration of a windows machine than just installing rustup.

    As I said I'm sure there's some good reasons behind using onig versus depending on some parts of ripgrep, just would be nice to know so that I can stop wondering.... :-)

    opened by gilescope 8
  • UnicodeDecodeError

    UnicodeDecodeError

    cmd: cargo expand --color never version: v0.3.10

    Error:

    ** Error while highlighting:
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 1832403: ordinal not in range(128)
       (file "/usr/local/lib/python2.7/site-packages/Pygments-1.6-py2.7.egg/pygments/lexer.py", line 168, in get_tokens)
    

    I don't understand why pygments is invoked at all when using --color never. I can also reproduce without the option.

    opened by gnzlbg 8
  • Installing with cargo install fails due to semver breakage in onig_sys

    Installing with cargo install fails due to semver breakage in onig_sys

    Problem

    When using cargo install cargo-expand the compilation fails due to a semver-breaking release of onig_sys. This does not happen when building the repo using cargo build. This is due to Cargo.lock being pinned to a non-breaking version of onig_sys. cargo install doesn't seem to take the lock-file into account when installing it directly from crates.io.

    Error message on compilation

    $ cargo install cargo-expand
        Updating crates.io index
      Installing cargo-expand v0.4.12
       Compiling proc-macro2 v0.4.30
       Compiling unicode-xid v0.1.0
       Compiling libc v0.2.60
       Compiling syn v0.15.43
       Compiling cc v1.0.38
       Compiling memchr v2.2.1
       Compiling version_check v0.1.5
       Compiling failure_derive v0.1.5
       Compiling log v0.4.8
       Compiling rustc-demangle v0.1.15
       Compiling lazy_static v1.3.0
       Compiling byteorder v1.3.2
       Compiling cfg-if v0.1.9
       Compiling bitflags v1.1.0
       Compiling glob v0.3.0
       Compiling regex-syntax v0.6.11
       Compiling quick-error v1.2.2
       Compiling unicode-width v0.1.5
       Compiling strsim v0.8.0
       Compiling bindgen v0.50.0
       Compiling ansi_term v0.11.0
       Compiling vec_map v0.8.1
       Compiling termcolor v1.0.5
       Compiling semver-parser v0.7.0
       Compiling shlex v0.1.1
       Compiling peeking_take_while v0.1.2
       Compiling strsim v0.7.0
       Compiling pkg-config v0.3.15
       Compiling fnv v1.0.6
       Compiling ident_case v1.0.1
       Compiling autocfg v0.1.5
       Compiling crc32fast v1.2.0
       Compiling ryu v1.0.0
       Compiling serde v1.0.98
       Compiling safemem v0.3.1
       Compiling ppv-lite86 v0.2.5
       Compiling scopeguard v1.0.0
       Compiling smallvec v0.6.10
       Compiling encoding_index_tests v0.1.4
       Compiling itoa v0.4.4
       Compiling linked-hash-map v0.5.2
       Compiling unicode-segmentation v1.3.0
       Compiling derive_builder v0.7.2
       Compiling xml-rs v0.8.0
       Compiling same-file v1.0.5
       Compiling lazycell v1.2.1
       Compiling shell-words v0.1.0
       Compiling remove_dir_all v0.5.2
       Compiling thread_local v0.3.6
       Compiling nom v4.2.3
       Compiling error-chain v0.12.1
       Compiling humantime v1.2.0
       Compiling textwrap v0.11.0
       Compiling clang-sys v0.28.1
       Compiling backtrace-sys v0.1.31
       Compiling libloading v0.5.2
       Compiling miniz-sys v0.1.12
       Compiling ansi_colours v1.0.1
       Compiling semver v0.9.0
       Compiling bincode v1.1.4
       Compiling line-wrap v0.1.1
       Compiling lock_api v0.3.1
       Compiling encoding-index-singlebyte v1.20141219.5
       Compiling encoding-index-tradchinese v1.20141219.5
       Compiling encoding-index-japanese v1.20141219.5
       Compiling encoding-index-korean v1.20141219.5
       Compiling encoding-index-simpchinese v1.20141219.5
       Compiling c2-chacha v0.2.2
       Compiling yaml-rust v0.4.3
       Compiling walkdir v2.2.9
       Compiling heck v0.3.1
       Compiling rustc_version v0.2.3
       Compiling encoding v0.2.33
       Compiling atty v0.2.13
       Compiling getrandom v0.1.8
       Compiling termios v0.3.1
       Compiling clicolors-control v1.0.0
       Compiling dirs v1.0.5
       Compiling directories v1.0.2
       Compiling aho-corasick v0.7.6
       Compiling content_inspector v0.2.4
       Compiling fxhash v0.2.1
       Compiling base64 v0.10.1
       Compiling quote v0.6.13
       Compiling clap v2.33.0
       Compiling parking_lot_core v0.6.2
       Compiling parking_lot v0.9.0
       Compiling rand_core v0.5.0
       Compiling backtrace v0.3.34
       Compiling flate2 v1.0.9
       Compiling cexpr v0.3.5
       Compiling rand_chacha v0.2.1
       Compiling regex v1.2.1
       Compiling rand v0.7.0
       Compiling tempfile v3.1.0
       Compiling env_logger v0.6.2
       Compiling console v0.7.7
       Compiling toolchain_find v0.1.4
       Compiling synstructure v0.10.2
       Compiling darling_core v0.9.0
       Compiling serde_derive v1.0.98
       Compiling structopt-derive v0.2.18
       Compiling syn-select v0.1.4
       Compiling structopt v0.2.18
       Compiling failure v0.1.5
       Compiling which v2.0.1
       Compiling darling_macro v0.9.0
       Compiling plist v0.4.2
       Compiling serde_json v1.0.40
       Compiling toml v0.5.1
       Compiling darling v0.9.0
       Compiling derive_builder_core v0.5.0
       Compiling onig_sys v69.2.0
       Compiling onig v4.3.2
    error[E0412]: cannot find type `OnigRegexMut` in module `onig_sys`
       --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/lib.rs:142:20
        |
    142 |     raw: onig_sys::OnigRegexMut,
        |                    ^^^^^^^^^^^^ help: a type alias with a similar name exists: `OnigRegex`
    
    error[E0412]: cannot find type `OnigRegexMut` in module `onig_sys`
       --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/lib.rs:320:32
        |
    320 |         let mut reg: onig_sys::OnigRegexMut = null_mut();
        |                                ^^^^^^^^^^^^ help: a type alias with a similar name exists: `OnigRegex`
    
    error[E0412]: cannot find type `OnigRegexMut` in module `onig_sys`
       --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/lib.rs:321:50
        |
    321 |         let reg_ptr = &mut reg as *mut onig_sys::OnigRegexMut;
        |                                                  ^^^^^^^^^^^^ help: a type alias with a similar name exists: `OnigRegex`
    
    error[E0308]: mismatched types
       --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/lib.rs:326:18
        |
    326 |             enc: null(),
        |                  ^^^^^^ types differ in mutability
        |
        = note: expected type `*mut onig_sys::OnigEncodingTypeST`
                   found type `*const _`
    
    error[E0308]: mismatched types
       --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/lib.rs:327:18
        |
    327 |             par: null(),
        |                  ^^^^^^ types differ in mutability
        |
        = note: expected type `*mut u8`
                   found type `*const _`
    
    error[E0308]: mismatched types
       --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/lib.rs:328:22
        |
    328 |             par_end: null(),
        |                      ^^^^^^ types differ in mutability
        |
        = note: expected type `*mut u8`
                   found type `*const _`
    
    error[E0308]: mismatched types
       --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/lib.rs:341:17
        |
    341 |                 syntax as *const Syntax as *const onig_sys::OnigSyntaxType,
        |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ in mutability
        |
        = note: expected type `*mut onig_sys::OnigSyntaxType`
                   found type `*const onig_sys::OnigSyntaxType`
    
    error[E0308]: mismatched types
       --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/lib.rs:346:19
        |
    346 |         if err == onig_sys::ONIG_NORMAL {
        |                   ^^^^^^^^^^^^^^^^^^^^^ expected i32, found u32
    help: you can convert an `u32` to `i32` and panic if the converted value wouldn't fit
        |
    346 |         if err == onig_sys::ONIG_NORMAL.try_into().unwrap() {
        |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
    error[E0308]: mismatched types
       --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/lib.rs:515:17
        |
    515 |                 match_param.as_raw()
        |                 ^^^^^^^^^^^^^^^^^^^^ types differ in mutability
        |
        = note: expected type `*mut onig_sys::OnigMatchParamStruct`
                   found type `*const onig_sys::OnigMatchParamStruct`
    
    error[E0308]: mismatched types
       --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/lib.rs:704:17
        |
    704 |                 match_param.as_raw()
        |                 ^^^^^^^^^^^^^^^^^^^^ types differ in mutability
        |
        = note: expected type `*mut onig_sys::OnigMatchParamStruct`
                   found type `*const onig_sys::OnigMatchParamStruct`
    
    error[E0308]: mismatched types
       --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/find.rs:182:17
        |
    182 |                 scan_cb::<F>,
        |                 ^^^^^^^^^^^^ expected enum `std::option::Option`, found fn item
        |
        = note: expected type `std::option::Option<unsafe extern "C" fn(i32, i32, *mut onig_sys::re_registers, *mut std::ffi::c_void) -> i32>`
                   found type `extern "C" fn(i32, i32, *const onig_sys::re_registers, *mut std::ffi::c_void) -> i32 {find::<impl Regex>::scan_with_region::scan_cb::<F>}`
    
    error[E0308]: mismatched types
      --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/region.rs:24:22
       |
    24 |                 beg: null(),
       |                      ^^^^^^ types differ in mutability
       |
       = note: expected type `*mut i32`
                  found type `*const _`
    
    error[E0308]: mismatched types
      --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/region.rs:25:22
       |
    25 |                 end: null(),
       |                      ^^^^^^ types differ in mutability
       |
       = note: expected type `*mut i32`
                  found type `*const _`
    
    error[E0308]: mismatched types
      --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/region.rs:26:31
       |
    26 |                 history_root: null(),
       |                               ^^^^^^ types differ in mutability
       |
       = note: expected type `*mut onig_sys::OnigCaptureTreeNodeStruct`
                  found type `*const _`
    
    error[E0308]: mismatched types
      --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/region.rs:53:57
       |
    53 |             onig_sys::onig_region_copy(&mut region.raw, ptr);
       |                                                         ^^^ types differ in mutability
       |
       = note: expected type `*mut onig_sys::re_registers`
                  found type `*const onig_sys::re_registers`
    
    error[E0308]: mismatched types
      --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/region.rs:84:17
       |
    84 |         if r != onig_sys::ONIG_NORMAL {
       |                 ^^^^^^^^^^^^^^^^^^^^^ expected i32, found u32
    help: you can convert an `u32` to `i32` and panic if the converted value wouldn't fit
       |
    84 |         if r != onig_sys::ONIG_NORMAL.try_into().unwrap() {
       |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
    error[E0308]: mismatched types
       --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/region.rs:131:61
        |
    131 |         let tree = unsafe { onig_sys::onig_get_capture_tree(&self.raw) };
        |                                                             ^^^^^^^^^ types differ in mutability
        |
        = note: expected type `*mut onig_sys::re_registers`
                   found type `&onig_sys::re_registers`
    
    error[E0308]: mismatched types
       --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/region.rs:191:17
        |
    191 |                 &self.raw,
        |                 ^^^^^^^^^ types differ in mutability
        |
        = note: expected type `*mut onig_sys::re_registers`
                   found type `&onig_sys::re_registers`
    
    error[E0308]: mismatched types
       --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/region.rs:193:17
        |
    193 |                 traverse_cb::<F>,
        |                 ^^^^^^^^^^^^^^^^
        |                 |
        |                 expected enum `std::option::Option`, found fn item
        |                 help: try using a variant of the expected type: `Some(traverse_cb::<F>)`
        |
        = note: expected type `std::option::Option<unsafe extern "C" fn(i32, i32, i32, i32, i32, *mut std::ffi::c_void) -> i32>`
                   found type `extern "C" fn(i32, i32, i32, i32, i32, *mut std::ffi::c_void) -> i32 {region::Region::tree_traverse_at::traverse_cb::<F>}`
    
    error[E0308]: mismatched types
      --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/match_param.rs:30:17
       |
    30 |                 limit as c_uint
       |                 ^^^^^^^^^^^^^^^
       |                 |
       |                 expected u64, found u32
       |                 help: you can convert an `u32` to `u64`: `(limit as c_uint).into()`
    
    error[E0308]: mismatched types
      --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/names.rs:64:17
       |
    64 |                 foreach_cb::<F>,
       |                 ^^^^^^^^^^^^^^^ expected enum `std::option::Option`, found fn item
       |
       = note: expected type `std::option::Option<unsafe extern "C" fn(*const u8, *const u8, i32, *mut i32, *mut onig_sys::re_pattern_buffer, *mut std::ffi::c_void) -> i32>`
                  found type `extern "C" fn(*const u8, *const u8, i32, *const i32, *mut onig_sys::re_pattern_buffer, *mut std::ffi::c_void) -> i32 {names::<impl Regex>::foreach_name::foreach_cb::<F>}`
    
    error[E0308]: mismatched types
      --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/syntax.rs:99:51
       |
    99 |             let op = onig_sys::onig_get_syntax_op(&self.raw);
       |                                                   ^^^^^^^^^ types differ in mutability
       |
       = note: expected type `*mut onig_sys::OnigSyntaxType`
                  found type `&onig_sys::OnigSyntaxType`
    
    error[E0308]: mismatched types
       --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/syntax.rs:100:53
        |
    100 |             let op2 = onig_sys::onig_get_syntax_op2(&self.raw);
        |                                                     ^^^^^^^^^ types differ in mutability
        |
        = note: expected type `*mut onig_sys::OnigSyntaxType`
                   found type `&onig_sys::OnigSyntaxType`
    
    error[E0308]: mismatched types
       --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/syntax.rs:135:88
        |
    135 |         SyntaxBehavior::from_bits_truncate(unsafe { onig_sys::onig_get_syntax_behavior(&self.raw) })
        |                                                                                        ^^^^^^^^^ types differ in mutability
        |
        = note: expected type `*mut onig_sys::OnigSyntaxType`
                   found type `&onig_sys::OnigSyntaxType`
    
    error[E0308]: mismatched types
       --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/syntax.rs:160:85
        |
    160 |         RegexOptions::from_bits_truncate(unsafe { onig_sys::onig_get_syntax_options(&self.raw) })
        |                                                                                     ^^^^^^^^^ types differ in mutability
        |
        = note: expected type `*mut onig_sys::OnigSyntaxType`
                   found type `&onig_sys::OnigSyntaxType`
    
    error[E0308]: mismatched types
      --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/utils.rs:37:77
       |
    37 |         unsafe { onig_sys::onig_unicode_define_user_property(name.as_ptr(), raw_ranges.as_ptr()) };
       |                                                                             ^^^^^^^^^^^^^^^^^^^ types differ in mutability
       |
       = note: expected type `*mut u32`
                  found type `*const u32`
    
    error[E0308]: mismatched types
      --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/buffers.rs:28:18
       |
    27 |     fn encoding(&self) -> onig_sys::OnigEncoding {
       |                           ---------------------- expected `*mut onig_sys::OnigEncodingTypeST` because of return type
    28 |         unsafe { &onig_sys::OnigEncodingUTF8 }
       |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ in mutability
       |
       = note: expected type `*mut onig_sys::OnigEncodingTypeST`
                  found type `&onig_sys::OnigEncodingTypeST`
    
    error[E0308]: mismatched types
      --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/buffers.rs:97:27
       |
    97 |             enc: unsafe { &onig_sys::OnigEncodingASCII },
       |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ in mutability
       |
       = note: expected type `*mut onig_sys::OnigEncodingTypeST`
                  found type `&onig_sys::OnigEncodingTypeST`
    
    error[E0308]: mismatched types
       --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/flags.rs:263:13
        |
    263 |             onig_sys::ONIG_TRAVERSE_CALLBACK_AT_FIRST;
        |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected i32, found u32
    
    error[E0308]: mismatched types
       --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/flags.rs:266:13
        |
    266 |             onig_sys::ONIG_TRAVERSE_CALLBACK_AT_LAST;
        |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected i32, found u32
    
    error[E0308]: mismatched types
       --> /home/oruud/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/onig-4.3.2/src/flags.rs:269:13
        |
    269 |             onig_sys::ONIG_TRAVERSE_CALLBACK_AT_BOTH;
        |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected i32, found u32
    
    error: aborting due to 31 previous errors
    
    Some errors have detailed explanations: E0308, E0412.
    For more information about an error, try `rustc --explain E0308`.
    error: failed to compile `cargo-expand v0.4.12`, intermediate artifacts can be found at `/tmp/cargo-installgfq3Mf`
    
    Caused by:
      Could not compile `onig`.
    
    To learn more, run the command again with --verbose.
    

    Solution

    • syntec (the dependency which depends on onig) needs to:
    • prettyprint needs to:
      • [ ] depend on the new version of syntect
      • [ ] release a new version
    • cargo-expand needs to:
      • [ ] depend on new version of prettyprint
      • [ ] release a new version

    Workaround

    As mentionned in the introduction, one can still install this directly from the repo because then the Cargo.lock file is honored. However one has to use cargo build --release and then copy the resulting binary into a folder in the $PATH.

    opened by barskern 7
  • Expanding integration tests

    Expanding integration tests

    When running cargo expand --lib --tests integration tests (located in the tests folder) are not epanded. I have confirmed the the same tests as unit tests (located in src/lib.rs) are expanded properly.

    Is there a way to include the integration tests in the expansion?

    opened by bicarlsen 5
  • Switch to using syn-select

    Switch to using syn-select

    dtolnay/request-for-implementation#1 asked for a crate to handle syntactic filtering by path in a single file. syn-select is now available, matching the test cases specified in the original ticket.

    opened by TedDriggs 5
  • Specifying specific functions from an impl

    Specifying specific functions from an impl

    Surrectly it seems to only support modules and top-level things.

    Maybe it should also support expanding only specific impl or specific function inside impl?

    opened by vi 5
  • `cargo expand` hangs in an infinite loop

    `cargo expand` hangs in an infinite loop

    I try to expand that program

    extern crate pest;
    #[macro_use]
    extern crate pest_derive;
    
    #[derive(Parser)]
    #[grammar = "grm.pest"]
    pub struct MyParser;
    
    fn main() { }
    

    The grm.pest file:

    A = { "A" }
    B = { "B" }
    file = {
        SOI ~
        (( A | B )? ~ NEWLINE)* ~
        EOI
    }
    

    And cargo expand command hangs in an infinite loop.

    opened by chabapok 4
  • the option `Z` is only accepted on the nightly compiler

    the option `Z` is only accepted on the nightly compiler

    PS D:\RustProject\msg_chain> cargo expand
        Checking msg_chain v0.1.0 (D:\RustProject\msg_chain)
    error: the option `Z` is only accepted on the nightly compiler
    error: could not compile `msg_chain`
    To learn more, run the command again with --verbose.
    

    I am using stable tool chain

    installed toolchains
    --------------------
    
    stable-x86_64-pc-windows-msvc (default)
    nightly-x86_64-pc-windows-msvc
    
    active toolchain
    ----------------
    
    stable-x86_64-pc-windows-msvc (default)
    rustc 1.53.0 (53cb7b09b 2021-06-17)
    

    I think maybe cargo expand failure becuse my crate contain custom derive macro. And I create a crate named ctest with default code src/main.rs

    fn main() {
        println!("Hello, world!");
    }
    

    but cargo expand report the same error

    PS D:\RustProject\ctest> cargo expand
        Checking ctest v0.1.0 (D:\RustProject\ctest)
    error: the option `Z` is only accepted on the nightly compiler
    error: could not compile `ctest`
    To learn more, run the command again with --verbose.
    
    opened by Goodjooy 4
  • Is there a way to only expand an associated function on a type?

    Is there a way to only expand an associated function on a type?

    struct MyType {
        foo: usize,
    }
    impl MyType {
        fn print_foo(&self) {
            println!("{}", self.foo);
        }
    }
    

    Currently it seems like the only way to expand MyType::print_foo is to expand the entire module, or at least I haven't found a way to accomplish this. Is there a particular syntax for this that I'm missing?

    If not, please see this as a feature request. Much thanks. =)

    opened by cyqsimon 0
  • Can cargo-expand only expand procedural-macro, not including declarative macros?

    Can cargo-expand only expand procedural-macro, not including declarative macros?

    I want to define and export declarative macros inside procedural-macro. For debug use, I want to see the exact declarative macros. Below is a simple example.

    #[proc_macro]
    pub fn example_macro(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
        quote!(
            #[macro_export]
            macro_rules! print_hello {
                () => (
                    println!("hello world");
                )
            }
        ).into()
    }
    

    I only want to expand example_macro, but not print_hello inside, is this possible? Thanks a lot.

    opened by StevenJiang1110 0
  • Compiling Result from expand

    Compiling Result from expand

    Hello,

    We are trying to debug and learn some complex macros(codegens), but currently, the result fromcargo expand cannot be compiled(I think it is intended based on the disclaimer). May I know if there is any way to generate an expanded code but compilable?

    Thank you!

    opened by QiLOL 0
  • Request: Expand doctests

    Request: Expand doctests

    I know this is an extremely niche thing to want, but the macro im working on fails in doctests where it succeeds in other code. Being able to expand the doctests would be very helpful to understand what is happening here (Ive tried: cargo expand --lib --tests doesnt include doctests. im guessing there's some hidden target I can point it at but my searches of the documentation turn up nothing)

    opened by drewcassidy 0
  • Ignoring path to argument

    Ignoring path to argument

    I find that cargo expand is ignoring the cargo expand path::to::module syntax.

    I suspect this is related to #31 and probably because I am using a multi binary crate --- specifically https://github.com/phillord/horned-owl.

    For example:

    cargo expand
    error: extra arguments to `rustc` can only be passed to one target, consider filtering
    the package by passing, e.g., `--lib` or `--bin NAME` to specify a single target
    

    Likewise, attempting to limit to one lib

    cargo expand io::xml::writer
    error: extra arguments to `rustc` can only be passed to one target, consider filtering
    the package by passing, e.g., `--lib` or `--bin NAME` to specify a single target
    

    Using --lib expands everything.

    cargo expand --lib io::writer::xml
    #[prelude_import]
    use std::prelude::rust_2018::*;
    #[macro_use]
    extern crate std;
    //extern crate curie;
    //extern crate enum_meta;
    #[macro_use]
    extern crate failure;
    //#[macro_use]
    extern crate indexmap;
    extern crate log;
    extern crate quick_xml;
    ..........
    

    --bin works however

    cargo expand --bin horned-triples
    cargo expand --bin horned-triples | more
        Checking horned-owl v0.9.0 (/tmp/horned-owl)
        Finished check [unoptimized + debuginfo] target(s) in 3.49s
    
    #![feature(prelude_import)]
    #[prelude_import]
    use std::prelude::rust_2018::*;
    #[macro_use]
    extern crate std;
    extern crate clap;
    extern crate failure;
    extern crate horned_owl;
    use clap::App;
    use clap::Arg;
    use clap::ArgMatches;
    use failure::Error;
    use horned_owl::error::CommandError;
    use std::fs::File;
    ...........
    
    opened by phillord 3
Releases(1.0.36)
Owner
David Tolnay
David Tolnay
Provide expansion of proc-macros, in a way that rustc directs you directly to the issues at hand

expander Expands a proc-macro into a file, and uses a include! directive in place. Advantages Only expands a particular proc-macro, not all of them. I

Bernhard Schuster 16 Oct 5, 2022
An experimental, well-documented and expansion-ready virtual machine written in Rust.

Notice ivm is undergoing a complete refactor. ivm ivm is a rich, well-documented virtual machine written in Rust. Pros Documentation everywhere. Every

Imajin 4 Jul 9, 2022
Safe Unix shell-like parameter expansion/variable substitution via cross-platform CLI or Rust API

Safe Unix shell-like parameter expansion/variable substitution for those who need a more powerful alternative to envsubst but don't want to resort to

Isak Wertwein 4 Oct 4, 2022
The [cain!] macro is a macro that rewrites sequential Rust branch statements into nested branches

Note! This crate is experimental and under development. It may include bugs that alter the behavior of your code in unexpected ways. You should review

Fredrik Østrem 2 Jan 19, 2022
Simple rust asset handling derive macro for enums, and a proc-macro learning resource!

asset-derive Summary • Todos • Docs Summary Simple Rust asset loading derive macro for Enums, and a resource for learning proc-macros! Please feel fre

Shadorain 5 Feb 9, 2023
The cumulative sibling of `Result` and `Either`.

validated The cumulative sibling of Result and Either. The Validated type has special FromIterator instances that enable all errors in a sequence to b

Colin Woodbury 17 Nov 13, 2022
A CLI command to parse kustomize build result and notify it to GitLab

ksnotify A CLI command to parse kustomize build result and notify it to GitLab Caution This repository is under development status. What ksnotify does

null 7 Jan 2, 2023
Automatically check for SPF misconfigurations that could result in email spoofing

SPFJack Email spoofing is dead, but misconfiguration never dies. Purpose This project is designed to take in domain names and review their SPF records

Alex (LunarCA) 2 Mar 27, 2022
Allows processing of iterators of Result types

try-continue try-continue provides one method, try_continue, which allows you to work with iterators of type Result<T, _>, as if they were simply iter

Nick Krichevsky 3 Dec 26, 2021
wrap errors with automatic backtrace capture and print-on-result-unwrap

backtrace-error This is a tiny crate that provides a tiny error-wrapper struct BacktraceError with only two features: Captures a backtrace on From-con

Graydon Hoare 24 Nov 19, 2022
CLI tool that make it easier to perform multiple lighthouse runs towards a single target and output the result in a "plotable" format.

Lighthouse Groupie CLI tool that make it easier to perform multiple lighthouse runs towards a single target and output the result in a "plotable" form

Polestar 1 Jan 12, 2022
CLI tool that make it easier to perform multiple lighthouse runs towards a single target and output the result in a plotable format.

Lighthouse Aggregator CLI tool that make it easier to perform multiple lighthouse runs towards a single target and output the result in a "plotable" f

Polestar 1 Jan 12, 2022
A (mostly) drop-in replacement for Rust's Result that provides backtrace support

Errant A (mostly) drop-in replacement for Rust's Result that provides backtrace support. Please note that Errant is still very early in development an

Joshua Barretto 17 Dec 26, 2022
This rust library is to get lottery monthly result loto6, numbers3 and numbers4

Scraping Japanese Lottery Site this library is to get lottery monthly result loto6, numbers3 and numbers4. scraping japanese lottery site from https:/

kubocker 5 Aug 14, 2023
A rust crate can find first `Err` in `Iterator>` and iterating continuously, without allocation.

Api Document first-err Find the first Err in Iterator<Result<T, E>> and allow iterating continuously. This crate is specifically designed to replace t

null 3 Oct 28, 2023
Cargo subcommand to automatically create universal libraries for iOS.

cargo lipo Provides a cargo lipo subcommand which automatically creates a universal library for use with your iOS application. Maintenance Status Plea

Tim Neumann 430 Dec 29, 2022
A very simple third-party cargo subcommand to execute a custom command

cargo-x A very simple third-party cargo subcommand to execute a custom command Usage install cargo-x cargo install cargo-x or upgrade cargo install -

刘冲 9 Dec 26, 2022
Automated license checking for rust. cargo lichking is a Cargo subcommand that checks licensing information for dependencies.

cargo-lichking Automated license checking for rust. cargo lichking is a Cargo subcommand that checks licensing information for dependencies. Liches ar

Nemo157 120 Dec 19, 2022
a cargo subcommand for counting lines of code in Rust projects

cargo-count Linux: A cargo subcommand for displaying line counts of source code in projects, including a niave unsafe counter for Rust source files. T

Kevin K. 125 Dec 1, 2022
A cargo subcommand for creating GraphViz DOT files and dependency graphs

cargo-graph Linux: A cargo subcommand for building GraphViz DOT files of dependency graphs. This subcommand was originally based off and inspired by t

Kevin K. 213 Nov 24, 2022