typestate-rs
typestate-rs copied to clipboard
Labeling a function in a trait `pub` gives misleading "Non-productive state" diagnostic
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);
}
}