Nonsensical rustc error: expected and found are same
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
use statig::{
Outcome::Super,
awaitable::{IntoStateMachine, Outcome, State, Superstate},
};
enum BaseEvent {
Pause,
Resume,
Confirm,
Recover,
Cancel,
}
pub enum AllEvents<FE> {
Base(BaseEvent),
FlowEvent(FE),
}
pub enum DoneStates {
Finished,
Cancelled,
Panicked,
}
pub enum NotRunningStates {
Idle,
Paused,
Blocked,
Errored,
}
pub enum AllStates<FS> {
Done(DoneStates),
NotRunning(NotRunningStates),
FlowState(FS),
}
pub enum AllSuperstates<FSS> {
Common,
Done,
NotRunning,
Running,
FlowSuperstate(FSS),
}
pub trait BaseHandlers<S>
where
for<'sub, 'evt> S: IntoStateMachine<
State = AllStates<S>,
Superstate<'sub> = AllSuperstates<S>,
Event<'evt> = AllEvents<S>,
> + 'sub,
for<'b> S::Superstate<'b>: Superstate<S>,
{
fn finished(event: &S::Event<'_>) -> Outcome<AllStates<S>> {
Outcome::Handled
}
fn cancelled(event: &S::Event<'_>) -> Outcome<AllStates<S>> {
Outcome::Handled
}
fn panicked(event: &S::Event<'_>) -> Outcome<AllStates<S>> {
Outcome::Handled
}
}
impl<S> State<S> for AllStates<S>
where
// for some lifetime, S must be a state machine with AllStates as its State type, AllSuperstates as its Superstate type, implement BaseHandlers, and have the same lifetime
for<'sub, 'evt> S: IntoStateMachine<
State = AllStates<S>,
Superstate<'sub> = AllSuperstates<S>,
Event<'evt> = AllEvents<S>,
> + BaseHandlers<S>
+ 'sub,
for<'b> S::Superstate<'b>: Superstate<S>,
{
fn call_handler(
&mut self,
shared_storage: &mut S,
event: &S::Event<'_>,
context: &mut S::Context<'_>,
) -> impl Future<Output = statig::Outcome<Self>> {
async move {
match self {
AllStates::Done(done_state) => match done_state {
DoneStates::Finished => S::finished(event),
DoneStates::Cancelled => S::cancelled(event),
DoneStates::Panicked => S::panicked(event),
},
_ => panic!(),
}
}
}
fn superstate(&mut self) -> Option<<S as IntoStateMachine>::Superstate<'_>> {
match self {
AllStates::Done(_) => Some(AllSuperstates::Done),
AllStates::NotRunning(_) => Some(AllSuperstates::NotRunning),
AllStates::FlowState(_) => S::State::superstate(self),
}
}
}
impl<S> Superstate<S> for AllSuperstates<S>
where
for<'sub, 'evt> S: IntoStateMachine<
State = AllStates<S>,
Superstate<'sub> = AllSuperstates<S>,
Event<'evt> = AllEvents<S>,
> + BaseHandlers<S>
+ 'sub,
for<'b> S::Superstate<'b>: Superstate<S>,
{
fn call_handler(
&mut self,
shared_storage: &mut S,
event: &S::Event<'_>,
context: &mut S::Context<'_>,
) -> impl Future<Output = Outcome<<S as IntoStateMachine>::State>> {
async move {
match self {
AllSuperstates::Common => {
// Handle common superstate events
Outcome::Handled
}
_ => panic!(),
}
}
}
}
Current output
method `call_handler` has an incompatible type for trait
expected signature `fn(&mut core::flows::AllSuperstates<_>, &mut _, &core::flows::AllEvents<_>, &mut _) -> impl futures::Future<Output = Outcome<<S as statig::awaitable::IntoStateMachine>::State>>`
found signature `fn(&mut core::flows::AllSuperstates<_>, &mut _, &core::flows::AllEvents<_>, &mut _) -> impl futures::Future<Output = Outcome<<S as statig::awaitable::IntoStateMachine>::State>>`
Desired output
No error
Rationale and extra context
Trying to do some work extending Statig, pretty intense type and lifetime bounds. It looks like the compiler became confused at some point sorting through the type bounds, and shows an error that the expected and found signature do not match, except that they do.
Other cases
Rust Version
rustc 1.87.0 (17067e9ac 2025-05-09)
binary: rustc
commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359
commit-date: 2025-05-09
host: x86_64-unknown-linux-gnu
release: 1.87.0
LLVM version: 20.1.1
Anything else?
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No repository file or test is named. Start by compiling the provided reproducer with rustc 1.87.0, then inspect the trait bounds and lifetime relationships around AllStates::call_handler and AllSuperstates::call_handler. Reduce the example while preserving the identical expected and found signatures; done means the reported case produces the desired result or a meaningful diagnostic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100