typestate-rs icon indicating copy to clipboard operation
typestate-rs copied to clipboard

Labeling a function in a trait `pub` gives misleading "Non-productive state" diagnostic

Open Dessix opened this issue 2 years ago • 0 comments

I just tripped myself up on this one for a little while by porting an impl block to trait signatures.

The error message is misleading for syntax that would otherwise be flat-out invalid.

#[typestate]
mod traffic_light {
    #[automaton]
    pub struct TrafficLight;

    #[state]
    pub struct Green; // Errors with "Non-productive state. For a state to be productive..."
    #[state]
    pub struct Red;

    pub trait Green {
        fn turn_on() -> Green;
        pub fn to_red(self) -> Red;
    }
    pub trait Red {
        fn turn_off(self);
    }
}

Dessix avatar Jul 08 '22 21:07 Dessix