| 482 | use std::fmt; |
| 483 | |
| 484 | fn get_names<E: Error>( |
| 485 | functions: &PrimaryMap<FuncId, FunctionDeclaration>, |
| 486 | data_objects: &PrimaryMap<DataId, DataDeclaration>, |
| 487 | ) -> Result<HashMap<String, FuncOrDataId>, E> { |
| 488 | let mut names = HashMap::new(); |
| 489 | for (func_id, decl) in functions.iter() { |
| 490 | if let Some(name) = &decl.name { |
| 491 | let old = names.insert(name.clone(), FuncOrDataId::Func(func_id)); |
| 492 | if old.is_some() { |
| 493 | return Err(E::invalid_value( |
| 494 | Unexpected::Other("duplicate name"), |
| 495 | &"FunctionDeclaration's with no duplicate names", |
| 496 | )); |
| 497 | } |
| 498 | } |
| 499 | } |
| 500 | for (data_id, decl) in data_objects.iter() { |
| 501 | if let Some(name) = &decl.name { |
| 502 | let old = names.insert(name.clone(), FuncOrDataId::Data(data_id)); |
| 503 | if old.is_some() { |
| 504 | return Err(E::invalid_value( |
| 505 | Unexpected::Other("duplicate name"), |
| 506 | &"DataDeclaration's with no duplicate names", |
| 507 | )); |
| 508 | } |
| 509 | } |
| 510 | } |
| 511 | Ok(names) |
| 512 | } |
| 513 | |
| 514 | impl Serialize for ModuleDeclarations { |
| 515 | fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> { |