Skip to content

Emit dummy StructOpt impl when reporting errors #240

@dtolnay

Description

@dtolnay

Currently when structopt-derive reports an error, only the compile_error is emitted. That means the author will see both the compile_error and most likely an error about a missing StructOpt impl.

error: `CARGO_PKG_VERSION` environment variable is not defined, use `version = "version" to set it manually or `no_version` to not set it at all
 --> src/main.rs:5:10
  |
5 | #[derive(StructOpt, Debug)]
  |          ^^^^^^^^^

error[E0599]: no function or associated item named `from_args` found for type `Opt` in the current scope
  --> src/main.rs:44:20
   |
7  | struct Opt {
   | ---------- function or associated item `from_args` not found for this
...
44 |     let opt = Opt::from_args();
   |                    ^^^^^^^^^ function or associated item not found in `Opt`
   |
   = help: items from traits can only be used if the trait is implemented and in scope
   = note: the following trait defines an item `from_args`, perhaps you need to implement it:
           candidate #1: `structopt::StructOpt`

error: aborting due to 2 previous errors

It would be nicer to emit a dummy StructOpt impl in addition to the error. Nothing in the impl will be called because the crate doesn't compile from the compile_error, but this way the author gets less useless errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementWe would love to have this feature! Feel free to supply a PR

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions