-
Notifications
You must be signed in to change notification settings - Fork 10
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
Incorrect type is generated when using generics #27
Comments
I found the issue. Consider the following minimal example: use typestate::typestate;
#[typestate]
mod my_state {
#[automaton]
pub struct Automaton;
#[state]
pub struct S<T>(T);
pub trait S {
fn new<T>() -> S<T>;
fn end(self);
}
}
fn main() {
} Using mod my_state {
pub struct Automaton<State: AutomatonState> {
pub state: State,
}
pub struct State1<T>(T);
pub trait State1State {
fn new<T>() -> State1<T>;
fn end(self);
}
#[doc(hidden)]
mod __private {
pub trait AutomatonState {}
}
pub trait AutomatonState: __private::AutomatonState {}
impl<__T: ?::core::marker::Sized> AutomatonState for __T where __T: __private::AutomatonState {}
impl<T> __private::AutomatonState for State1<T> {}
}
fn main() {} The problem lies in the expanded output for the fn new<T>() -> State1<T>; Which should instead be: fn new<T>() -> Automaton<State1<T>>; |
On another note, traits (currently) are not implemented inside the module, as the module only serves as a declaration of the typestate. |
Using generics in any of the states causes the automaton's type to be stripped away. Take the following example:
cargo expand
output:We see that
Automaton::<State1<()>>::new()
yields us a typeState1<()>
instead of the correct typeAutomaton<State1<()>>
. If we remove the generic parameters toState1
, all is well again.The text was updated successfully, but these errors were encountered: