Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes a bunch of clippy warnings. #118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions etk-analyze/src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,14 @@ mod tests {
let connected = self
.connected
.into_iter()
.map(|x| x.borrow().clone())
.map(|x| *x.borrow())
.map(|(f, t)| Self::find_nodes(&cfg, f, t))
.map(|(f, t)| (f, t, true));

let unconnected = self
.unconnected
.into_iter()
.map(|x| x.borrow().clone())
.map(|x| *x.borrow())
.map(|(f, t)| Self::find_nodes(&cfg, f, t))
.map(|(f, t)| (f, t, false));

Expand Down
132 changes: 66 additions & 66 deletions etk-analyze/src/sym.rs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions etk-asm/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl Assembler {
}) => {
let labels = op.expr().unwrap().labels(&self.declared_macros).unwrap();
let declared: HashSet<_> =
self.declared_labels.into_iter().map(|(k, _)| k).collect();
self.declared_labels.into_keys().collect();
let invoked: HashSet<_> = labels.into_iter().collect();
let missing = invoked
.difference(&declared)
Expand Down Expand Up @@ -780,7 +780,7 @@ mod tests {
fn assemble_variable_push_const() -> Result<(), Error> {
let mut asm = Assembler::new();
let sz = asm.push_all(vec![AbstractOp::Push(
Terminal::Number((0x00aaaaaaaaaaaaaaaaaaaaaaaa as u128).into()).into(),
Terminal::Number(0x00aaaaaaaaaaaaaaaaaaaaaaaa_u128.into()).into(),
)])?;
assert_eq!(13, sz);
assert_eq!(asm.take(), hex!("6baaaaaaaaaaaaaaaaaaaaaaaa"));
Expand Down Expand Up @@ -813,7 +813,7 @@ mod tests {
fn assemble_variable_push_const0() -> Result<(), Error> {
let mut asm = Assembler::new();
let sz = asm.push_all(vec![AbstractOp::Push(
Terminal::Number((0x00 as u128).into()).into(),
Terminal::Number(0x00_u128.into()).into(),
)])?;
assert_eq!(2, sz);
assert_eq!(asm.take(), hex!("6000"));
Expand Down Expand Up @@ -1273,7 +1273,7 @@ mod tests {
AbstractOp::Macro(InstructionMacroInvocation {
name: "my_macro".into(),
parameters: vec![
BigInt::from_bytes_be(Sign::Plus, &vec![0x42]).into(),
BigInt::from_bytes_be(Sign::Plus, &[0x42]).into(),
Terminal::Label("b".to_string()).into(),
],
}),
Expand Down
2 changes: 1 addition & 1 deletion etk-asm/src/disasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl<'a> Iterator for Iter<'a> {
let buffer = &mut self.disassembler.buffer;
let front = *buffer.front()?;
let specifier = Op::<()>::from(front);
let len = specifier.size() as usize;
let len = specifier.size();
if buffer.len() < len {
return None;
}
Expand Down
7 changes: 3 additions & 4 deletions etk-asm/src/ingest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ mod tests {
let mut f = NamedTempFile::new().unwrap();
let root = f.path().parent().unwrap().join("root.asm");

write!(f, "{}", s).unwrap();
write!(f, "{s}").unwrap();
(f, root)
}

Expand Down Expand Up @@ -759,13 +759,12 @@ mod tests {
fn ingest_recursive() {
let (mut f, root) = new_file("");
let path = f.path().display().to_string();
write!(f, r#"%import("{}")"#, path).unwrap();
write!(f, r#"%import("{path}")"#).unwrap();

let text = format!(
r#"
%import("{}")
%import("{path}")
"#,
path,
);

let mut output = Vec::new();
Expand Down
10 changes: 5 additions & 5 deletions etk-asm/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,14 @@ impl fmt::Display for AbstractOp {
Self::Op(op) => {
write!(f, "{}", op.code())?;
if let Some(imm) = op.immediate() {
write!(f, " {}", imm)?;
write!(f, " {imm}")?;
}
Ok(())
}
Self::Push(txt) => write!(f, r#"%push({})"#, txt),
Self::Label(lbl) => write!(f, r#"{}:"#, lbl),
Self::Macro(m) => write!(f, "{}", m),
Self::MacroDefinition(defn) => write!(f, "{}", defn),
Self::Push(txt) => write!(f, r#"%push({txt})"#),
Self::Label(lbl) => write!(f, r#"{lbl}:"#),
Self::Macro(m) => write!(f, "{m}"),
Self::MacroDefinition(defn) => write!(f, "{defn}"),
}
}
}
Expand Down
38 changes: 19 additions & 19 deletions etk-asm/src/ops/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ pub enum Expression {
impl Debug for Expression {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Expression::Expression(s) => write!(f, r#"({:?})"#, s),
Expression::Expression(s) => write!(f, r#"({s:?})"#),
Expression::Macro(m) => write!(f, r#"Expression::Macro("{}")"#, m.name),
Expression::Terminal(t) => write!(f, r#"Expression::Terminal({:?})"#, t),
Expression::Plus(lhs, rhs) => write!(f, r#"Expression::Plus({:?}, {:?})"#, lhs, rhs),
Expression::Minus(lhs, rhs) => write!(f, r#"Expression::Minus({:?}, {:?})"#, lhs, rhs),
Expression::Times(lhs, rhs) => write!(f, r#"Expression::Times({:?}, {:?})"#, lhs, rhs),
Expression::Terminal(t) => write!(f, r#"Expression::Terminal({t:?})"#),
Expression::Plus(lhs, rhs) => write!(f, r#"Expression::Plus({lhs:?}, {rhs:?})"#),
Expression::Minus(lhs, rhs) => write!(f, r#"Expression::Minus({lhs:?}, {rhs:?})"#),
Expression::Times(lhs, rhs) => write!(f, r#"Expression::Times({lhs:?}, {rhs:?})"#),
Expression::Divide(lhs, rhs) => {
write!(f, r#"Expression::Divide({:?}, {:?})"#, lhs, rhs)
write!(f, r#"Expression::Divide({lhs:?}, {rhs:?})"#)
}
}
}
Expand All @@ -134,13 +134,13 @@ impl Debug for Expression {
impl fmt::Display for Expression {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Expression::Expression(s) => write!(f, r#"({})"#, s),
Expression::Macro(m) => write!(f, r#"{}"#, m),
Expression::Terminal(t) => write!(f, r#"{}"#, t),
Expression::Plus(lhs, rhs) => write!(f, r#"{}+{}"#, lhs, rhs),
Expression::Minus(lhs, rhs) => write!(f, r#"{}-{}"#, lhs, rhs),
Expression::Times(lhs, rhs) => write!(f, r#"{}*{}"#, lhs, rhs),
Expression::Divide(lhs, rhs) => write!(f, r#"{}/{}"#, lhs, rhs),
Expression::Expression(s) => write!(f, r#"({s})"#),
Expression::Macro(m) => write!(f, r#"{m}"#),
Expression::Terminal(t) => write!(f, r#"{t}"#),
Expression::Plus(lhs, rhs) => write!(f, r#"{lhs}+{rhs}"#),
Expression::Minus(lhs, rhs) => write!(f, r#"{lhs}-{rhs}"#),
Expression::Times(lhs, rhs) => write!(f, r#"{lhs}*{rhs}"#),
Expression::Divide(lhs, rhs) => write!(f, r#"{lhs}/{rhs}"#),
}
}
}
Expand Down Expand Up @@ -309,19 +309,19 @@ impl Expression {
impl Debug for Terminal {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Terminal::Label(l) => write!(f, r#"Terminal::Label({})"#, l),
Terminal::Number(n) => write!(f, r#"Terminal::Number({})"#, n),
Terminal::Variable(v) => write!(f, r#"Terminal::Variable({})"#, v),
Terminal::Label(l) => write!(f, r#"Terminal::Label({l})"#),
Terminal::Number(n) => write!(f, r#"Terminal::Number({n})"#),
Terminal::Variable(v) => write!(f, r#"Terminal::Variable({v})"#),
}
}
}

impl fmt::Display for Terminal {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Terminal::Label(l) => write!(f, r#"Label({})"#, l),
Terminal::Number(n) => write!(f, r#"{}"#, n),
Terminal::Variable(v) => write!(f, r#"Variable({})"#, v),
Terminal::Label(l) => write!(f, r#"Label({l})"#),
Terminal::Number(n) => write!(f, r#"{n}"#),
Terminal::Variable(v) => write!(f, r#"Variable({v})"#),
}
}
}
Expand Down
76 changes: 26 additions & 50 deletions etk-asm/src/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,11 @@ mod tests {

#[test]
fn parse_include() {
let asm = format!(
r#"
let asm = r#"
push1 1
%include("foo.asm")
push1 2
"#,
);
"#.to_string();
let expected = nodes![
Op::from(Push1(Imm::from(1u8))),
Node::Include(PathBuf::from("foo.asm")),
Expand All @@ -348,13 +346,11 @@ mod tests {

#[test]
fn parse_include_hex() {
let asm = format!(
r#"
let asm = r#"
push1 1
%include_hex("foo.hex")
push1 2
"#,
);
"#.to_string();
let expected = nodes![
Op::from(Push1(Imm::from(1u8))),
Node::IncludeHex(PathBuf::from("foo.hex")),
Expand All @@ -365,13 +361,11 @@ mod tests {

#[test]
fn parse_import() {
let asm = format!(
r#"
let asm = r#"
push1 1
%import("foo.asm")
push1 2
"#,
);
"#.to_string();
let expected = nodes![
Op::from(Push1(Imm::from(1u8))),
Node::Import(PathBuf::from("foo.asm")),
Expand All @@ -382,11 +376,9 @@ mod tests {

#[test]
fn parse_import_extra_argument() {
let asm = format!(
r#"
let asm = r#"
%import("foo.asm", "bar.asm")
"#,
);
"#.to_string();
assert!(matches!(
parse_asm(&asm),
Err(ParseError::ExtraArgument {
Expand All @@ -398,11 +390,9 @@ mod tests {

#[test]
fn parse_import_missing_argument() {
let asm = format!(
r#"
let asm = r#"
%import()
"#,
);
"#.to_string();
assert!(matches!(
parse_asm(&asm),
Err(ParseError::MissingArgument {
Expand All @@ -415,23 +405,19 @@ mod tests {

#[test]
fn parse_import_argument_type() {
let asm = format!(
r#"
let asm = r#"
%import(0x44)
"#,
);
"#.to_string();
assert_matches!(parse_asm(&asm), Err(ParseError::ArgumentType { .. }))
}

#[test]
fn parse_import_spaces() {
let asm = format!(
r#"
let asm = r#"
push1 1
%import( "hello.asm" )
push1 2
"#,
);
"#.to_string();
let expected = nodes![
Op::from(Push1(Imm::from(1u8))),
Node::Import(PathBuf::from("hello.asm")),
Expand All @@ -442,13 +428,11 @@ mod tests {

#[test]
fn parse_push_macro_with_label() {
let asm = format!(
r#"
let asm = r#"
push1 1
%push( hello )
push1 2
"#,
);
"#.to_string();
let expected = nodes![
Op::from(Push1(Imm::from(1u8))),
AbstractOp::Push(Imm::with_label("hello")),
Expand All @@ -459,8 +443,7 @@ mod tests {

#[test]
fn parse_instruction_macro() {
let asm = format!(
r#"
let asm = r#"
%macro my_macro(foo, bar)
gasprice
pop
Expand All @@ -469,8 +452,7 @@ mod tests {
%another_macro()
%end
%my_macro(0x42, 10)
"#,
);
"#.to_string();
let expected = nodes![
AbstractOp::MacroDefinition(
InstructionMacroDefinition {
Expand Down Expand Up @@ -498,10 +480,10 @@ mod tests {
AbstractOp::Macro(InstructionMacroInvocation {
name: "my_macro".into(),
parameters: vec![
BigInt::from_bytes_be(Sign::Plus, &vec![0x42]).into(),
BigInt::from_bytes_be(Sign::Plus, &[0x42]).into(),
BigInt::from_bytes_be(
Sign::Plus,
&vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10]
&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10]
)
.into()
]
Expand All @@ -513,14 +495,12 @@ mod tests {

#[test]
fn parse_expression() {
let asm = format!(
r#"
let asm = r#"
push1 1+-1
push1 2*foo
push1 (1+(2*foo))-(bar/42)
push1 0x20+0o1+0b10
"#,
);
"#.to_string();
let expected = nodes![
Op::from(Push1(Imm::with_expression(Expression::Plus(
1.into(),
Expand Down Expand Up @@ -556,13 +536,11 @@ mod tests {

#[test]
fn parse_push_macro_with_expression() {
let asm = format!(
r#"
let asm = r#"
push1 1
%push( 1 + 1 )
push1 2
"#,
);
"#.to_string();
let expected = nodes![
Op::from(Push1(Imm::from(1u8))),
AbstractOp::Push(Imm::with_expression(Expression::Plus(1.into(), 1.into()))),
Expand All @@ -573,14 +551,12 @@ mod tests {

#[test]
fn parse_expression_macro() {
let asm = format!(
r#"
let asm = r#"
%def foobar()
1+2
%end
push1 foobar()
"#,
);
"#.to_string();
let expected = nodes![
ExpressionMacroDefinition {
name: "foobar".into(),
Expand Down
4 changes: 2 additions & 2 deletions etk-asm/tests/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ fn source<P>(paths: &[P]) -> PathBuf
where
P: AsRef<Path>,
{
let rel: PathBuf = paths.into_iter().collect();
let rel: PathBuf = paths.iter().collect();
let mut root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
root.push("tests");
root.push("asm");
root.join(&rel)
root.join(rel)
}

#[test]
Expand Down
Loading