Skip to content

Commit d13e944

Browse files
authored
Rust 1.84.1 clippies and remove temporary files (#1714)
Signed-off-by: Sean Young <sean@mess.org>
1 parent 11ceb8f commit d13e944

File tree

17 files changed

+37
-436
lines changed

17 files changed

+37
-436
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ Cargo.lock
33
/target
44
**/*.rs.bk
55
*.ll
6-
tests/.tmp*
7-
tests/create_me/
6+
/tests/.tmp*
7+
/tests/create_me/
8+
/test_snapshots/
89

910
.helix/
1011
.vscode/

fmt/src/comments.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl CommentWithMetadata {
117117
// line has something
118118
// check if the last comment after code was a postfix comment
119119
if last_comment
120-
.map_or(false, |last| last.loc.end() > code_end && !last.is_prefix())
120+
.is_some_and(|last| last.loc.end() > code_end && !last.is_prefix())
121121
{
122122
// get the indent size of the next item of code
123123
let next_indent_len = src[comment.loc().end()..]
@@ -434,7 +434,7 @@ impl std::iter::FusedIterator for CommentStateCharIndices<'_> {}
434434
/// An Iterator over characters in a string slice which are not a apart of comments
435435
pub struct NonCommentChars<'a>(CommentStateCharIndices<'a>);
436436

437-
impl<'a> Iterator for NonCommentChars<'a> {
437+
impl Iterator for NonCommentChars<'_> {
438438
type Item = char;
439439

440440
#[inline]

fmt/src/formatter.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl Context {
8989
pub(crate) fn is_constructor_function(&self) -> bool {
9090
self.function
9191
.as_ref()
92-
.map_or(false, |f| matches!(f.ty, FunctionTy::Constructor))
92+
.is_some_and(|f| matches!(f.ty, FunctionTy::Constructor))
9393
}
9494
}
9595

@@ -348,7 +348,7 @@ impl<'a, W: Write> Formatter<'a, W> {
348348
};
349349

350350
self.find_next_line(start_from)
351-
.map_or(false, |loc| loc >= end_at)
351+
.is_some_and(|loc| loc >= end_at)
352352
}
353353
}
354354
}
@@ -549,7 +549,7 @@ impl<'a, W: Write> Formatter<'a, W> {
549549
fn write_doc_block_line(&mut self, comment: &CommentWithMetadata, line: &str) -> Result<()> {
550550
if line.trim().starts_with('*') {
551551
let line = line.trim().trim_start_matches('*');
552-
let needs_space = line.chars().next().map_or(false, |ch| !ch.is_whitespace());
552+
let needs_space = line.chars().next().is_some_and(|ch| !ch.is_whitespace());
553553
write!(self.buf(), " *{}", if needs_space { " " } else { "" })?;
554554
self.write_comment_line(comment, line)?;
555555
self.write_whitespace_separator(true)?;
@@ -1797,7 +1797,7 @@ impl<'a, W: Write> Formatter<'a, W> {
17971797
}
17981798

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

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

18641864
// EOF newline
1865-
if self.last_char().map_or(true, |char| char != '\n') {
1865+
if self.last_char() != Some('\n') {
18661866
writeln!(self.buf())?;
18671867
}
18681868

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

32693269
// we can however check if the contract `is` the `base`, this however also does
32703270
// not cover all cases
3271-
let is_contract_base = self.context.contract.as_ref().map_or(false, |contract| {
3271+
let is_contract_base = self.context.contract.as_ref().is_some_and(|contract| {
32723272
contract.base.iter().any(|contract_base| {
32733273
contract_base
32743274
.name
@@ -3292,7 +3292,7 @@ impl<'a, W: Write> Visitor for Formatter<'a, W> {
32923292
.content
32933293
.chars()
32943294
.next()
3295-
.map_or(false, |c| c.is_lowercase());
3295+
.is_some_and(|c| c.is_lowercase());
32963296
if is_lowercase && base_or_modifier.content.ends_with("()") {
32973297
base_or_modifier
32983298
.content
@@ -3904,14 +3904,14 @@ struct Transaction<'f, 'a, W> {
39043904
comments: Comments,
39053905
}
39063906

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

3914-
impl<'f, 'a, W> std::ops::DerefMut for Transaction<'f, 'a, W> {
3914+
impl<W> std::ops::DerefMut for Transaction<'_, '_, W> {
39153915
fn deref_mut(&mut self) -> &mut Self::Target {
39163916
self.fmt
39173917
}

fmt/src/solang_ext/loc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ pub trait CodeLocationExt {
1212
fn loc(&self) -> pt::Loc;
1313
}
1414

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

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

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

fmt/src/string.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl<'a> QuoteStateCharIndices<'a> {
4343
}
4444
}
4545

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

76-
impl<'a> QuotedRanges<'a> {
76+
impl QuotedRanges<'_> {
7777
pub fn with_state(mut self, state: QuoteState) -> Self {
7878
self.0 = self.0.with_state(state);
7979
self
8080
}
8181
}
8282

83-
impl<'a> Iterator for QuotedRanges<'a> {
83+
impl Iterator for QuotedRanges<'_> {
8484
type Item = (char, usize, usize);
8585
fn next(&mut self) -> Option<Self::Item> {
8686
let (quote, start) = loop {

src/bin/cli/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: Apache-2.0
22

3-
#[cfg(test)]
3+
#![cfg(test)]
44

55
mod tests {
66
use crate::{cli, options_arg, Cli, Commands};

src/codegen/revert.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ pub(super) fn require(
281281
FormatArg::StringLiteral,
282282
Expression::BytesLiteral {
283283
loc: Loc::Codegen,
284-
ty: Type::Bytes(error_string.as_bytes().len() as u8),
284+
ty: Type::Bytes(error_string.len() as u8),
285285
value: error_string.as_bytes().to_vec(),
286286
},
287287
),
@@ -350,7 +350,7 @@ pub(super) fn revert(
350350
FormatArg::StringLiteral,
351351
Expression::BytesLiteral {
352352
loc: Codegen,
353-
ty: Type::Bytes(error_string.as_bytes().len() as u8),
353+
ty: Type::Bytes(error_string.len() as u8),
354354
value: error_string.as_bytes().to_vec(),
355355
},
356356
),
@@ -412,7 +412,7 @@ pub(super) fn string_to_expr(string: String) -> Expression {
412412
FormatArg::StringLiteral,
413413
Expression::BytesLiteral {
414414
loc: Loc::Codegen,
415-
ty: Type::Bytes(string.as_bytes().len() as u8),
415+
ty: Type::Bytes(string.len() as u8),
416416
value: string.as_bytes().to_vec(),
417417
},
418418
)],

src/codegen/strength_reduce/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::collections::{HashMap, HashSet};
1717
use std::convert::TryInto;
1818
use value::{get_max_signed, get_max_unsigned, is_single_constant, Value};
1919

20-
/**
20+
/*
2121
Strength Reduce optimization pass - replace expensive arithmetic operations with cheaper ones
2222
2323
Currently implemented:

src/codegen/strength_reduce/reaching_values.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ pub(super) fn reaching_values(
8989
/// changes in the set.
9090
/// There is a discussion to improve this function: https://github.com/hyperledger-solang/solang/issues/934
9191
fn update_map(var_no: usize, set: &HashSet<Value>, map: &mut Variables) -> bool {
92-
return if let Some(existing) = map.get_mut(&var_no) {
93-
if existing.iter().next().map_or(false, |v| v.all_unknown()) {
92+
if let Some(existing) = map.get_mut(&var_no) {
93+
if existing.iter().next().is_some_and(|v| v.all_unknown()) {
9494
// If we already think it is unknown, nothing can improve on that
9595
false
9696
} else if let Some(v) = set.iter().find(|v| v.all_unknown()) {
@@ -138,7 +138,7 @@ fn update_map(var_no: usize, set: &HashSet<Value>, map: &mut Variables) -> bool
138138
}
139139

140140
true
141-
};
141+
}
142142
}
143143

144144
/// For a given instruction, calculate the new reaching values

src/codegen/subexpression_elimination/available_expression_set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::cell::RefCell;
1212
use std::collections::{HashMap, HashSet};
1313
use std::rc::Rc;
1414

15-
impl<'a, 'b: 'a> AvailableExpressionSet<'a> {
15+
impl<'a> AvailableExpressionSet<'a> {
1616
/// Deep clone a set
1717
pub fn deep_clone(&self) -> AvailableExpressionSet<'a> {
1818
let mut new_set = AvailableExpressionSet {

0 commit comments

Comments
 (0)