From 0616a960d6470d3afc4c466ebe72e3e612df1e95 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Tue, 10 Jul 2018 15:55:53 +0200 Subject: [PATCH] [clippy] A few fixes in module/src/module.rs; - use Self more to indicate the current type; - explicitly clone one Option; - invert !is_none to is_some; --- lib/module/src/module.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/module/src/module.rs b/lib/module/src/module.rs index 76ac8926b9..216e3ed6e1 100644 --- a/lib/module/src/module.rs +++ b/lib/module/src/module.rs @@ -20,7 +20,7 @@ entity_impl!(FuncId, "funcid"); /// Function identifiers are namespace 0 in `ir::ExternalName` impl From for ir::ExternalName { - fn from(id: FuncId) -> ir::ExternalName { + fn from(id: FuncId) -> Self { ir::ExternalName::User { namespace: 0, index: id.0, @@ -35,7 +35,7 @@ entity_impl!(DataId, "dataid"); /// Data identifiers are namespace 1 in `ir::ExternalName` impl From for ir::ExternalName { - fn from(id: DataId) -> ir::ExternalName { + fn from(id: DataId) -> Self { ir::ExternalName::User { namespace: 1, index: id.0, @@ -74,16 +74,16 @@ impl Linkage { } /// Test whether this linkage can have a definition. - pub fn is_definable(&self) -> bool { - match *self { + pub fn is_definable(self) -> bool { + match self { Linkage::Import => false, Linkage::Local | Linkage::Preemptible | Linkage::Export => true, } } /// Test whether this linkage will have a definition that cannot be preempted. - pub fn is_final(&self) -> bool { - match *self { + pub fn is_final(self) -> bool { + match self { Linkage::Import | Linkage::Preemptible => false, Linkage::Local | Linkage::Export => true, } @@ -101,10 +101,10 @@ pub enum FuncOrDataId { /// Mapping to `ir::ExternalName` is trivial based on the `FuncId` and `DataId` mapping. impl From for ir::ExternalName { - fn from(id: FuncOrDataId) -> ir::ExternalName { + fn from(id: FuncOrDataId) -> Self { match id { - FuncOrDataId::Func(funcid) => ir::ExternalName::from(funcid), - FuncOrDataId::Data(dataid) => ir::ExternalName::from(dataid), + FuncOrDataId::Func(funcid) => Self::from(funcid), + FuncOrDataId::Data(dataid) => Self::from(dataid), } } } @@ -317,7 +317,7 @@ where /// Get the module identifier for a given name, if that name /// has been declared. pub fn get_name(&self, name: &str) -> Option { - self.names.get(name).map(|e| *e) + self.names.get(name).cloned() } /// Return then pointer type for the current target. @@ -472,7 +472,7 @@ where })?; let info = &self.contents.functions[func]; - if !info.compiled.is_none() { + if info.compiled.is_some() { return Err(ModuleError::DuplicateDefinition(info.decl.name.clone())); } if !info.decl.linkage.is_definable() { @@ -495,7 +495,7 @@ where pub fn define_data(&mut self, data: DataId, data_ctx: &DataContext) -> ModuleResult<()> { let compiled = { let info = &self.contents.data_objects[data]; - if !info.compiled.is_none() { + if info.compiled.is_some() { return Err(ModuleError::DuplicateDefinition(info.decl.name.clone())); } if !info.decl.linkage.is_definable() {