diff --git a/.gitignore b/.gitignore index 0474e94..7e74eb7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +# Rust artifacts +target Cargo.lock # IDE metadate diff --git a/crates/macro/src/lib.rs b/crates/macro/src/lib.rs index ff09c9f..3e7959e 100644 --- a/crates/macro/src/lib.rs +++ b/crates/macro/src/lib.rs @@ -85,9 +85,9 @@ unused_unsafe, unreachable_patterns )] +#![warn(rust_2018_idioms)] #![recursion_limit = "128"] -extern crate proc_macro; mod macro_attr_parser; mod macro_input_parser; diff --git a/crates/macro/src/macro_attr_parser.rs b/crates/macro/src/macro_attr_parser.rs index a4f10e7..65377b6 100644 --- a/crates/macro/src/macro_attr_parser.rs +++ b/crates/macro/src/macro_attr_parser.rs @@ -28,7 +28,7 @@ pub enum HandlerAttr { } impl HandlerAttrs { - pub fn init_fn_name(&self) -> Option<(&str)> { + pub fn init_fn_name(&self) -> Option<&str> { self.handler_attrs .iter() .filter_map(|attr| match attr { @@ -38,7 +38,7 @@ impl HandlerAttrs { .next() } - pub fn side_modules(&self) -> Option<(&Vec)> { + pub fn side_modules(&self) -> Option<&Vec> { self.handler_attrs .iter() .filter_map(|attr| match attr { @@ -58,7 +58,7 @@ impl Default for HandlerAttrs { } impl Parse for HandlerAttrs { - fn parse(input: ParseStream) -> syn::Result { + fn parse(input: ParseStream<'_>) -> syn::Result { let mut attrs = HandlerAttrs::default(); if input.is_empty() { return Ok(attrs); @@ -73,7 +73,7 @@ impl Parse for HandlerAttrs { } impl Parse for HandlerAttr { - fn parse(input: ParseStream) -> syn::Result { + fn parse(input: ParseStream<'_>) -> syn::Result { // trying to parse the `init_fn`/`side_modules`/... tokens let attr_name = input.step(|cursor| match cursor.ident() { Some((ident, rem)) => Ok((ident, rem)), diff --git a/crates/main/Cargo.toml b/crates/main/Cargo.toml index 8a8a1b7..f42b392 100644 --- a/crates/main/Cargo.toml +++ b/crates/main/Cargo.toml @@ -19,12 +19,12 @@ path = "src/lib.rs" crate-type = ["rlib"] [dependencies] -log = { version = "0.4", features = ["std"] } -syn = { version = '0.15.0', features = ['full'] } +log = { version = "0.4.8", features = ["std"] } +syn = { version = '0.15.44', features = ['full'] } [dev-dependencies] -simple_logger = "1.0" # used in doc test -lazy_static = "1.3.0" # used in doc test +simple_logger = "1.6.0" # used in doc test +lazy_static = "1.4.0" # used in doc test [features] # Turn on the Wasm logger. diff --git a/crates/main/src/lib.rs b/crates/main/src/lib.rs index ce70243..e867342 100644 --- a/crates/main/src/lib.rs +++ b/crates/main/src/lib.rs @@ -29,8 +29,7 @@ unused_unsafe, unreachable_patterns )] - -extern crate core; +#![warn(rust_2018_idioms)] pub mod memory; diff --git a/crates/main/src/memory/errors.rs b/crates/main/src/memory/errors.rs index 6fa88b2..f04d51f 100644 --- a/crates/main/src/memory/errors.rs +++ b/crates/main/src/memory/errors.rs @@ -26,7 +26,7 @@ use std::io; pub struct MemError(String); impl Display for MemError { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { write!(f, "MemError({:?})", self) } } diff --git a/crates/main/src/memory/mod.rs b/crates/main/src/memory/mod.rs index 5e2ea06..de56509 100644 --- a/crates/main/src/memory/mod.rs +++ b/crates/main/src/memory/mod.rs @@ -21,7 +21,7 @@ pub mod errors; use self::errors::MemError; -use std::alloc::{Alloc, Global, Layout}; +use std::alloc::{alloc as global_alloc, dealloc as global_dealloc, Layout}; use std::mem; use std::num::NonZeroUsize; use std::ptr::{self, NonNull}; @@ -43,7 +43,7 @@ pub const RESPONSE_SIZE_BYTES: usize = 4; /// pub unsafe fn alloc(size: NonZeroUsize) -> MemResult> { let layout: Layout = Layout::from_size_align(size.get(), mem::align_of::())?; - Global.alloc(layout).map_err(Into::into) + Ok(NonNull::new_unchecked(global_alloc(layout))) } /// Deallocates memory area for current memory pointer and size. Actually is just a wrapper for @@ -57,7 +57,7 @@ pub unsafe fn alloc(size: NonZeroUsize) -> MemResult> { /// pub unsafe fn dealloc(ptr: NonNull, size: NonZeroUsize) -> MemResult<()> { let layout = Layout::from_size_align(size.get(), mem::align_of::())?; - Global.dealloc(ptr, layout); + global_dealloc(ptr.as_ptr(), layout); Ok(()) } diff --git a/src/lib.rs b/src/lib.rs index 494b302..49de066 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,6 +33,7 @@ unused_unsafe, unreachable_patterns )] +#![warn(rust_2018_idioms)] extern crate fluence_sdk_macro; extern crate fluence_sdk_main;