Coder Social home page Coder Social logo

Comments (4)

BurntSushi avatar BurntSushi commented on June 13, 2024

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.

alexcrichton avatar alexcrichton commented on June 13, 2024

Whoa, this is surprising! I've opened an issue on this: rust-lang/rust#21878

from docopt.rs.

BurntSushi avatar BurntSushi commented on June 13, 2024

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.

caipre avatar caipre commented on June 13, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.