cargo-expand icon indicating copy to clipboard operation
cargo-expand copied to clipboard

Ignoring path to argument

Open phillord opened this issue 3 years ago • 3 comments

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;
...........

phillord avatar Mar 19 '21 15:03 phillord

cargo expand --lib foo::bar not only ignores the scope and generates everything in the crate, it also claims that WARNING: no such item: foo::bar regardless of whether this item actually exists or not. Even using the crate's name only, i.e. foo doesn't work, foo::bar::SomeStruct doesn't either

edit: above has been tested using the following toolchains: stable-x86_64-apple-darwin (default) nightly-x86_64-apple-darwin

switching to nightly as default or override has no effect

thorstenfrank avatar Jul 28 '22 19:07 thorstenfrank

@thorstenfrank Don't include the crate name in the path.

I can't reproduce the original report in this issue. I tried all sorts of various paths like io::rdf::reader::vocab_lookup in the given repo, and it expands as expected. If someone has a specific reproduction, please share it. Otherwise I think this can be closed.

ehuss avatar Jul 28 '22 22:07 ehuss

@ehuss you're absolutely right, works perfectly when omitting the crate. Thank you!

thorstenfrank avatar Jul 29 '22 04:07 thorstenfrank