-
Notifications
You must be signed in to change notification settings - Fork 83
Docopt causes nil value panic when called with no arguments. #89
Comments
Oh my. This is a very interesting bug! This code also triggers it, without the macro: extern crate "rustc-serialize" as rustc_serialize;
extern crate docopt;
static USAGE: &'static str = "
Usage: misc [options]
Options:
-h, --help Show this message.
";
#[derive(RustcDecodable)]
struct Args {
pub flag_help: bool,
}
fn main() {
let _ = docopt::Docopt::new(USAGE).and_then(|d| d.decode())
.unwrap_or_else(|e| e.exit());
} Notice anything funny? What is the type of If you change the let _: Args = docopt::Docopt::new(USAGE).and_then(|d| d.decode())
.unwrap_or_else(|e| e.exit()); Then all is well. Somehow, in the absence of @alexchandel In your case, you should use: let _: Args = Args::docopt().decode().unwrap_or_else(|e| e.exit()); and it should work. This is a terrible failure mode though. I'm not sure how to improve it. @alexcrichton Does this look like a bug in |
Whoa, this is surprising! I've opened an issue on this: rust-lang/rust#21878 |
I'm going to close this because it's being tracked upstream in Rust proper. I'm not sure there's much we can do here. |
@BurntSushi : The corresponding issue was closed upstream but is still relevant here (type inference fails). Would you accept a PR adding a comment that specifying the type is necessary to avoid this panic? |
The following minimal docopt program, which takes no parameters, panics when called without any arguments:
The panic message is:
This should not happen, because it makes it impossible to have a program take no arguments and read from stdin, with '[-]'.
The text was updated successfully, but these errors were encountered: