Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ Cargo.lock
/target
**/*.rs.bk
*.ll
tests/.tmp*
tests/create_me/
/tests/.tmp*
/tests/create_me/
/test_snapshots/

.helix/
.vscode/
4 changes: 2 additions & 2 deletions fmt/src/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl CommentWithMetadata {
// line has something
// check if the last comment after code was a postfix comment
if last_comment
.map_or(false, |last| last.loc.end() > code_end && !last.is_prefix())
.is_some_and(|last| last.loc.end() > code_end && !last.is_prefix())
{
// get the indent size of the next item of code
let next_indent_len = src[comment.loc().end()..]
Expand Down Expand Up @@ -434,7 +434,7 @@ impl std::iter::FusedIterator for CommentStateCharIndices<'_> {}
/// An Iterator over characters in a string slice which are not a apart of comments
pub struct NonCommentChars<'a>(CommentStateCharIndices<'a>);

impl<'a> Iterator for NonCommentChars<'a> {
impl Iterator for NonCommentChars<'_> {
type Item = char;

#[inline]
Expand Down
18 changes: 9 additions & 9 deletions fmt/src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl Context {
pub(crate) fn is_constructor_function(&self) -> bool {
self.function
.as_ref()
.map_or(false, |f| matches!(f.ty, FunctionTy::Constructor))
.is_some_and(|f| matches!(f.ty, FunctionTy::Constructor))
}
}

Expand Down Expand Up @@ -348,7 +348,7 @@ impl<'a, W: Write> Formatter<'a, W> {
};

self.find_next_line(start_from)
.map_or(false, |loc| loc >= end_at)
.is_some_and(|loc| loc >= end_at)
}
}
}
Expand Down Expand Up @@ -549,7 +549,7 @@ impl<'a, W: Write> Formatter<'a, W> {
fn write_doc_block_line(&mut self, comment: &CommentWithMetadata, line: &str) -> Result<()> {
if line.trim().starts_with('*') {
let line = line.trim().trim_start_matches('*');
let needs_space = line.chars().next().map_or(false, |ch| !ch.is_whitespace());
let needs_space = line.chars().next().is_some_and(|ch| !ch.is_whitespace());
write!(self.buf(), " *{}", if needs_space { " " } else { "" })?;
self.write_comment_line(comment, line)?;
self.write_whitespace_separator(true)?;
Expand Down Expand Up @@ -1797,7 +1797,7 @@ impl<'a, W: Write> Formatter<'a, W> {
}

// Traverse the Solidity Parse Tree and write to the code formatter
impl<'a, W: Write> Visitor for Formatter<'a, W> {
impl<W: Write> Visitor for Formatter<'_, W> {
type Error = FormatterError;

#[instrument(name = "source", skip(self))]
Expand Down Expand Up @@ -1862,7 +1862,7 @@ impl<'a, W: Write> Visitor for Formatter<'a, W> {
)?;

// EOF newline
if self.last_char().map_or(true, |char| char != '\n') {
if self.last_char() != Some('\n') {
writeln!(self.buf())?;
}

Expand Down Expand Up @@ -3268,7 +3268,7 @@ impl<'a, W: Write> Visitor for Formatter<'a, W> {

// we can however check if the contract `is` the `base`, this however also does
// not cover all cases
let is_contract_base = self.context.contract.as_ref().map_or(false, |contract| {
let is_contract_base = self.context.contract.as_ref().is_some_and(|contract| {
contract.base.iter().any(|contract_base| {
contract_base
.name
Expand All @@ -3292,7 +3292,7 @@ impl<'a, W: Write> Visitor for Formatter<'a, W> {
.content
.chars()
.next()
.map_or(false, |c| c.is_lowercase());
.is_some_and(|c| c.is_lowercase());
if is_lowercase && base_or_modifier.content.ends_with("()") {
base_or_modifier
.content
Expand Down Expand Up @@ -3904,14 +3904,14 @@ struct Transaction<'f, 'a, W> {
comments: Comments,
}

impl<'f, 'a, W> std::ops::Deref for Transaction<'f, 'a, W> {
impl<'a, W> std::ops::Deref for Transaction<'_, 'a, W> {
type Target = Formatter<'a, W>;
fn deref(&self) -> &Self::Target {
self.fmt
}
}

impl<'f, 'a, W> std::ops::DerefMut for Transaction<'f, 'a, W> {
impl<W> std::ops::DerefMut for Transaction<'_, '_, W> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.fmt
}
Expand Down
6 changes: 3 additions & 3 deletions fmt/src/solang_ext/loc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ pub trait CodeLocationExt {
fn loc(&self) -> pt::Loc;
}

impl<'a, T: ?Sized + CodeLocationExt> CodeLocationExt for &'a T {
impl<T: ?Sized + CodeLocationExt> CodeLocationExt for &'_ T {
fn loc(&self) -> pt::Loc {
(**self).loc()
}
}

impl<'a, T: ?Sized + CodeLocationExt> CodeLocationExt for &'a mut T {
impl<T: ?Sized + CodeLocationExt> CodeLocationExt for &'_ mut T {
fn loc(&self) -> pt::Loc {
(**self).loc()
}
}

impl<'a, T: ?Sized + ToOwned + CodeLocationExt> CodeLocationExt for Cow<'a, T> {
impl<T: ?Sized + ToOwned + CodeLocationExt> CodeLocationExt for Cow<'_, T> {
fn loc(&self) -> pt::Loc {
(**self).loc()
}
Expand Down
6 changes: 3 additions & 3 deletions fmt/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<'a> QuoteStateCharIndices<'a> {
}
}

impl<'a> Iterator for QuoteStateCharIndices<'a> {
impl Iterator for QuoteStateCharIndices<'_> {
type Item = (QuoteState, usize, char);
fn next(&mut self) -> Option<Self::Item> {
let (idx, ch) = self.iter.next()?;
Expand Down Expand Up @@ -73,14 +73,14 @@ impl<'a> Iterator for QuoteStateCharIndices<'a> {
/// An iterator over the indices of quoted string locations
pub struct QuotedRanges<'a>(QuoteStateCharIndices<'a>);

impl<'a> QuotedRanges<'a> {
impl QuotedRanges<'_> {
pub fn with_state(mut self, state: QuoteState) -> Self {
self.0 = self.0.with_state(state);
self
}
}

impl<'a> Iterator for QuotedRanges<'a> {
impl Iterator for QuotedRanges<'_> {
type Item = (char, usize, usize);
fn next(&mut self) -> Option<Self::Item> {
let (quote, start) = loop {
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cli/test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Apache-2.0

#[cfg(test)]
#![cfg(test)]

mod tests {
use crate::{cli, options_arg, Cli, Commands};
Expand Down
6 changes: 3 additions & 3 deletions src/codegen/revert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ pub(super) fn require(
FormatArg::StringLiteral,
Expression::BytesLiteral {
loc: Loc::Codegen,
ty: Type::Bytes(error_string.as_bytes().len() as u8),
ty: Type::Bytes(error_string.len() as u8),
value: error_string.as_bytes().to_vec(),
},
),
Expand Down Expand Up @@ -350,7 +350,7 @@ pub(super) fn revert(
FormatArg::StringLiteral,
Expression::BytesLiteral {
loc: Codegen,
ty: Type::Bytes(error_string.as_bytes().len() as u8),
ty: Type::Bytes(error_string.len() as u8),
value: error_string.as_bytes().to_vec(),
},
),
Expand Down Expand Up @@ -412,7 +412,7 @@ pub(super) fn string_to_expr(string: String) -> Expression {
FormatArg::StringLiteral,
Expression::BytesLiteral {
loc: Loc::Codegen,
ty: Type::Bytes(string.as_bytes().len() as u8),
ty: Type::Bytes(string.len() as u8),
value: string.as_bytes().to_vec(),
},
)],
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/strength_reduce/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::collections::{HashMap, HashSet};
use std::convert::TryInto;
use value::{get_max_signed, get_max_unsigned, is_single_constant, Value};

/**
/*
Strength Reduce optimization pass - replace expensive arithmetic operations with cheaper ones

Currently implemented:
Expand Down
6 changes: 3 additions & 3 deletions src/codegen/strength_reduce/reaching_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ pub(super) fn reaching_values(
/// changes in the set.
/// There is a discussion to improve this function: https://github.com/hyperledger-solang/solang/issues/934
fn update_map(var_no: usize, set: &HashSet<Value>, map: &mut Variables) -> bool {
return if let Some(existing) = map.get_mut(&var_no) {
if existing.iter().next().map_or(false, |v| v.all_unknown()) {
if let Some(existing) = map.get_mut(&var_no) {
if existing.iter().next().is_some_and(|v| v.all_unknown()) {
// If we already think it is unknown, nothing can improve on that
false
} else if let Some(v) = set.iter().find(|v| v.all_unknown()) {
Expand Down Expand Up @@ -138,7 +138,7 @@ fn update_map(var_no: usize, set: &HashSet<Value>, map: &mut Variables) -> bool
}

true
};
}
}

/// For a given instruction, calculate the new reaching values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
use std::rc::Rc;

impl<'a, 'b: 'a> AvailableExpressionSet<'a> {
impl<'a> AvailableExpressionSet<'a> {
/// Deep clone a set
pub fn deep_clone(&self) -> AvailableExpressionSet<'a> {
let mut new_set = AvailableExpressionSet {
Expand Down
5 changes: 2 additions & 3 deletions src/emit/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,8 +909,7 @@ impl<'a> Binary<'a> {
pub(crate) fn llvm_type(&self, ty: &Type, ns: &Namespace) -> BasicTypeEnum<'a> {
emit_context!(self);
if ty.is_builtin_struct() == Some(StructType::AccountInfo) {
return self
.context
self.context
.struct_type(
&[
byte_ptr!().as_basic_type_enum(), // SolPubkey *
Expand All @@ -925,7 +924,7 @@ impl<'a> Binary<'a> {
],
false,
)
.as_basic_type_enum();
.as_basic_type_enum()
} else {
match ty {
Type::Bool => BasicTypeEnum::IntType(self.context.bool_type()),
Expand Down
2 changes: 1 addition & 1 deletion src/emit/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ pub(super) fn multiply<'a, T: TargetRuntime<'a> + ?Sized>(
.build_int_truncate(res.into_int_value(), left.get_type(), "")
.unwrap()
} else {
return call_mul32_without_ovf(bin, l, r, o, mul_bits, mul_ty, left.get_type());
call_mul32_without_ovf(bin, l, r, o, mul_bits, mul_ty, left.get_type())
}
} else if !unchecked {
build_binary_op_with_overflow_check(
Expand Down
2 changes: 1 addition & 1 deletion src/sema/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl<'a> FormatIterator<'a> {
}
}

impl<'a> Iterator for FormatIterator<'a> {
impl Iterator for FormatIterator<'_> {
type Item = (pt::Loc, char);

fn next(&mut self) -> Option<Self::Item> {
Expand Down
2 changes: 1 addition & 1 deletion src/sema/mutability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct StateCheck<'a> {
data_account: DataAccountUsage,
}

impl<'a> StateCheck<'a> {
impl StateCheck<'_> {
fn value(&mut self, loc: &pt::Loc) {
self.check_level(loc, Access::Value);
self.required_access.increase_to(Access::Value);
Expand Down
Loading