Skip to content

Commit bcc568f

Browse files
committed
Auto merge of #61792 - lzutao:issue-51301, r=Centril
Add ui test for issue 51301 Closes #51301
2 parents cdd7437 + 8a5e1ee commit bcc568f

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/test/ui/issues/issue-51301.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use std::any::TypeId;
2+
use std::collections::HashMap;
3+
use std::hash::Hash;
4+
5+
trait State {
6+
type EventType;
7+
fn get_type_id_of_state(&self) -> TypeId;
8+
}
9+
10+
struct 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+
16+
impl<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+
35+
fn main() {}

src/test/ui/issues/issue-51301.stderr

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0507]: cannot move out of a shared reference
2+
--> $DIR/issue-51301.rs:25:20
3+
|
4+
LL | .find(|(&event_type, _)| event == event_type)
5+
| ^^----------^^^^
6+
| |
7+
| data moved here
8+
| move occurs because `event_type` has type `EventType`, which does not implement the `Copy` trait
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0507`.

0 commit comments

Comments
 (0)