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

The conflict between argh and anyhow #193

Open
twang2218 opened this issue Nov 29, 2024 · 0 comments
Open

The conflict between argh and anyhow #193

twang2218 opened this issue Nov 29, 2024 · 0 comments

Comments

@twang2218
Copy link

To reproduce the issue, here is the code:

use anyhow::Ok;
use argh::FromArgs;

#[derive(FromArgs)]
/// A simple CLI tool
struct Args {
    /// the input file
    #[argh(option)]
    input: String,
}

fn main() -> anyhow::Result<()> {
    let args: Args = argh::from_env();
    println!("Hello, world!: input: {}", args.input);
    Ok(())
}

cargo build output:

cargo build
   Compiling argh_vs_anyhow v0.1.0 (/Users/tao/lab/rust/fortune/project/argh_vs_anyhow)
error[E0308]: mismatched types
 --> src/main.rs:4:10
  |
4 | #[derive(FromArgs)]
  |          ^^^^^^^^
  |          |
  |          expected `Result<Args, EarlyExit>`, found `Result<Args, Error>`
  |          expected `Result<Args, EarlyExit>` because of return type
  |
  = note: expected enum `Result<_, EarlyExit>`
             found enum `Result<_, anyhow::Error>`
  = note: this error originates in the derive macro `FromArgs` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
 --> src/main.rs:4:10
  |
4 | #[derive(FromArgs)]
  |          ^^^^^^^^ expected `Result<String, String>`, found `Result<String, Error>`
  |
  = note: expected enum `Result<_, String>`
             found enum `Result<_, anyhow::Error>`
  = note: this error originates in the derive macro `FromArgs` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
 --> src/main.rs:4:10
  |
4 | #[derive(FromArgs)]
  |          ^^^^^^^^
  |          |
  |          expected `Result<Vec<String>, EarlyExit>`, found `Result<Vec<String>, Error>`
  |          expected `Result<Vec<String>, EarlyExit>` because of return type
  |
  = note: expected enum `Result<_, EarlyExit>`
             found enum `Result<_, anyhow::Error>`
  = note: this error originates in the derive macro `FromArgs` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0308`.
error: could not compile `argh_vs_anyhow` (bin "argh_vs_anyhow") due to 3 previous errors

anyhow::Ok conflicted with core::result::Result Ok, so, I believe the fully qualified type path should be used in argh code to avoid the conflict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant