Skip to content

error[E0425]: cannot find value app in this scope #424

@d-e-s-o

Description

@d-e-s-o

I have the following code:

use structopt::StructOpt;

macro_rules! Command {
  ( $name:ident, [
    #[$meta:meta] $var:ident($inner:ty)
  ] ) => {
    #[derive(Debug, PartialEq, structopt::StructOpt)]
    enum $name {
      #[$meta] $var($inner),
    }
  };
}

Command! {GitCmd, [
  #[structopt(external_subcommand)]
  Ext(Vec<String>)
]}

// Works:
//#[derive(Debug, PartialEq, StructOpt)]
//enum GitCmd {
//  #[structopt(external_subcommand)]
//  Ext(Vec<String>),
//}

fn main() {
  assert_eq!(
    GitCmd::from_iter(&["test", "git", "status"]),
    GitCmd::Ext(vec!["git".to_string(), "status".to_string()]),
  );
}

And it fails to compile (0.3.16, default features):

error[E0425]: cannot find value `app` in this scope
 --> src/main.rs:7:32
  |
7 |     #[derive(Debug, PartialEq, structopt::StructOpt)]
  |                                ^^^^^^^^^^^^^^^^^^^^ not found in this scope

error: aborting due to previous error

For more information about this error, try `rustc --explain E0425`.
error: could not compile `foo`.

To learn more, run the command again with --verbose.

I checked the expanded output and everything seems perfectly fine.

So then I came up with the following patch to structopt-derive:

--- lib.rs
+++ lib.rs
@@ -481,7 +481,7 @@ fn gen_augment_clap_enum(
         let kind = attrs.kind();
         match &*kind {
             Kind::ExternalSubcommand => {
-                quote_spanned! { attrs.kind().span()=>
+                quote! {
                     let app = app.setting(
                         ::structopt::clap::AppSettings::AllowExternalSubcommands
                     );

And now everything works. I am not really sure what to make of that. I checked the quote_spanned macro but nothing stood out. Any ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions