]> git.proxmox.com Git - rustc.git/blame - src/test/ui/issues/issue-51301.rs
New upstream version 1.49.0+dfsg1
[rustc.git] / src / test / ui / issues / issue-51301.rs
CommitLineData
dc9dc135
XL
1use std::any::TypeId;
2use std::collections::HashMap;
3use std::hash::Hash;
4
5trait State {
6 type EventType;
7 fn get_type_id_of_state(&self) -> TypeId;
8}
9
10struct StateMachine<EventType: Hash + Eq> {
11 current_state: Box<dyn State<EventType = EventType>>,
12 transition_table:
13 HashMap<TypeId, HashMap<EventType, fn() -> Box<dyn State<EventType = EventType>>>>,
14}
15
16impl<EventType: Hash + Eq> StateMachine<EventType> {
17 fn inner_process_event(&mut self, event: EventType) -> Result<(), i8> {
18 let new_state_creation_function = self
19 .transition_table
20 .iter()
21 .find(|(&event_typeid, _)| event_typeid == self.current_state.get_type_id_of_state())
22 .ok_or(1)?
23 .1
24 .iter()
25 .find(|(&event_type, _)| event == event_type)
26 //~^ ERROR cannot move out of a shared reference
27 .ok_or(2)?
28 .1;
29
30 self.current_state = new_state_creation_function();
31 Ok(())
32 }
33}
34
35fn main() {}