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

std::getopt::opts_str fails for arguments other than the first one #6492

Closed
bruceiv opened this issue May 15, 2013 · 1 comment
Closed

std::getopt::opts_str fails for arguments other than the first one #6492

bruceiv opened this issue May 15, 2013 · 1 comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@bruceiv
Copy link

bruceiv commented May 15, 2013

I'm new to Rust, so it's possible I'm doing something wrong, but I can't get std::getopt::opts_str to work for any argument but the first one given (I'm running Rust 0.6). I've tried some other permutations, but here's a minimal test case:

extern mod std;
use std::getopts::*;

fn main() {
    let args = os::args();

    let opts = ~[
        optopt("a"), optopt("arg")
    ];

    let matches = match getopts(vec::tail(args), opts) {
        result::Ok(m)  => { m }
        result::Err(f) => { io::println(fail_str(f)); return }
    };

    if opts_present(&matches, [~"a", ~"arg"]) {
        io::println(fmt!("Argument `%s`", opts_str(&matches, [~"a", ~"arg"])));
        return;
    }
}

and here's the output of some invocations (the expected result would be for the second line to output the same as first):

% rustc test.rs
% ./test -a foo   
Argument `foo`
% ./test --arg foo
rust: task failed at 'index out of bounds: the len is 0 but the index is 0', /home/aaron/Downloads/rust-0.6/src/libstd/getopts.rs:360
@emberian
Copy link
Member

Updated testcase:

extern mod extra;
use extra::getopts::*;

fn main() {
    let args = std::os::args();

    let opts = ~[
        optopt("a"), optopt("arg")
    ];

    let matches = match getopts(args.tail(), opts) {
        Ok(m)  => m,
        Err(f) => fail!(fail_str(f))
    };

    if opts_present(&matches, [~"a", ~"arg"]) {
        println(fmt!("Argument `%s`", opts_str(&matches, [~"a", ~"arg"])));
        return;
    }
}

I think this is a bug in getopts, not positive.

bors added a commit that referenced this issue Jul 31, 2013
Fix std::getopt::opts_str

Closes #6492 (std::getopt::opts_str fails for arguments other than the first one).
@bors bors closed this as completed in ed0f014 Jul 31, 2013
flip1995 pushed a commit to flip1995/rust that referenced this issue Nov 23, 2021
Add Clippy version to Clippy's lint list

Hey, hey, the semester is finally over, and I wanted to get back into hacking on Clippy. It has also been some time since our metadata collection monster has been feed. So, this PR adds a new attribute `clippy::version` to document which version a lint was stabilized. I considered using `git blame` but that would be very hacky and probably not accurate.

I'm also thinking that this attribute can be used to have a `clippy::nightly` lint group which is allow-by-default that delays setting the actual lint group until the defined version is reached. Just something to consider regarding rust-lang#6623 🙃

This PR only adds the version to 4 lints to keep it reviewable. I'll do a followup PR to add the version to other lints if the implementation is accepted 🙃

![image](https://user-images.githubusercontent.com/17087237/137118859-0aafdfdf-7595-4289-8ba4-33d58eb6991d.png)

Also, mobile approved xD

![image](https://user-images.githubusercontent.com/17087237/137118944-833cf7fb-a4a1-45d6-9af8-32c951822360.png)

---

r? `@flip1995`

cc: rust-lang#7172

closes: rust-lang#6492

changelog: [Clippy's lint list](https://rust-lang.github.io/rust-clippy/master/index.html) now displays the version a lint was added. 🎉

---

Example lint declaration after this update:

```rs
declare_clippy_lint! {
    /// [...]
    ///
    /// ### Example
    /// ```rust
    /// // Bad
    /// let x = 3.14;
    /// // Good
    /// let x = std::f32::consts::PI;
    /// ```
    #[clippy::version = "pre 1.29.0"]
    pub APPROX_CONSTANT,
    correctness,
    "the approximate of a known float constant (in `std::fXX::consts`)"
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants