diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 70f8d1a2..47f5050d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,9 @@ name: CI on: push: - branches: [master] + branches: + - master + - rebis-dev tags: - "v**" pull_request: @@ -47,7 +49,6 @@ jobs: - { os: ubuntu-22.04, rust-version: nightly, target: 'wasm32-unknown-unknown', publish: true, args: '--no-default-features' , test-args: '--no-run --no-default-features', use_swap: true } # Cargo.toml rust-version - { os: ubuntu-22.04, rust-version: "1.85", target: 'x86_64-unknown-linux-gnu'} - # rust versions - { os: ubuntu-22.04, rust-version: beta, target: 'x86_64-unknown-linux-gnu'} - { os: ubuntu-22.04, rust-version: nightly, target: 'x86_64-unknown-linux-gnu', miri: true, components: "miri"} defaults: diff --git a/build/instructions_template.rs b/build/instructions_template.rs index dc2ed9f7..31c329b9 100644 --- a/build/instructions_template.rs +++ b/build/instructions_template.rs @@ -1055,7 +1055,7 @@ fn generate_instruction_preface() -> TokenStream { constants.iter().map(|(c, ptr)| { functor!( atom!(":"), - [cell((c.clone())), indexing_code_ptr((*ptr))] + [cell((*c)), indexing_code_ptr((*ptr))] ) }), ) @@ -3262,14 +3262,14 @@ where let disc = match DiscriminantT::from_str(id.to_string().as_str()) { Ok(disc) => disc, Err(_) => { - panic!("can't generate discriminant {}", id); + panic!("can't generate discriminant {id}"); } }; match disc.get_str(key) { Some(prop) => prop, None => { - panic!("can't find property {} of discriminant {:?}", key, disc); + panic!("can't find property {key} of discriminant {disc:?}"); } } } @@ -3387,7 +3387,7 @@ impl InstructionData { (name, arity, CountableInference::HasDefault) } else { - panic!("type ID is: {}", id); + panic!("type ID is: {id}"); }; let v_ident = variant diff --git a/build/static_string_indexing.rs b/build/static_string_indexing.rs index bffb5c13..a577a517 100644 --- a/build/static_string_indexing.rs +++ b/build/static_string_indexing.rs @@ -126,14 +126,14 @@ pub fn index_static_strings(instruction_rs_path: &std::path::Path) -> TokenStrea match file.read_to_string(&mut src) { Ok(_) => {} Err(e) => { - panic!("error reading file: {:?}", e); + panic!("error reading file: {e:?}"); } } let syntax = match syn::parse_file(&src) { Ok(s) => s, Err(e) => { - panic!("parse error: {} in file {:?}", e, path); + panic!("parse error: {e} in file {path:?}"); } }; Ok(syntax) diff --git a/src/atom_table.rs b/src/atom_table.rs index 12910753..d7796d73 100644 --- a/src/atom_table.rs +++ b/src/atom_table.rs @@ -254,7 +254,7 @@ impl std::ops::Deref for AtomString<'_> { fn deref(&self) -> &Self::Target { match self { Self::Static(reference) => reference, - Self::Inlined(inlined) => inlined_to_str(&inlined), + Self::Inlined(inlined) => inlined_to_str(inlined), Self::Dynamic(guard) => guard.deref(), } } diff --git a/src/debray_allocator.rs b/src/debray_allocator.rs index 3bc96dfc..53c7f206 100644 --- a/src/debray_allocator.rs +++ b/src/debray_allocator.rs @@ -251,7 +251,7 @@ impl DebrayAllocator { } } - if self.branch_stack.len() > 0 { + if !self.branch_stack.is_empty() { for var_num in subsumed_hits { self.branch_stack.add_branch_occurrence(var_num); } diff --git a/src/ffi.rs b/src/ffi.rs index a3015b6d..55bb525b 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -324,7 +324,7 @@ impl ForeignFunctionTable { let mut pointer_args = Self::build_pointer_args(&mut args, &function_impl.args, &mut self.structs)?; - return unsafe { + unsafe { macro_rules! call_and_return { ($type:ty) => {{ let mut n: Box = Box::new(0); @@ -410,7 +410,7 @@ impl ForeignFunctionTable { } _ => unreachable!(), } - }; + } } fn read_struct( diff --git a/src/forms.rs b/src/forms.rs index 1418b570..26f37b3e 100644 --- a/src/forms.rs +++ b/src/forms.rs @@ -372,11 +372,11 @@ pub enum ModuleSource { impl ModuleSource { pub(crate) fn as_functor_stub(&self) -> MachineStub { - match self { - &ModuleSource::Library(name) => { + match *self { + ModuleSource::Library(name) => { functor!(atom!("library"), [atom_as_cell(name)]) } - &ModuleSource::File(name) => { + ModuleSource::File(name) => { functor!(name) } } @@ -627,9 +627,9 @@ impl Default for Number { impl fmt::Display for Number { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - Number::Float(fl) => write!(f, "{}", fl), - Number::Integer(n) => write!(f, "{}", n), - Number::Rational(r) => write!(f, "{}", r), + Number::Float(fl) => write!(f, "{fl}"), + Number::Integer(n) => write!(f, "{n}"), + Number::Rational(r) => write!(f, "{r}"), Number::Fixnum(n) => write!(f, "{}", n.get_num()), } } diff --git a/src/functor_macro.rs b/src/functor_macro.rs index ba19f682..591fa185 100644 --- a/src/functor_macro.rs +++ b/src/functor_macro.rs @@ -698,9 +698,9 @@ mod tests { let functor = variadic_functor( atom!("switch_on_constants"), 1, - constants.iter().map(|(c, ptr)| { - functor!(atom!(":"), [cell((c.clone())), indexing_code_ptr((*ptr))]) - }), + constants + .iter() + .map(|(c, ptr)| functor!(atom!(":"), [cell((*c)), indexing_code_ptr((*ptr))])), ); heap.truncate(0); @@ -739,12 +739,12 @@ mod tests { ] ); - println!("{:?}", stub); + println!("{stub:?}"); // now the error form let lineless_error_form = functor!(atom!("error"), [functor(stub), functor(culprit)]); - println!("{:?}", lineless_error_form); + println!("{lineless_error_form:?}"); let mut heap = Heap::new(); let mut functor_writer = Heap::functor_writer(lineless_error_form); diff --git a/src/heap_print.rs b/src/heap_print.rs index 9cc3a2d0..57fef895 100644 --- a/src/heap_print.rs +++ b/src/heap_print.rs @@ -831,13 +831,13 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> { read_heap_cell!(cell, (HeapCellValueTag::Lis | HeapCellValueTag::Str, h) => { - Some(format!("{}", h)) + Some(format!("{h}")) } (HeapCellValueTag::Var | HeapCellValueTag::AttrVar, h) => { - Some(format!("_{}", h)) + Some(format!("_{h}")) } (HeapCellValueTag::StackVar, h) => { - Some(format!("_s_{}", h)) + Some(format!("_s_{h}")) } _ => { None @@ -1002,7 +1002,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> { #[inline] fn print_ip_addr(&mut self, ip: IpAddr) { push_char!(self, '\''); - append_str!(self, &format!("{}", ip)); + append_str!(self, &format!("{ip}")); push_char!(self, '\''); } @@ -1039,7 +1039,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> { self.print_rational(max_depth, r, *op); } n => { - let output_str = format!("{}", n); + let output_str = format!("{n}"); push_space_if_amb!(self, &output_str, { append_str!(self, &output_str); @@ -1086,7 +1086,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> { match self.op_dir.get(&(atom!("rdiv"), Fixity::In)) { Some(op_desc) => { if r.is_int() { - let output_str = format!("{}", r); + let output_str = format!("{r}"); push_space_if_amb!(self, &output_str, { append_str!(self, &output_str); diff --git a/src/iterators.rs b/src/iterators.rs index 5bd51d99..8e2e43dd 100644 --- a/src/iterators.rs +++ b/src/iterators.rs @@ -403,7 +403,7 @@ impl<'a> Iterator for ClauseIterator<'a> { self.state_stack .push(ClauseIteratorState::RemainingBranches(branches, 0)); } - &ChunkedTerms::Chunk { ref terms } => { + ChunkedTerms::Chunk { ref terms } => { return Some(ClauseItem::Chunk { terms }); } } diff --git a/src/machine/compile.rs b/src/machine/compile.rs index 7dcbee14..8e799009 100644 --- a/src/machine/compile.rs +++ b/src/machine/compile.rs @@ -133,7 +133,7 @@ fn merge_indices( ); retraction_info.push_record(RetractionRecord::AddedIndex( - skeleton[clause_index].opt_arg_index_key.clone(), + skeleton[clause_index].opt_arg_index_key, clause_loc, )); } else { @@ -246,7 +246,7 @@ fn remove_index_from_subsequence( // appear anywhere inside an Internal record. retraction_info.push_record(RetractionRecord::RemovedIndex( index_loc, - opt_arg_index_key.clone(), + *opt_arg_index_key, offset, )); } @@ -808,7 +808,7 @@ fn prepend_compiled_clause( skeleton.clauses[0].clause_start = clause_loc + 2; retraction_info.push_record(RetractionRecord::AddedIndex( - skeleton.clauses[0].opt_arg_index_key.clone(), + skeleton.clauses[0].opt_arg_index_key, skeleton.clauses[0].clause_start, )); @@ -1070,7 +1070,7 @@ fn append_compiled_clause( skeleton.clauses[target_pos].opt_arg_index_key += index_loc - 1; retraction_info.push_record(RetractionRecord::AddedIndex( - skeleton.clauses[target_pos].opt_arg_index_key.clone(), + skeleton.clauses[target_pos].opt_arg_index_key, skeleton.clauses[target_pos].clause_start, )); diff --git a/src/machine/cycle_detection.rs b/src/machine/cycle_detection.rs index da125518..a800a9b6 100644 --- a/src/machine/cycle_detection.rs +++ b/src/machine/cycle_detection.rs @@ -137,10 +137,7 @@ impl<'a, const STOP_AT_CYCLES: bool> CycleDetectingIter<'a, STOP_AT_CYCLES> { let cell = self.heap[h]; let arity = cell_as_atom_cell!(self.heap[h]).get_arity(); - let last_cell_loc = match self.traverse_subterm(h + 1, arity) { - Some(last_cell_loc) => last_cell_loc, - None => return None, - }; + let last_cell_loc = self.traverse_subterm(h + 1, arity)?; if last_cell_loc == h { if self.backward() { @@ -171,10 +168,7 @@ impl<'a, const STOP_AT_CYCLES: bool> CycleDetectingIter<'a, STOP_AT_CYCLES> { let mut cell = self.heap[self.current]; cell.set_value(self.next); - let last_cell_loc = match self.traverse_subterm(self.next as usize, 2) { - Some(last_cell_loc) => last_cell_loc, - None => return None, - }; + let last_cell_loc = self.traverse_subterm(self.next as usize, 2)?; if self.cycle_detection_active() { for idx in (self.next as usize..last_cell_loc).rev() { diff --git a/src/machine/dispatch.rs b/src/machine/dispatch.rs index 2428f7d2..af34bcd7 100644 --- a/src/machine/dispatch.rs +++ b/src/machine/dispatch.rs @@ -3277,7 +3277,7 @@ impl Machine { &Instruction::PutPartialString(_, ref string, reg) => { self.machine_st[reg] = backtrack_on_resource_error!( self.machine_st, - self.machine_st.heap.allocate_pstr(&string) + self.machine_st.heap.allocate_pstr(string) ); self.machine_st.p += 1; diff --git a/src/machine/heap.rs b/src/machine/heap.rs index fdf24047..e69050ab 100644 --- a/src/machine/heap.rs +++ b/src/machine/heap.rs @@ -612,7 +612,6 @@ impl Heap { } } - #[must_use] pub fn reserve(&mut self, num_cells: usize) -> Result { let section; let len = heap_index!(num_cells); @@ -745,10 +744,8 @@ impl Heap { // the heap to a pre-allocated resource error pub(crate) fn push_cell(&mut self, cell: HeapCellValue) -> Result<(), usize> { unsafe { - if self.inner.byte_len == self.inner.byte_cap { - if !self.grow() { - return Err(self.resource_error_offset()); - } + if self.inner.byte_len == self.inner.byte_cap && !self.grow() { + return Err(self.resource_error_offset()); } // SAFETY: @@ -1009,7 +1006,7 @@ impl<'a> PStrSegmentIter<'a> { let string_buf = unsafe { let char_ptr = heap.inner.ptr.add(pstr_loc); let slice = std::slice::from_raw_parts(char_ptr, heap.inner.byte_len - pstr_loc); - std::str::from_utf8_unchecked(&slice) + std::str::from_utf8_unchecked(slice) }; PStrSegmentIter { string_buf } diff --git a/src/machine/load_state.rs b/src/machine/load_state.rs index 40e9a383..89c50153 100644 --- a/src/machine/load_state.rs +++ b/src/machine/load_state.rs @@ -546,27 +546,21 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> { for export in removed_module.module_decl.exports.iter() { match export { ModuleExport::PredicateKey(ref key) => { - match ( + if let (Some(module_code_idx), Some(target_code_idx)) = ( removed_module.code_dir.get(key).cloned(), code_dir.get_mut(key).cloned(), ) { - (Some(module_code_idx), Some(target_code_idx)) => { - let code_index_tbl = - &mut LS::machine_st(payload).arena.code_index_tbl; - let module_code_ptr = - code_index_tbl.get_entry(module_code_idx.into()); - let target_code_ptr = - code_index_tbl.get_entry(target_code_idx.into()); + let code_index_tbl = &mut LS::machine_st(payload).arena.code_index_tbl; + let module_code_ptr = code_index_tbl.get_entry(module_code_idx.into()); + let target_code_ptr = code_index_tbl.get_entry(target_code_idx.into()); - if module_code_ptr == target_code_ptr { - let old_index_ptr = target_code_idx - .replace(code_index_tbl, IndexPtr::undefined()); - payload - .retraction_info - .push_record(predicate_retractor(*key, old_index_ptr)); - } + if module_code_ptr == target_code_ptr { + let old_index_ptr = + target_code_idx.replace(code_index_tbl, IndexPtr::undefined()); + payload + .retraction_info + .push_record(predicate_retractor(*key, old_index_ptr)); } - _ => {} } } ModuleExport::OpDecl(op_decl) => { @@ -688,12 +682,12 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> { let code_index_tbl = &mut LS::machine_st(&mut self.payload).arena.code_index_tbl; if module_name == atom!("user") { - return *self + *self .wam_prelude .indices .code_dir .entry(key) - .or_insert_with(|| CodeIndex::new(IndexPtr::undefined(), code_index_tbl)); + .or_insert_with(|| CodeIndex::new(IndexPtr::undefined(), code_index_tbl)) } else { self.get_or_insert_local_code_index(module_name, key) } diff --git a/src/machine/loader.rs b/src/machine/loader.rs index 685a69a0..08282f68 100644 --- a/src/machine/loader.rs +++ b/src/machine/loader.rs @@ -1407,10 +1407,10 @@ impl MachineState { term_stack.push(Term::Literal(Cell::default(), Literal::try_from(addr).unwrap())); } (HeapCellValueTag::StackVar, h) => { - term_stack.push(Term::Var(Cell::default(), VarPtr::from(format!("s_{}", h)))); + term_stack.push(Term::Var(Cell::default(), VarPtr::from(format!("s_{h}")))); } (HeapCellValueTag::Var | HeapCellValueTag::AttrVar, h) => { - term_stack.push(Term::Var(Cell::default(), VarPtr::from(format!("_{}", h)))); + term_stack.push(Term::Var(Cell::default(), VarPtr::from(format!("_{h}")))); } (HeapCellValueTag::Atom, (name, arity)) => { let h = iter.focus().value() as usize; diff --git a/src/machine/machine_indices.rs b/src/machine/machine_indices.rs index 4f04c2b1..7f7bfe35 100644 --- a/src/machine/machine_indices.rs +++ b/src/machine/machine_indices.rs @@ -159,17 +159,17 @@ impl From for CodeIndex { } } -impl Into for CodeIndex { +impl From for CodeIndexOffset { #[inline(always)] - fn into(self) -> CodeIndexOffset { - self.0 + fn from(value: CodeIndex) -> CodeIndexOffset { + value.0 } } -impl Into for &'_ CodeIndex { +impl From<&'_ CodeIndex> for CodeIndexOffset { #[inline(always)] - fn into(self) -> CodeIndexOffset { - self.0 + fn from(value: &'_ CodeIndex) -> CodeIndexOffset { + value.0 } } @@ -206,7 +206,7 @@ impl VarKey { #[inline] pub(crate) fn to_string(&self) -> String { match self { - VarKey::AnonVar(h) => format!("_{}", h), + VarKey::AnonVar(h) => format!("_{h}"), VarKey::VarPtr(var) => var.borrow().to_string(), } } @@ -526,7 +526,7 @@ impl IndexStore { &'a self, range: R, ) -> impl Iterator + 'a { - self.streams.range(range).into_iter().copied() + self.streams.range(range).copied() } /// Forcibly sets `alias` to `stream`. diff --git a/src/machine/machine_state.rs b/src/machine/machine_state.rs index fac5d7b6..7663c952 100644 --- a/src/machine/machine_state.rs +++ b/src/machine/machine_state.rs @@ -659,8 +659,8 @@ impl MachineState { &self.atom_tbl, ) ); - - Ok(unify_fn!(*self, var_names_offset, var_names_addr)) + unify_fn!(*self, var_names_offset, var_names_addr); + Ok(()) } pub fn read_term_body(&mut self, mut term_write_result: TermWriteResult) -> CallResult { diff --git a/src/machine/machine_state_impl.rs b/src/machine/machine_state_impl.rs index f663656c..3f14253d 100644 --- a/src/machine/machine_state_impl.rs +++ b/src/machine/machine_state_impl.rs @@ -847,13 +847,11 @@ impl MachineState { if let Some(c) = char_iter.next() { if n == 1 { self.unify_char(c, a3); + } else if char_iter.next().is_some() { + unify_fn!(*self, pstr_loc_as_cell!(pstr_loc + c.len_utf8()), a3); } else { - if char_iter.next().is_some() { - unify_fn!(*self, pstr_loc_as_cell!(pstr_loc + c.len_utf8()), a3); - } else { - let tail_idx = Heap::pstr_tail_idx(pstr_loc + c.len_utf8()); - unify_fn!(*self, self.heap[tail_idx], a3); - } + let tail_idx = Heap::pstr_tail_idx(pstr_loc + c.len_utf8()); + unify_fn!(*self, self.heap[tail_idx], a3); } } else { unreachable!() diff --git a/src/machine/mock_wam.rs b/src/machine/mock_wam.rs index b7201b71..0fcebd41 100644 --- a/src/machine/mock_wam.rs +++ b/src/machine/mock_wam.rs @@ -56,7 +56,7 @@ impl MockWAM { let mut printer = HCPrinter::new( &mut self.machine_st.heap, &mut self.machine_st.stack, - &mut self.machine_st.arena, + &self.machine_st.arena, &self.op_dir, PrinterOutputter::new(), term_write_result.heap_loc, @@ -195,15 +195,11 @@ pub fn all_cells_marked_and_unforwarded(heap: &Heap, offset: usize) { assert!( cell.get_mark_bit(), - "cell {:?} at index {} is not marked", - cell, - curr_idx + "cell {cell:?} at index {curr_idx} is not marked" ); assert!( !cell.get_forwarding_bit(), - "cell {:?} at index {} is forwarded", - cell, - curr_idx + "cell {cell:?} at index {curr_idx} is forwarded" ); } } @@ -227,9 +223,7 @@ pub fn all_cells_unmarked(iter: &impl SizedHeap) { assert!( !cell.get_mark_bit(), - "cell {:?} at index {} is still marked", - cell, - curr_idx + "cell {cell:?} at index {curr_idx} is still marked" ); } } @@ -255,6 +249,7 @@ pub(crate) fn parse_and_write_parsed_term_to_heap( impl Machine { /// For use in tests. + #[allow(clippy::unbuffered_bytes)] pub fn test_load_file(&mut self, file: &str) -> Vec { let stream = Stream::from_owned_string( std::fs::read_to_string(AsRef::::as_ref(file)).unwrap(), @@ -266,6 +261,7 @@ impl Machine { } /// For use in tests. + #[allow(clippy::unbuffered_bytes)] pub fn test_load_string(&mut self, code: &str) -> Vec { let stream = Stream::from_owned_string(code.to_owned(), &mut self.machine_st.arena); diff --git a/src/machine/streams.rs b/src/machine/streams.rs index 1f9fae09..25e9a75a 100644 --- a/src/machine/streams.rs +++ b/src/machine/streams.rs @@ -1653,7 +1653,8 @@ impl MachineState { }; stream.set_past_end_of_stream(true); - Ok(unify!(self, result, end_of_stream)) + unify!(self, result, end_of_stream); + Ok(()) } EOFAction::Reset => { if !stream.reset() { diff --git a/src/machine/system_calls.rs b/src/machine/system_calls.rs index 6c861ae6..8c0eee0a 100644 --- a/src/machine/system_calls.rs +++ b/src/machine/system_calls.rs @@ -194,7 +194,7 @@ fn pstr_segment_char_count_up_to( let mut byte_offset = 0; if max_chars > 0 { - while let Some(c) = char_iter.next() { + for c in &mut char_iter { if c == '\u{0}' { break; } @@ -784,7 +784,7 @@ impl MachineState { let steps = if max_steps > -1 { std::cmp::min(max_steps, num_steps as i64) } else { - max_steps as i64 + max_steps }; self.finalize_skip_max_list(steps, pstr_loc); // cell); @@ -989,6 +989,7 @@ impl MachineState { } } + #[allow(clippy::never_loop)] // TODO why is there a loop here that never loops? loop { match lexer.lookahead_char() { Err(e) if e.is_unexpected_eof() => { @@ -2327,7 +2328,7 @@ impl Machine { let cell = step_or_resource_error!( self.machine_st, - self.machine_st.heap.allocate_cstr(&*name.as_str()) + self.machine_st.heap.allocate_cstr(&name.as_str()) ); unify!(self.machine_st, self.machine_st.registers[2], cell); @@ -2386,7 +2387,7 @@ impl Machine { self.machine_st, sized_iter_to_heap_list( &mut self.machine_st.heap, - (&*name).chars().count(), + name.chars().count(), iter, ) ); @@ -2916,7 +2917,7 @@ impl Machine { let string = match Number::try_from((n, &self.machine_st.arena.f64_tbl)) { Ok(Number::Float(OrderedFloat(n))) => { - format!("{0:<20?}", n) + format!("{n:<20?}") } Ok(Number::Fixnum(n)) => n.get_num().to_string(), Ok(Number::Integer(n)) => n.to_string(), @@ -3245,7 +3246,7 @@ impl Machine { let n: u32 = (&*n).try_into().unwrap(); let n = char::try_from(n); if let Ok(c) = n { - write!(&mut stream, "{}", c).unwrap(); + write!(&mut stream, "{c}").unwrap(); return Ok(()); } } @@ -3253,7 +3254,7 @@ impl Machine { let n = n.get_num(); if let Some(c) = u32::try_from(n).ok().and_then(char::from_u32) { - write!(&mut stream, "{}", c).unwrap(); + write!(&mut stream, "{c}").unwrap(); return Ok(()); } } @@ -3295,13 +3296,13 @@ impl Machine { read_heap_cell!(addr, (HeapCellValueTag::Atom, (name, _arity)) => { if let Some(c) = name.as_char() { - write!(&mut stream, "{}", c).unwrap(); + write!(&mut stream, "{c}").unwrap(); return Ok(()); } } /* (HeapCellValueTag::Char, c) => { - write!(&mut stream, "{}", c).unwrap(); + write!(&mut stream, "{c}").unwrap(); return Ok(()); } */ @@ -3792,11 +3793,7 @@ impl Machine { #[inline(always)] pub(crate) fn first_stream(&mut self) { - let first_stream = self - .indices - .iter_streams(..) - .filter(|s| !s.is_null_stream()) - .next(); + let first_stream = self.indices.iter_streams(..).find(|s| !s.is_null_stream()); if let Some(first_stream) = first_stream { let stream = first_stream.into(); @@ -3816,8 +3813,7 @@ impl Machine { .indices .iter_streams(prev_stream..) .filter(|s| !s.is_null_stream()) - .skip(1) - .next(); + .nth(1); if let Some(next_stream) = next_stream { let var = self.deref_register(2).as_var().unwrap(); @@ -3935,14 +3931,14 @@ impl Machine { self.indices.remove_stream(stream); - stream.close().or_else(|_| { + stream.close().map_err(|_| { let stub = functor_stub(atom!("close"), 1); let addr = stream.into(); let err = self .machine_st .existence_error(ExistenceError::Stream(addr)); - Err(self.machine_st.error_form(err, stub)) + self.machine_st.error_form(err, stub) }) } @@ -4152,9 +4148,7 @@ impl Machine { let mut functor_writer = Heap::functor_writer(functor); - if let Err(e) = functor_writer(heap) { - return Err(e); - } + functor_writer(heap)?; num_functors += 1; } @@ -7637,7 +7631,7 @@ impl Machine { let buffer = git_version!(cargo_prefix = "cargo:", fallback = "unknown"); let cstr_cell = - step_or_resource_error!(self.machine_st, self.machine_st.heap.allocate_cstr(&buffer)); + step_or_resource_error!(self.machine_st, self.machine_st.heap.allocate_cstr(buffer)); unify!(self.machine_st, cstr_cell, self.machine_st.registers[1]); } @@ -8622,7 +8616,7 @@ impl Machine { ]; for spec in SPECIFIERS { - fstr.push_str(&format!("'{}'=\"%{}\", ", spec, spec).to_string()); + fstr.push_str(&format!("'{spec}'=\"%{spec}\", ")); } fstr.push_str("finis]."); @@ -8719,7 +8713,7 @@ impl Machine { Ok(result) } scraper::Node::Comment(comment) => { - let comment = self.machine_st.heap.allocate_cstr(&comment)?; + let comment = self.machine_st.heap.allocate_cstr(comment)?; let result = str_loc_as_cell!(self.machine_st.heap.cell_len()); let mut writer = self.machine_st.heap.reserve(2)?; diff --git a/src/machine/unify.rs b/src/machine/unify.rs index 6ada6fb1..fdc430ee 100644 --- a/src/machine/unify.rs +++ b/src/machine/unify.rs @@ -290,7 +290,7 @@ pub(crate) trait Unifier: DerefMut { let machine_st = self.deref_mut(); let f1 = machine_st.arena.f64_tbl.get_entry(f1); - let f2 = machine_st.arena.f64_tbl.get_entry(f2.into()); + let f2 = machine_st.arena.f64_tbl.get_entry(f2); self.fail = f1 != f2; } diff --git a/src/parser/ast.rs b/src/parser/ast.rs index aa9ea077..18389225 100644 --- a/src/parser/ast.rs +++ b/src/parser/ast.rs @@ -10,7 +10,6 @@ use std::cell::{Cell, Ref, RefCell, RefMut}; use std::fmt; use std::hash::Hash; use std::hash::Hasher; -use std::i64; use std::io::{Error as IOError, ErrorKind}; use std::ops::Not; use std::ops::RangeInclusive; @@ -268,8 +267,8 @@ impl RegType { impl fmt::Display for RegType { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - RegType::Perm(val) => write!(f, "Y{}", val), - RegType::Temp(val) => write!(f, "X{}", val), + RegType::Perm(val) => write!(f, "Y{val}"), + RegType::Temp(val) => write!(f, "X{val}"), } } } @@ -291,10 +290,10 @@ impl VarReg { impl fmt::Display for VarReg { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - VarReg::Norm(RegType::Perm(reg)) => write!(f, "Y{}", reg), - VarReg::Norm(RegType::Temp(reg)) => write!(f, "X{}", reg), - VarReg::ArgAndNorm(RegType::Perm(reg), arg) => write!(f, "Y{} A{}", reg, arg), - VarReg::ArgAndNorm(RegType::Temp(reg), arg) => write!(f, "X{} A{}", reg, arg), + VarReg::Norm(RegType::Perm(reg)) => write!(f, "Y{reg}"), + VarReg::Norm(RegType::Temp(reg)) => write!(f, "X{reg}"), + VarReg::ArgAndNorm(RegType::Perm(reg), arg) => write!(f, "Y{reg} A{arg}"), + VarReg::ArgAndNorm(RegType::Temp(reg), arg) => write!(f, "X{reg} A{arg}"), } } } @@ -830,7 +829,7 @@ impl Var { #[inline(always)] pub fn to_string(&self) -> String { match self { - Var::InSitu(n) | Var::Generated(n) => format!("_{}", n), + Var::InSitu(n) | Var::Generated(n) => format!("_{n}"), Var::Named(value) => value.as_ref().clone(), } } @@ -858,9 +857,9 @@ impl Term { } pub fn name(&self) -> Option { - match self { - &Term::Literal(_, Literal::Atom(atom)) => Some(atom), - &Term::Clause(_, atom, ..) => Some(atom), + match *self { + Term::Literal(_, Literal::Atom(atom)) => Some(atom), + Term::Clause(_, atom, ..) => Some(atom), _ => None, } } diff --git a/src/parser/lexer.rs b/src/parser/lexer.rs index 5fd5b7ba..0ca5ef69 100644 --- a/src/parser/lexer.rs +++ b/src/parser/lexer.rs @@ -63,6 +63,7 @@ enum Number { impl Number { #[inline] + #[allow(clippy::wrong_self_convention)] fn to_literal(self) -> Literal { match self { Number::BigInt(ibig) => Literal::Integer(ibig), @@ -80,6 +81,7 @@ enum NumberToken { impl NumberToken { #[inline] + #[allow(clippy::wrong_self_convention)] fn to_token(self) -> Option { match self { NumberToken::Number(number) => Some(Token::Literal(number.to_literal())), @@ -959,8 +961,8 @@ impl<'a, R: CharRead> Lexer<'a, R> { )))) } }, - Ok(NumberToken::Number(n)) => return Ok(Token::Literal(n.to_literal())), - Err(e) => return Err(e), + Ok(NumberToken::Number(n)) => Ok(Token::Literal(n.to_literal())), + Err(e) => Err(e), } } diff --git a/src/parser/parser.rs b/src/parser/parser.rs index 7a889520..a874face 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -111,7 +111,7 @@ pub(crate) fn as_partial_string( tail_ref = tail; } Term::CompleteString(_, cstr) => { - string += &*cstr.as_str(); + string += cstr.as_str(); tail = Term::Literal(Cell::default(), Literal::Atom(atom!("[]"))); break; }