Skip to content

Commit

Permalink
remove redundant imports and prefer it.first() to it.get(0)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Apr 27, 2024
1 parent 6627ad1 commit 724c3be
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion spec-test/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ impl<'s> Parse<'s> for Script<'s> {
while !parser.is_done()? {
commands.push(parser.parse()?);
}
let start = commands.get(0).map(Command::start_pos).unwrap_or(0);
let start = commands.first().map(Command::start_pos).unwrap_or(0);
Ok(Script { start, commands })
}
}
Expand Down
2 changes: 1 addition & 1 deletion wain-exec/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Memory {
pub fn allocate(memories: &[ast::Memory]) -> Result<Self> {
// Note: Only one memory exists thanks to validation
assert!(memories.len() <= 1);
if let Some(memory) = memories.get(0) {
if let Some(memory) = memories.first() {
if let Some(i) = &memory.import {
Err(Trap::unknown_import(i, "memory", memory.start))
} else {
Expand Down
2 changes: 1 addition & 1 deletion wain-exec/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl<'m, 's, I: Importer> Runtime<'m, 's, I> {

let fty = &module.types[func.idx as usize];
let name = &i.name.0;
match importer.validate(name, &fty.params, fty.results.get(0).copied()) {
match importer.validate(name, &fty.params, fty.results.first().copied()) {
Some(ImportInvalidError::NotFound) => {
return Err(unknown_import(i, func.start));
}
Expand Down
1 change: 0 additions & 1 deletion wain-exec/src/stack.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::value::{LittleEndian, Value};
use std::cmp::Ordering;
use std::convert::{TryFrom, TryInto};
use std::fmt;
use std::mem;
use std::mem::size_of;
Expand Down
2 changes: 1 addition & 1 deletion wain-exec/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl Table {
pub fn allocate(tables: &[ast::Table]) -> Result<Self> {
// Note: Only one table exists thanks to validation
assert!(tables.len() <= 1);
if let Some(table) = tables.get(0) {
if let Some(table) = tables.first() {
if let Some(i) = &table.import {
Err(Trap::unknown_import(i, "table", table.start))
} else {
Expand Down
1 change: 0 additions & 1 deletion wain-exec/src/value.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::convert::{TryFrom, TryInto};
use std::fmt;
use std::mem::size_of;
use std::ops;
Expand Down
2 changes: 1 addition & 1 deletion wain-syntax-binary/src/leb128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ mod tests {

#[test]
fn u32_value_ok() {
for (input, expected) in vec![
for (input, expected) in [
(vec![0x00], 0),
(vec![0x80, 0x01], 128),
(vec![0xc0, 0xc4, 0x07], 123456),
Expand Down
1 change: 0 additions & 1 deletion wain-syntax-binary/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::error::{Error, ErrorKind, Result};
use crate::leb128::Leb128;
use crate::source::BinarySource;
use std::borrow::Cow;
use std::convert::TryInto;
use std::marker::PhantomData;
use std::str;
use wain_ast::*;
Expand Down
2 changes: 1 addition & 1 deletion wain-validate/src/insn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ pub(crate) fn validate_func_body<'outer, S: Source>(
) -> Result<(), S> {
// Note: FuncType already validated func_ty has at most one result type
// This assumes a function can have only one return value
let ret_ty = func_ty.results.get(0).copied();
let ret_ty = func_ty.results.first().copied();
let mut ctx = FuncBodyContext {
current_op: "",
current_offset: start,
Expand Down

0 comments on commit 724c3be

Please sign in to comment.