more clippy lints

This commit is contained in:
Skgland
2021-02-06 19:58:31 +01:00
parent 1eb9fcf521
commit 3f7a60d84b
2 changed files with 10 additions and 10 deletions

View File

@@ -561,7 +561,7 @@ impl PartialEq for Constant {
impl Eq for Constant {} impl Eq for Constant {}
impl Constant { impl Constant {
pub fn to_atom(self) -> Option<ClauseName> { pub fn to_atom(&self) -> Option<ClauseName> {
match self { match self {
Constant::Atom(a, _) => Some(a.defrock_brackets()), Constant::Atom(a, _) => Some(a.defrock_brackets()),
_ => None, _ => None,
@@ -678,7 +678,7 @@ impl ClauseName {
!self.as_str().is_empty() && self.as_str().chars().nth(1).is_none() !self.as_str().is_empty() && self.as_str().chars().nth(1).is_none()
} }
pub fn defrock_brackets(self) -> Self { pub fn defrock_brackets(&self) -> Self {
fn defrock_brackets(s: &str) -> &str { fn defrock_brackets(s: &str) -> &str {
if s.starts_with('(') && s.ends_with(')') { if s.starts_with('(') && s.ends_with(')') {
&s[1..s.len() - 1] &s[1..s.len() - 1]
@@ -726,7 +726,7 @@ impl Term {
} }
} }
pub fn to_constant(self) -> Option<Constant> { pub fn into_constant(self) -> Option<Constant> {
match self { match self {
Term::Constant(_, c) => Some(c), Term::Constant(_, c) => Some(c),
_ => None, _ => None,

View File

@@ -95,7 +95,7 @@ fn setup_predicate_indicator(term: &mut Term) -> Result<PredicateKey, Compilatio
let name = *terms.pop().unwrap(); let name = *terms.pop().unwrap();
let arity = arity let arity = arity
.to_constant() .into_constant()
.and_then(|c| match c { .and_then(|c| match c {
Constant::Integer(n) => n.to_usize(), Constant::Integer(n) => n.to_usize(),
Constant::Fixnum(n) => usize::try_from(n).ok(), Constant::Fixnum(n) => usize::try_from(n).ok(),
@@ -104,7 +104,7 @@ fn setup_predicate_indicator(term: &mut Term) -> Result<PredicateKey, Compilatio
.ok_or(CompilationError::InvalidModuleExport)?; .ok_or(CompilationError::InvalidModuleExport)?;
let name = name let name = name
.to_constant() .into_constant()
.and_then(|c| c.to_atom()) .and_then(|c| c.to_atom())
.ok_or(CompilationError::InvalidModuleExport)?; .ok_or(CompilationError::InvalidModuleExport)?;
@@ -174,7 +174,7 @@ pub(super) fn setup_module_export_list(
export_list = *t2; export_list = *t2;
} }
if export_list.to_constant() != Some(Constant::EmptyList) { if export_list.into_constant() != Some(Constant::EmptyList) {
Err(CompilationError::InvalidModuleDecl) Err(CompilationError::InvalidModuleDecl)
} else { } else {
Ok(exports) Ok(exports)
@@ -189,7 +189,7 @@ fn setup_module_decl(
let name = terms let name = terms
.pop() .pop()
.unwrap() .unwrap()
.to_constant() .into_constant()
.and_then(|c| c.to_atom()) .and_then(|c| c.to_atom())
.ok_or(CompilationError::InvalidModuleDecl)?; .ok_or(CompilationError::InvalidModuleDecl)?;
@@ -205,7 +205,7 @@ fn setup_use_module_decl(mut terms: Vec<Box<Term>>) -> Result<ModuleSource, Comp
terms terms
.pop() .pop()
.unwrap() .unwrap()
.to_constant() .into_constant()
.and_then(|c| c.to_atom()) .and_then(|c| c.to_atom())
.map(|c| ModuleSource::Library(c)) .map(|c| ModuleSource::Library(c))
.ok_or(CompilationError::InvalidUseModuleDecl) .ok_or(CompilationError::InvalidUseModuleDecl)
@@ -257,7 +257,7 @@ fn setup_qualified_import(
terms terms
.pop() .pop()
.unwrap() .unwrap()
.to_constant() .into_constant()
.and_then(|c| c.to_atom()) .and_then(|c| c.to_atom())
.map(|c| ModuleSource::Library(c)) .map(|c| ModuleSource::Library(c))
.ok_or(CompilationError::InvalidUseModuleDecl) .ok_or(CompilationError::InvalidUseModuleDecl)
@@ -273,7 +273,7 @@ fn setup_qualified_import(
export_list = *t2; export_list = *t2;
} }
if export_list.to_constant() != Some(Constant::EmptyList) { if export_list.into_constant() != Some(Constant::EmptyList) {
Err(CompilationError::InvalidModuleDecl) Err(CompilationError::InvalidModuleDecl)
} else { } else {
Ok((module_src, exports)) Ok((module_src, exports))