Skip to content

Commit

Permalink
Fix clippy lints and "make lint"
Browse files Browse the repository at this point in the history
  • Loading branch information
fschutt committed Jul 29, 2022
1 parent 2505cd3 commit 17e0dd0
Showing 6 changed files with 65 additions and 59 deletions.
9 changes: 5 additions & 4 deletions lib/c-api/build.rs
Original file line number Diff line number Diff line change
@@ -56,14 +56,14 @@ macro_rules! map_feature_as_c_define {
($feature:expr, $c_define:ident, $accumulator:ident) => {
#[cfg(feature = $feature)]
{
$accumulator.push_str(&format!(
let _ = write!($accumulator
r#"
// The `{feature}` feature has been enabled for this build.
#define {define}
"#,
feature = $feature,
define = $c_define,
));
);
}
};
}
@@ -184,7 +184,8 @@ fn build_wasm_c_api_headers(crate_dir: &str, out_dir: &str) {
}

fn add_wasmer_version(pre_header: &mut String) {
pre_header.push_str(&format!(
let _ = write!(
pre_header,
r#"
// This file corresponds to the following Wasmer version.
#define WASMER_VERSION "{full}"
@@ -198,7 +199,7 @@ fn add_wasmer_version(pre_header: &mut String) {
minor = env!("CARGO_PKG_VERSION_MINOR"),
patch = env!("CARGO_PKG_VERSION_PATCH"),
pre = env!("CARGO_PKG_VERSION_PRE"),
));
);
}

/// Create a fresh new `Builder`, already pre-configured.
2 changes: 1 addition & 1 deletion lib/types/src/units.rs
Original file line number Diff line number Diff line change
@@ -115,7 +115,7 @@ where
}

/// The only error that can happen when converting `Bytes` to `Pages`
#[derive(Debug, Clone, Copy, PartialEq, Error)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
#[error("Number of pages exceeds uint32 range")]
pub struct PageCountOutOfRange;

49 changes: 28 additions & 21 deletions lib/vfs/src/mem_fs/file.rs
Original file line number Diff line number Diff line change
@@ -51,12 +51,11 @@ impl VirtualFile for FileHandle {
_ => return 0,
};

let node = match fs.storage.get(self.inode) {
Some(node) => node,
_ => return 0,
};

node.metadata().accessed
let inode = fs.storage.get(self.inode);
match inode {
Some(node) => node.metadata().accessed,
_ => 0,
}
}

fn last_modified(&self) -> u64 {
@@ -65,12 +64,11 @@ impl VirtualFile for FileHandle {
_ => return 0,
};

let node = match fs.storage.get(self.inode) {
Some(node) => node,
_ => return 0,
};

node.metadata().modified
let inode = fs.storage.get(self.inode);
match inode {
Some(node) => node.metadata().modified,
_ => 0,
}
}

fn created_time(&self) -> u64 {
@@ -79,7 +77,8 @@ impl VirtualFile for FileHandle {
_ => return 0,
};

let node = match fs.storage.get(self.inode) {
let inode = fs.storage.get(self.inode);
let node = match inode {
Some(node) => node,
_ => return 0,
};
@@ -93,7 +92,8 @@ impl VirtualFile for FileHandle {
_ => return 0,
};

match fs.storage.get(self.inode) {
let inode = fs.storage.get(self.inode);
match inode {
Some(Node::File { file, .. }) => file.len().try_into().unwrap_or(0),
_ => 0,
}
@@ -106,7 +106,8 @@ impl VirtualFile for FileHandle {
.try_write()
.map_err(|_| FsError::Lock)?;

match fs.storage.get_mut(self.inode) {
let inode = fs.storage.get_mut(self.inode);
match inode {
Some(Node::File { file, metadata, .. }) => {
file.buffer
.resize(new_size.try_into().map_err(|_| FsError::UnknownError)?, 0);
@@ -178,7 +179,8 @@ impl VirtualFile for FileHandle {
.try_read()
.map_err(|_| FsError::Lock)?;

match fs.storage.get(self.inode) {
let inode = fs.storage.get(self.inode);
match inode {
Some(Node::File { file, .. }) => Ok(file.buffer.len() - file.cursor),
_ => Err(FsError::NotAFile),
}
@@ -416,7 +418,8 @@ impl Read for FileHandle {
io::Error::new(io::ErrorKind::Other, "failed to acquire a write lock")
})?;

let file = match fs.storage.get_mut(self.inode) {
let inode = fs.storage.get_mut(self.inode);
let file = match inode {
Some(Node::File { file, .. }) => file,
_ => {
return Err(io::Error::new(
@@ -445,7 +448,8 @@ impl Read for FileHandle {
io::Error::new(io::ErrorKind::Other, "failed to acquire a write lock")
})?;

let file = match fs.storage.get_mut(self.inode) {
let inode = fs.storage.get_mut(self.inode);
let file = match inode {
Some(Node::File { file, .. }) => file,
_ => {
return Err(io::Error::new(
@@ -493,7 +497,8 @@ impl Read for FileHandle {
io::Error::new(io::ErrorKind::Other, "failed to acquire a write lock")
})?;

let file = match fs.storage.get_mut(self.inode) {
let inode = fs.storage.get_mut(self.inode);
let file = match inode {
Some(Node::File { file, .. }) => file,
_ => {
return Err(io::Error::new(
@@ -532,7 +537,8 @@ impl Seek for FileHandle {
io::Error::new(io::ErrorKind::Other, "failed to acquire a write lock")
})?;

let file = match fs.storage.get_mut(self.inode) {
let inode = fs.storage.get_mut(self.inode);
let file = match inode {
Some(Node::File { file, .. }) => file,
_ => {
return Err(io::Error::new(
@@ -563,7 +569,8 @@ impl Write for FileHandle {
io::Error::new(io::ErrorKind::Other, "failed to acquire a write lock")
})?;

let (file, metadata) = match fs.storage.get_mut(self.inode) {
let inode = fs.storage.get_mut(self.inode);
let (file, metadata) = match inode {
Some(Node::File { file, metadata, .. }) => (file, metadata),
_ => {
return Err(io::Error::new(
5 changes: 3 additions & 2 deletions lib/vfs/src/mem_fs/file_opener.rs
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ impl crate::FileOpener for FileOpener {

// Find the inode of the file if it exists.
let maybe_inode_of_file = fs
.from_parent_get_position_and_inode_of_file(inode_of_parent, &name_of_file)?
.as_parent_get_position_and_inode_of_file(inode_of_parent, &name_of_file)?
.map(|(_nth, inode)| inode);

(inode_of_parent, maybe_inode_of_file, name_of_file)
@@ -81,7 +81,8 @@ impl crate::FileOpener for FileOpener {
.try_write()
.map_err(|_| FsError::Lock)?;

match fs.storage.get_mut(inode_of_file) {
let inode = fs.storage.get_mut(inode_of_file);
match inode {
Some(Node::File { metadata, file, .. }) => {
// Update the accessed time.
metadata.accessed = time();
35 changes: 15 additions & 20 deletions lib/vfs/src/mem_fs/filesystem.rs
Original file line number Diff line number Diff line change
@@ -28,7 +28,8 @@ impl crate::FileSystem for FileSystem {
let (path, inode_of_directory) = fs.canonicalize(path)?;

// Check it's a directory and fetch the immediate children as `DirEntry`.
let children = match fs.storage.get(inode_of_directory) {
let inode = fs.storage.get(inode_of_directory);
let children = match inode {
Some(Node::Directory { children, .. }) => children
.iter()
.filter_map(|inode| fs.storage.get(*inode))
@@ -133,12 +134,11 @@ impl crate::FileSystem for FileSystem {

// Get the child index to remove in the parent node, in
// addition to the inode of the directory to remove.
let (position, inode_of_directory) = fs
.from_parent_get_position_and_inode_of_directory(
inode_of_parent,
&name_of_directory,
DirectoryMustBeEmpty::Yes,
)?;
let (position, inode_of_directory) = fs.as_parent_get_position_and_inode_of_directory(
inode_of_parent,
&name_of_directory,
DirectoryMustBeEmpty::Yes,
)?;

(inode_of_parent, position, inode_of_directory)
};
@@ -183,7 +183,7 @@ impl crate::FileSystem for FileSystem {
// Get the child indexes to update in the parent nodes, in
// addition to the inode of the directory to update.
let (position_of_from, inode) = fs
.from_parent_get_position_and_inode(inode_of_from_parent, &name_of_from)?
.as_parent_get_position_and_inode(inode_of_from_parent, &name_of_from)?
.ok_or(FsError::NotAFile)?;

(
@@ -211,7 +211,8 @@ impl crate::FileSystem for FileSystem {
}
// Otherwise, we need to at least update the modified time of the parent.
else {
match fs.storage.get_mut(inode_of_from_parent) {
let inode = fs.storage.get_mut(inode_of_from_parent);
match inode {
Some(Node::Directory {
metadata: Metadata { modified, .. },
..
@@ -258,7 +259,7 @@ impl crate::FileSystem for FileSystem {

// Find the inode of the file if it exists, along with its position.
let maybe_position_and_inode_of_file =
fs.from_parent_get_position_and_inode_of_file(inode_of_parent, &name_of_file)?;
fs.as_parent_get_position_and_inode_of_file(inode_of_parent, &name_of_file)?;

match maybe_position_and_inode_of_file {
Some((position, inode_of_file)) => (inode_of_parent, position, inode_of_file),
@@ -318,13 +319,7 @@ impl FileSystemInner {
Node::Directory { children, .. } => children
.iter()
.filter_map(|inode| self.storage.get(*inode))
.find_map(|node| {
if node.name() == component.as_os_str() {
Some(node)
} else {
None
}
})
.find(|node| node.name() == component.as_os_str())
.ok_or(FsError::NotAFile)?,
_ => return Err(FsError::BaseNotDirectory),
};
@@ -347,7 +342,7 @@ impl FileSystemInner {

/// From the inode of a parent node (so, a directory), returns the
/// child index of `name_of_directory` along with its inode.
pub(super) fn from_parent_get_position_and_inode_of_directory(
pub(super) fn as_parent_get_position_and_inode_of_directory(
&self,
inode_of_parent: Inode,
name_of_directory: &OsString,
@@ -382,7 +377,7 @@ impl FileSystemInner {

/// From the inode of a parent node (so, a directory), returns the
/// child index of `name_of_file` along with its inode.
pub(super) fn from_parent_get_position_and_inode_of_file(
pub(super) fn as_parent_get_position_and_inode_of_file(
&self,
inode_of_parent: Inode,
name_of_file: &OsString,
@@ -409,7 +404,7 @@ impl FileSystemInner {
/// From the inode of a parent node (so, a directory), returns the
/// child index of `name_of` along with its inode, whatever the
/// type of inode is (directory or file).
fn from_parent_get_position_and_inode(
fn as_parent_get_position_and_inode(
&self,
inode_of_parent: Inode,
name_of: &OsString,
24 changes: 13 additions & 11 deletions tests/wasi-wast/src/wasitests.rs
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ use std::io::prelude::*;
use super::util;
use super::wasi_version::*;

#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NativeOutput {
stdout: String,
stderr: String,
@@ -284,6 +284,8 @@ pub struct WasiTest {

impl WasiTest {
fn into_wasi_wast(self) -> String {
use std::fmt::Write;

let mut out = format!(
";; This file was generated by https://github.com/wasmerio/wasi-tests\n
(wasi_test \"{}\"",
@@ -297,7 +299,7 @@ impl WasiTest {
.map(|(name, value)| format!("\"{}={}\"", name, value))
.collect::<Vec<String>>()
.join(" ");
out += &format!("\n (envs {})", envs);
let _ = write!(out, "\n (envs {})", envs);
}
if !self.options.args.is_empty() {
let args = self
@@ -307,7 +309,7 @@ impl WasiTest {
.map(|v| format!("\"{}\"", v))
.collect::<Vec<String>>()
.join(" ");
out += &format!("\n (args {})", args);
let _ = write!(out, "\n (args {})", args);
}

if !self.options.dir.is_empty() {
@@ -318,7 +320,7 @@ impl WasiTest {
.map(|v| format!("\"{}\"", v))
.collect::<Vec<String>>()
.join(" ");
out += &format!("\n (preopens {})", preopens);
let _ = write!(out, "\n (preopens {})", preopens);
}
if !self.options.mapdir.is_empty() {
let map_dirs = self
@@ -328,7 +330,7 @@ impl WasiTest {
.map(|(a, b)| format!("\"{}:{}\"", a, b))
.collect::<Vec<String>>()
.join(" ");
out += &format!("\n (map_dirs {})", map_dirs);
let _ = write!(out, "\n (map_dirs {})", map_dirs);
}
if !self.options.tempdir.is_empty() {
let temp_dirs = self
@@ -338,22 +340,22 @@ impl WasiTest {
.map(|td| format!("\"{}\"", td))
.collect::<Vec<String>>()
.join(" ");
out += &format!("\n (temp_dirs {})", temp_dirs);
let _ = write!(out, "\n (temp_dirs {})", temp_dirs);
}

out += &format!("\n (assert_return (i64.const {}))", self.result);
let _ = write!(out, "\n (assert_return (i64.const {}))", self.result);
if let Some(stdin) = &self.options.stdin {
out += &format!("\n (stdin {:?})", stdin);
let _ = write!(out, "\n (stdin {:?})", stdin);
}

if !self.stdout.is_empty() {
out += &format!("\n (assert_stdout {:?})", self.stdout);
let _ = write!(out, "\n (assert_stdout {:?})", self.stdout);
}
if !self.stderr.is_empty() {
out += &format!("\n (assert_stderr {:?})", self.stderr);
let _ = write!(out, "\n (assert_stderr {:?})", self.stderr);
}

out += "\n)\n";
let _ = write!(out, "\n)\n");

out
}

0 comments on commit 17e0dd0

Please sign in to comment.