Skip to content

Use param type to help Rust inference #5

@RReverser

Description

@RReverser

Currently, if I try to use types like this:

#[proptest]
fn test_ra(#[strategy(0..=24)] h: u8, #[strategy(0..60)] m: u8, #[strategy(0..60)] s: u8) {

I get an error like:

error[E0271]: type mismatch resolving `<RangeInclusive<i32> as proptest::strategy::Strategy>::Value == u8`
   --> src\coords\astro.rs:279:27
    |
279 |     fn test_ra(#[strategy(0..=24)] h: u8, #[strategy(0..60)] m: u8, #[strategy(0..60)] s: u8) {
    |                           ^ expected `u8`, found `i32`
    |
note: required by a bound in `_strategy_of_h`
   --> src\coords\astro.rs:279:39
    |
278 |     #[proptest]
    |     ----------- required by a bound in this
279 |     fn test_ra(#[strategy(0..=24)] h: u8, #[strategy(0..60)] m: u8, #[strategy(0..60)] s: u8) {
    |                                       ^^ required by this bound in `_strategy_of_h`

So, just like when using strategies directly in proptest!, I have to add suffixes to clarify which type I meant and then it works:

#[proptest]
fn test_ra(#[strategy(0..=24_u8)] h: u8, #[strategy(0..60_u8)] m: u8, #[strategy(0..60_u8)] s: u8) {

However, test_strategy has more info that regular proptest! macro does - namely, it has access to explicit parameter types. Could it perhaps pass those through to corresponding generics to make inference work correctly without explicit suffixes?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions