Skip to content

Map search benches are incorrect #22134

Closed
@Gankra

Description

@Gankra

the find closure being passed into collections::bench::find_*_n in BTreeMap and VecMap's benches has a trailing semi-colon making the return value (), and thus making the entire operation a no-op.

    #[bench]
    pub fn find_seq_100(b: &mut Bencher) {
        let mut m = BTreeMap::new();
        find_seq_n(100, &mut m, b,
                   |m, i| { m.insert(i, 1); },
                   |m, i| { m.get(&i); });
                                     ^~~~~ big trouble in little BTreeMap town
    }

Removing the semi-colon causes lifetime conflict issues.

map.rs:1882:32: 1882:39 error: cannot infer an appropriate lifetime for autoref due to conflicting requirements
map.rs:1882                     |m, i| { m.get(&i) });
                                           ^~~~~~~
map.rs:1880:9: 1880:20 note: first, the lifetime cannot outlive the expression at 1880:8...
map.rs:1880         find_rand_n(100, &mut m, b,
                    ^~~~~~~~~~~
map.rs:1880:9: 1880:20 note: ...so that the declared lifetime parameter bounds are satisfied
map.rs:1880         find_rand_n(100, &mut m, b,
                    ^~~~~~~~~~~
map.rs:1882:30: 1882:31 note: but, the lifetime must be valid for the expression at 1882:29...
map.rs:1882                     |m, i| { m.get(&i) });
                                         ^
map.rs:1882:30: 1882:31 note: ...so that auto-reference is valid at the time of borrow
map.rs:1882                     |m, i| { m.get(&i) });

CC @alexcrichton

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions