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

values_of ... len() panics due to exact_size #3241

Closed
2 tasks done
FauxFaux opened this issue Jan 2, 2022 · 1 comment · Fixed by #3247
Closed
2 tasks done

values_of ... len() panics due to exact_size #3241

FauxFaux opened this issue Jan 2, 2022 · 1 comment · Fixed by #3247
Labels
A-builder Area: Builder API C-bug Category: Updating dependencies E-easy Call for participation: Experience needed to fix: Easy / not much

Comments

@FauxFaux
Copy link

FauxFaux commented Jan 2, 2022

Please complete the following tasks

  • I have searched the discussions
  • I have searched the existing issues

Rust Version

1.58.0-nightly

Clap Version

3.0.0

Minimal reproducible code

fn main() {
    clap::App::new("boog").arg(
            clap::Arg::new("POTATO")
            .takes_value(true)
            .multiple_values(true)
            .required(true)
        )
        .get_matches()
        .values_of("POTATO")
        .expect("present")
        .len();
}

Steps to reproduce the bug with the above code

RUST_BACKTRACE=1 cargo run foo bars

Actual Behaviour

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `None`,
 right: `Some(0)`', /rustc/dd549dcab404ec4c7d07b5a83aca5bdd7171138f/library/core/src/iter/traits/exact_size.rs:108:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/dd549dcab404ec4c7d07b5a83aca5bdd7171138f/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/dd549dcab404ec4c7d07b5a83aca5bdd7171138f/library/core/src/panicking.rs:107:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
             at /rustc/dd549dcab404ec4c7d07b5a83aca5bdd7171138f/library/core/src/panicking.rs:145:5
   4: core::iter::traits::exact_size::ExactSizeIterator::len
             at /rustc/dd549dcab404ec4c7d07b5a83aca5bdd7171138f/library/core/src/iter/traits/exact_size.rs:108:9
   5: toke::main
             at ./src/main.rs:2:5

Expected Behaviour

len() == 2

Additional Context

Maybe something to do with ExactSizeIterator's rules about size_hint?

Debug Output

[      clap::parse::validator] 	Validator::validate_matched_args:iter:POTATO: vals=Flatten {
    inner: FlattenCompat {
        iter: Fuse {
            iter: Some(
                Iter(
                    [
                        [
                            "foo",
                            "bars",
                        ],
                    ],
                ),
            ),
        },
        frontiter: None,
        backiter: None,
    },
}
[      clap::parse::validator] 	Validator::validate_arg_num_vals
[      clap::parse::validator] 	Validator::validate_arg_values: arg="POTATO"
[      clap::parse::validator] 	Validator::validate_arg_num_occurs: "POTATO"=2
[    clap::parse::arg_matcher] 	ArgMatcher::get_global_values: global_arg_vec=[help]
thread 'main' panicked at 'assertion failed: `(left == right)`
@FauxFaux FauxFaux added the C-bug Category: Updating dependencies label Jan 2, 2022
epage added a commit to epage/clap that referenced this issue Jan 3, 2022
I was tempted to remove the exact-size nature.  Wouldn't be breaking
since it only panics but decided to go ahead and do this for now.

Fixes clap-rs#3241
epage added a commit to epage/clap that referenced this issue Jan 3, 2022
I was tempted to remove the exact-size nature.  Wouldn't be breaking
since it only panics but decided to go ahead and do this for now.

Fixes clap-rs#3241
@epage epage added A-builder Area: Builder API E-easy Call for participation: Experience needed to fix: Easy / not much labels Jan 3, 2022
@epage
Copy link
Member

epage commented Jan 3, 2022

v3.0.1 is now released with the fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-builder Area: Builder API C-bug Category: Updating dependencies E-easy Call for participation: Experience needed to fix: Easy / not much
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants