Skip to content

Commit

Permalink
Minor fixes to prevent warnings for Rust 2021 (bytecodealliance#255)
Browse files Browse the repository at this point in the history
* Minor fixes to prevent warnings related to Rust 2021 in the tests
* Remove unnecessary references
* Silence clippy

Co-authored-by: Sergei Shulepov <sergei@parity.io>
  • Loading branch information
chevdor and pepyakin committed Jul 8, 2021
1 parent 0f728ff commit 50a2bb0
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl FuncInstance {
args: &[RuntimeValue],
externals: &mut E,
) -> Result<Option<RuntimeValue>, Trap> {
check_function_args(func.signature(), &args)?;
check_function_args(func.signature(), args)?;
match *func.as_internal() {
FuncInstanceInternal::Internal { .. } => {
let mut interpreter = Interpreter::new(func, args, None)?;
Expand All @@ -165,7 +165,7 @@ impl FuncInstance {
externals: &mut E,
stack_recycler: &mut StackRecycler,
) -> Result<Option<RuntimeValue>, Trap> {
check_function_args(func.signature(), &args)?;
check_function_args(func.signature(), args)?;
match *func.as_internal() {
FuncInstanceInternal::Internal { .. } => {
let mut interpreter = Interpreter::new(func, args, Some(stack_recycler))?;
Expand Down
4 changes: 2 additions & 2 deletions src/memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ impl MemoryInstance {
///
/// [`set`]: #method.get
/// [`clear`]: #method.set
#[allow(clippy::clippy::needless_lifetimes)]
#[allow(clippy::needless_lifetimes)]
pub fn direct_access<'a>(&'a self) -> impl AsRef<[u8]> + 'a {
struct Buffer<'a>(Ref<'a, ByteBuf>);
impl<'a> AsRef<[u8]> for Buffer<'a> {
Expand All @@ -558,7 +558,7 @@ impl MemoryInstance {
///
/// [`get`]: #method.get
/// [`set`]: #method.set
#[allow(clippy::clippy::needless_lifetimes)]
#[allow(clippy::needless_lifetimes)]
pub fn direct_access_mut<'a>(&'a self) -> impl AsMut<[u8]> + 'a {
struct Buffer<'a>(RefMut<'a, ByteBuf>);
impl<'a> AsMut<[u8]> for Buffer<'a> {
Expand Down
2 changes: 2 additions & 0 deletions src/nan_preserving_float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ macro_rules! float {
}
}

// clippy suggestion would fail some tests
#[allow(clippy::cmp_owned)]
impl<T: Into<$for> + Copy> PartialEq<T> for $for {
fn eq(&self, other: &T) -> bool {
$is::from(*self) == $is::from((*other).into())
Expand Down
2 changes: 1 addition & 1 deletion src/prepare/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ impl Sink {

// Patch all relocations that was previously recorded for this
// particular label.
let unresolved_rels = mem::replace(&mut self.labels[label.0].1, Vec::new());
let unresolved_rels = mem::take(&mut self.labels[label.0].1);
for reloc in unresolved_rels {
self.ins.patch_relocation(reloc, dst_pc);
}
Expand Down
2 changes: 1 addition & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Signature {

/// Returns parameter types of this signature.
pub fn params(&self) -> &[ValueType] {
&self.params.as_ref()
self.params.as_ref()
}

/// Returns return type of this signature.
Expand Down
2 changes: 1 addition & 1 deletion tests/spec/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ fn try_spec(name: &str) -> Result<(), Error> {
for err in errors {
write!(out, "{}", err).expect("Error formatting errors");
}
panic!(out);
panic!("{}", out);
}

Ok(())
Expand Down
6 changes: 4 additions & 2 deletions validation/src/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub fn drive<T: FuncValidator>(
}

let mut context = FunctionValidationContext::new(
&module,
module,
Locals::new(params, body.locals())?,
DEFAULT_VALUE_STACK_LIMIT,
DEFAULT_FRAME_STACK_LIMIT,
Expand Down Expand Up @@ -237,6 +237,8 @@ impl<'a> FunctionValidationContext<'a> {
top.block_type
};

// Ignore clippy as pop(..) != pop(..) + push_value(..) under some conditions
#[allow(clippy::branches_sharing_code)]
if self.frame_stack.len() == 1 {
// We are about to close the last frame.

Expand Down Expand Up @@ -860,7 +862,7 @@ impl<'a> FunctionValidationContext<'a> {
&self.frame_stack,
StackValueType::Any,
)?;
if StackValueType::from(local_type) != value_type {
if local_type != value_type {
return Err(Error(format!(
"Trying to update local {} of type {:?} with value of type {:?}",
index, local_type, value_type
Expand Down
6 changes: 3 additions & 3 deletions validation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl FuncValidator for PlainFuncValidator {
pub fn validate_module<V: Validator>(module: &Module) -> Result<V::Output, Error> {
let mut context_builder = ModuleContextBuilder::new();
let mut imported_globals = Vec::new();
let mut validation = V::new(&module);
let mut validation = V::new(module);

// Copy types from module as is.
context_builder.set_types(
Expand Down Expand Up @@ -311,7 +311,7 @@ pub fn validate_module<V: Validator>(module: &Module) -> Result<V::Output, Error
.offset()
.as_ref()
.ok_or_else(|| Error("passive memory segments are not supported".into()))?;
let init_ty = expr_const_type(&offset, context.globals())?;
let init_ty = expr_const_type(offset, context.globals())?;
if init_ty != ValueType::I32 {
return Err(Error("segment offset should return I32".into()));
}
Expand All @@ -326,7 +326,7 @@ pub fn validate_module<V: Validator>(module: &Module) -> Result<V::Output, Error
.offset()
.as_ref()
.ok_or_else(|| Error("passive element segments are not supported".into()))?;
let init_ty = expr_const_type(&offset, context.globals())?;
let init_ty = expr_const_type(offset, context.globals())?;
if init_ty != ValueType::I32 {
return Err(Error("segment offset should return I32".into()));
}
Expand Down

0 comments on commit 50a2bb0

Please sign in to comment.