Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
d-e-s-o opened this issue Aug 25, 2020 · 3 comments · Fixed by #425 or tbillington/kondo#34
Closed

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

d-e-s-o opened this issue Aug 25, 2020 · 3 comments · Fixed by #425 or tbillington/kondo#34

Comments

@d-e-s-o
Copy link

d-e-s-o commented Aug 25, 2020

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?

@d-e-s-o
Copy link
Author

d-e-s-o commented Aug 25, 2020

I played around a bit with quote. And I can get the original building with the following patch:

--- src/runtime.rs
+++ src/runtime.rs
@@ -228,7 +228,7 @@ pub fn push_ident_spanned(tokens: &mut TokenStream, span: Span, s: &str) {
     if s.starts_with("r#") {
         parse_spanned(tokens, span, s);
     } else {
-        tokens.append(Ident::new(s, span));
+        tokens.append(Ident::new(s, Span::call_site()));
     }
 }

Not really sure what this means, though. ¯\_(-_-)_/¯

@CreepySkeleton
Copy link
Collaborator

That means that the app ident created via quote_spanned (with non-call_site span) and the app ident created via quote are two different identifiers entirely. Long story short: every token in source code has a span (kinda like original location but it's complicated) information which is a part of macro hygiene rules. Idents may have the same "value" (app == app), but may have different span info, and then they're different idents.

The app here should be call_site, that's an error I'll fix shortly.

@d-e-s-o
Copy link
Author

d-e-s-o commented Aug 25, 2020

Awesome!

d-e-s-o added a commit to d-e-s-o/nitrocli that referenced this issue Aug 26, 2020
This change updates the structopt crate to version 0.3.13. We need this
version as it fixes a compilation error [0] when using the
external_subcommand enum variant annotation provided by the crate. This
functionality will be used in a follow up change that enables usage of
user provided extensions.

[0]: TeXitoi/structopt#424
d-e-s-o added a commit to d-e-s-o/nitrocli that referenced this issue Sep 5, 2020
This change updates the structopt crate to version 0.3.13. We need this
version as it fixes a compilation error [0] when using the
external_subcommand enum variant annotation provided by the crate. This
functionality will be used in a follow up change that enables usage of
user provided extensions.

[0]: TeXitoi/structopt#424
d-e-s-o added a commit to d-e-s-o/nitrocli that referenced this issue Sep 7, 2020
This change updates the structopt crate to version 0.3.13. We need this
version as it fixes a compilation error [0] when using the
external_subcommand enum variant annotation provided by the crate. This
functionality will be used in a follow up change that enables usage of
user provided extensions.

[0]: TeXitoi/structopt#424
d-e-s-o added a commit to d-e-s-o/nitrocli that referenced this issue Sep 7, 2020
This change updates the structopt crate to version 0.3.13. We need this
version as it fixes a compilation error [0] when using the
external_subcommand enum variant annotation provided by the crate. This
functionality will be used in a follow up change that enables usage of
user provided extensions.

[0]: TeXitoi/structopt#424
d-e-s-o added a commit to d-e-s-o/nitrocli that referenced this issue Jan 11, 2021
This change updates the structopt crate to version 0.3.17. We need this
version as it fixes a compilation error [0] when using the
external_subcommand enum variant annotation provided by the crate. This
functionality will be used in a follow up change that enables usage of
user provided extensions.

[0]: TeXitoi/structopt#424
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants