Comments (4)
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 _
in that expression? I don't think this program should compile!
If you change the let
to:
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 Args
, Rust infers the type to be... nil
? Huh? Very strange.
@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 rustc
or is it intended behavior?
from docopt.rs.
Whoa, this is surprising! I've opened an issue on this: rust-lang/rust#21878
from docopt.rs.
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.
from docopt.rs.
@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?
from docopt.rs.
Related Issues (20)
- Panic on duplicates in the options section
- argument name with `_` underscore is misaligned to `-` hyphen HOT 1
- Could not compile by docopt_macros error at macro.rs line 187 HOT 1
- Silent breaking change in docopt 0.8.2 HOT 1
- Linking error during compilation HOT 1
- Strange behavior if subcommand starts with program name
- When repeated short and long =value flags are aliases, only one is deserialised HOT 2
- trouble with argument lists split over multiple lines HOT 1
- Allow Overlapping Option and Usage Flags for Documentation
- 1.1.0 Does not compile HOT 5
- Would `docopt_macros` still require nightly? HOT 1
- -h in priority
- Optional argument parsed as None instead of Some(_) if using '_' in option name
- Huge amount of memory used and very slow when parsing many arguments HOT 2
- get_vec and the borrow checker play badly together HOT 1
- Hidden undocumented options? HOT 1
- Positional arguments are misparsed as --required arguments HOT 4
- [Issue] Optional arguments in final array HOT 1
- Does docopt-style API scale to the complex use-cases? HOT 2
- Reverse order of usage strings HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docopt.rs.