Skip to content

Commit

Permalink
Fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
ia0 committed Oct 29, 2024
1 parent 8d729cf commit ae6cc70
Show file tree
Hide file tree
Showing 37 changed files with 71 additions and 44 deletions.
1 change: 1 addition & 0 deletions crates/api-desc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Patch

- Fix rust and clippy lints
- Update dependencies

## 0.2.0
Expand Down
2 changes: 1 addition & 1 deletion crates/api-desc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ enum Path<'a> {
Mod { name: &'a str, prev: &'a Path<'a> },
}

impl<'a> std::fmt::Display for Path<'a> {
impl std::fmt::Display for Path<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let (name, prev) = match self {
Path::Empty => return Ok(()),
Expand Down
2 changes: 2 additions & 0 deletions crates/interpreter/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Patch

- Fix missing check when module has no data but data count
- Fix rust and clippy lints
- Update dependencies
- Return an error instead of unsupported when too many locals
- Only take the initial frame in `Thread::new()`
Expand Down
10 changes: 5 additions & 5 deletions crates/interpreter/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub struct Call<'a, 'm> {
store: &'a mut Store<'m>,
}

impl<'m> Default for Store<'m> {
impl Default for Store<'_> {
fn default() -> Self {
Self {
id: STORE_ID.next(),
Expand Down Expand Up @@ -479,7 +479,7 @@ pub enum RunAnswer {
Host,
}

impl<'a, 'm> RunResult<'a, 'm> {
impl RunResult<'_, '_> {
pub fn forget(self) -> RunAnswer {
match self {
RunResult::Done(result) => RunAnswer::Done(result),
Expand Down Expand Up @@ -646,7 +646,7 @@ impl<'a, 'm> ComputeElem<'a, 'm> {
}
}

impl<'a, 'm> parser::ParseElem<'m, Use> for ComputeElem<'a, 'm> {
impl<'m> parser::ParseElem<'m, Use> for ComputeElem<'_, 'm> {
fn mode(&mut self, mode: parser::ElemMode<'_, 'm, Use>) -> MResult<(), Use> {
let mode = match mode {
parser::ElemMode::Passive => ElemMode::Passive,
Expand Down Expand Up @@ -690,7 +690,7 @@ impl<'a, 'm> ComputeData<'a, 'm> {
}
}

impl<'a, 'm> parser::ParseData<'m, Use> for ComputeData<'a, 'm> {
impl<'m> parser::ParseData<'m, Use> for ComputeData<'_, 'm> {
fn mode(&mut self, mode: parser::DataMode<'_, 'm, Use>) -> MResult<(), Use> {
let mode = match mode {
parser::DataMode::Passive => DataMode::Passive,
Expand Down Expand Up @@ -1481,7 +1481,7 @@ trait Growable {
fn grow(&mut self, n: u32, x: Self::Item);
}

impl<'m> Growable for Memory<'m> {
impl Growable for Memory<'_> {
type Item = ();
fn size(&self) -> u32 {
self.size
Expand Down
2 changes: 1 addition & 1 deletion crates/interpreter/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct Module<'m> {
cache: Cache<CacheKey, CacheValue>,
}

impl<'m> Default for Module<'m> {
impl Default for Module<'_> {
fn default() -> Self {
Self { binary: &[], types: Vec::new(), cache: Cache::unbounded() }
}
Expand Down
4 changes: 2 additions & 2 deletions crates/interpreter/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ pub enum ElemMode<'a, 'm, M: Mode> {

pub struct SkipElem;

impl<'m, M: Mode> ParseElem<'m, M> for SkipElem {}
impl<M: Mode> ParseElem<'_, M> for SkipElem {}

pub trait ParseData<'m, M: Mode> {
// Must read an expr from the parser.
Expand All @@ -645,7 +645,7 @@ pub enum DataMode<'a, 'm, M: Mode> {

pub struct SkipData;

impl<'m, M: Mode> ParseData<'m, M> for SkipData {}
impl<M: Mode> ParseData<'_, M> for SkipData {}

impl<'m, M: Mode> Parser<'m, M> {
fn internal_new(data: &'m [u8]) -> Self {
Expand Down
6 changes: 3 additions & 3 deletions crates/interpreter/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ pub enum SectionId {
DataCount = 12,
}

impl<'m> Deref for ResultType<'m> {
impl Deref for ResultType<'_> {
type Target = [ValType];

fn deref(&self) -> &Self::Target {
Expand All @@ -382,7 +382,7 @@ impl<'m> From<&'m [ValType]> for ResultType<'m> {
}
}

impl<'m> From<ValType> for ResultType<'m> {
impl From<ValType> for ResultType<'_> {
fn from(x: ValType) -> Self {
macro_rules! make {
($($x:ident),*) => {{
Expand All @@ -401,7 +401,7 @@ impl<'m> From<ValType> for ResultType<'m> {
}
}

impl<'m> From<()> for ResultType<'m> {
impl From<()> for ResultType<'_> {
fn from(_: ()) -> Self {
Self(&[])
}
Expand Down
6 changes: 4 additions & 2 deletions crates/interpreter/src/valid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ impl<'m> Context<'m> {
parser.parse_data(&mut ParseData::new(self, &mut refs, globals_len))?;
}
check(parser.is_empty())?;
} else {
check(self.datas.map_or(true, |m| m == 0))?;
}
self.check_section(parser, SectionId::Custom)?;
check(parser.is_empty())
Expand Down Expand Up @@ -269,7 +271,7 @@ impl<'a, 'm> ParseElem<'a, 'm> {
}
}

impl<'a, 'm> parser::ParseElem<'m, Check> for ParseElem<'a, 'm> {
impl<'m> parser::ParseElem<'m, Check> for ParseElem<'_, 'm> {
fn mode(&mut self, mode: parser::ElemMode<'_, 'm, Check>) -> MResult<(), Check> {
if let parser::ElemMode::Active { table, offset } = mode {
Expr::check_const(
Expand Down Expand Up @@ -320,7 +322,7 @@ impl<'a, 'm> ParseData<'a, 'm> {
}
}

impl<'a, 'm> parser::ParseData<'m, Check> for ParseData<'a, 'm> {
impl<'m> parser::ParseData<'m, Check> for ParseData<'_, 'm> {
fn mode(&mut self, mode: parser::DataMode<'_, 'm, Check>) -> MResult<(), Check> {
if let parser::DataMode::Active { memory, offset } = mode {
self.context.mem(memory)?;
Expand Down
2 changes: 2 additions & 0 deletions crates/interpreter/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ set -e

ensure_submodule third_party/WebAssembly/spec

# TODO(cleanup): Make sure we cover all spec/test/core tests using _test_diff.

test_helper

cargo test --lib --features=toctou
Expand Down
6 changes: 3 additions & 3 deletions crates/interpreter/tests/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ fn test(repo: &str, name: &str, skip: usize) {
for directive in wast.directives {
eprintln!("{name}:{}", directive.span().offset());
match directive {
WastDirective::Wat(QuoteWat::Wat(Wat::Module(mut m))) => {
WastDirective::Module(QuoteWat::Wat(Wat::Module(mut m))) => {
env.instantiate(name, &m.encode().unwrap());
env.register_id(m.id, env.inst);
}
WastDirective::Wat(mut wat) => env.instantiate(name, &wat.encode().unwrap()),
WastDirective::Module(mut wat) => env.instantiate(name, &wat.encode().unwrap()),
WastDirective::AssertMalformed { module, .. } => assert_malformed(&mut env, module),
WastDirective::AssertInvalid { module, .. } => assert_invalid(&mut env, module),
WastDirective::AssertReturn { exec, results, .. } => {
Expand All @@ -71,7 +71,7 @@ fn pool_size(name: &str) -> usize {
"linking" => 0x1000000,
"memory_copy" => 0x400000,
"memory_fill" => 0x200000,
"memory_grow" => 0x400000,
"memory_grow" => 0x800000,
"memory_init" => 0x400000,
"memory_trap" => 0x200000,
_ => 0x100000,
Expand Down
1 change: 1 addition & 0 deletions crates/prelude/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

### Patch

- Fix rust and clippy lints
- Make sure at compile-time that at most one `native`, `test`, or `wasm` feature is enabled
- Update dependencies

Expand Down
1 change: 1 addition & 0 deletions crates/prelude/src/allocator/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ extern "C" fn init() {
struct Pool(MaybeUninit<[u8; SIZE]>);
static mut POOL: Pool = Pool(MaybeUninit::uninit());
// SAFETY: This function is called at most once and POOL is only accessed here.
#[allow(static_mut_refs)] // TODO(cleanup)
let pool_ptr = NonNull::new(unsafe { POOL.0.as_mut_ptr() }).unwrap();
let mut allocator = ALLOCATOR.0.lock();
// SAFETY: POOL is static and won't be used again.
Expand Down
4 changes: 2 additions & 2 deletions crates/prelude/src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl<'a, T: Serial> Listener<'a, T> {
}
}

impl<'a, T: Serial> Drop for Listener<'a, T> {
impl<T: Serial> Drop for Listener<'_, T> {
fn drop(&mut self) {
self.serial.unregister(self.event).unwrap();
drop(unsafe { Box::from_raw(self.notified.as_ptr()) });
Expand Down Expand Up @@ -345,7 +345,7 @@ enum Kind<'a> {
Writer { buffer: &'a [u8] },
}

impl<'a> Kind<'a> {
impl Kind<'_> {
fn event(&self) -> Event {
match self {
Kind::Reader { .. } => Event::Read,
Expand Down
1 change: 1 addition & 0 deletions crates/protocol-usb/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

### Patch

- Fix rust and clippy lints
- Fail to compile if `device` and `host` features are used together
- Update dependencies
- Remove workaround lint false positive
Expand Down
2 changes: 1 addition & 1 deletion crates/protocol-usb/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl<'a> Encoder<'a> {
}
}

impl<'a> Iterator for Encoder<'a> {
impl Iterator for Encoder<'_> {
type Item = [u8; 64];

fn next(&mut self) -> Option<[u8; 64]> {
Expand Down
2 changes: 1 addition & 1 deletion crates/protocol-usb/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl State {
}
}

impl<'a, B: UsbBus> UsbClass<B> for Rpc<'a, B> {
impl<B: UsbBus> UsbClass<B> for Rpc<'_, B> {
fn get_configuration_descriptors(
&self, writer: &mut DescriptorWriter,
) -> usb_device::Result<()> {
Expand Down
1 change: 1 addition & 0 deletions crates/protocol/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

### Patch

- Fix rust and clippy lints
- Update dependencies

## 0.1.0
Expand Down
10 changes: 6 additions & 4 deletions crates/protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,21 @@ pub enum ApiResult<'a, T: Service> {
Err(Error),
}

impl<'a> Api<'a, Request> {
#[cfg(feature = "host")]
#[cfg(feature = "host")]
impl Api<'_, Request> {
pub fn encode(&self) -> Result<Box<[u8]>, Error> {
wasefire_wire::encode(self)
}
}

#[cfg(feature = "device")]
#[cfg(feature = "device")]
impl<'a> Api<'a, Request> {
pub fn decode(data: &'a [u8]) -> Result<Self, Error> {
wasefire_wire::decode(data)
}
}

impl<'a, T: Service> ApiResult<'a, T> {
impl<T: Service> ApiResult<'_, T> {
#[cfg(feature = "device")]
pub fn encode(&self) -> Result<Box<[u8]>, Error> {
wasefire_wire::encode(self)
Expand Down
2 changes: 1 addition & 1 deletion crates/runner-nordic/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use core::ptr::addr_of_mut;

use embedded_alloc::Heap;
use embedded_alloc::TlsfHeap as Heap;

#[global_allocator]
static ALLOCATOR: Heap = Heap::empty();
Expand Down
4 changes: 2 additions & 2 deletions crates/runner-nordic/src/board/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ struct Uart<'a> {
state: &'a mut State,
}

impl<'a> Uart<'a> {
impl Uart<'_> {
fn stoptx(regs: &RegisterBlock) {
regs.tasks_stoptx.write(|w| w.tasks_stoptx().set_bit());
while regs.events_txstopped.read().events_txstopped().bit_is_clear() {}
Expand Down Expand Up @@ -326,7 +326,7 @@ fn set_high(psel_bits: u32) {
struct PrettyError<'a>(&'a errorsrc::R);

#[cfg(feature = "debug")]
impl<'a> defmt::Format for PrettyError<'a> {
impl defmt::Format for PrettyError<'_> {
fn format(&self, fmt: defmt::Formatter) {
defmt::write!(fmt, "UART error:");
if self.0.overrun().is_present() {
Expand Down
1 change: 1 addition & 0 deletions crates/runner-nordic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ fn with_state<R>(f: impl FnOnce(&mut State) -> R) -> R {

// TODO(https://github.com/rust-embedded/cortex-m/issues/537): Remove when fixed.
#[allow(unsafe_op_in_unsafe_fn)]
#[allow(static_mut_refs)]
#[entry]
fn main() -> ! {
static mut CLOCKS: MaybeUninit<Clocks> = MaybeUninit::uninit();
Expand Down
2 changes: 1 addition & 1 deletion crates/runner-nordic/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl<'a> Helper<'a> {
}
}

impl<'a> Drop for Helper<'a> {
impl Drop for Helper<'_> {
fn drop(&mut self) {
let (driver, storage) = self.nvmc.take().unwrap().free();
DRIVER.put(driver);
Expand Down
1 change: 1 addition & 0 deletions crates/scheduler/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

### Patch

- Fix rust and clippy lints
- Reduce logging level of applet trapping (those are not errors)
- Make sure at compile-time that exactly one `native` or `wasm` feature is enabled
- Use `derive-where` instead of `derivative`
Expand Down
1 change: 1 addition & 0 deletions crates/scheduler/src/applet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ impl<B: Board> Applet<B> {
self.handlers.get(&key)
}

#[cfg(feature = "wasm")]
pub fn has_handlers(&self) -> bool {
!self.handlers.is_empty()
}
Expand Down
3 changes: 2 additions & 1 deletion crates/scheduler/src/applet/store/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ pub struct Store(());
pub struct Memory;

impl StoreApi for Store {
type Memory<'a> = Memory
type Memory<'a>
= Memory
where Self: 'a;

fn memory(&mut self) -> Memory {
Expand Down
5 changes: 3 additions & 2 deletions crates/scheduler/src/applet/store/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ impl Store {
}

impl StoreApi for Store {
type Memory<'a> = Memory<'a>
type Memory<'a>
= Memory<'a>
where Self: 'a;

fn memory(&mut self) -> Memory<'_> {
Expand Down Expand Up @@ -121,7 +122,7 @@ impl<'a> Memory<'a> {
}
}

impl<'a> MemoryApi for Memory<'a> {
impl MemoryApi for Memory<'_> {
fn get(&self, ptr: u32, len: u32) -> Result<&[u8], Trap> {
let ptr = ptr as usize;
let len = len as usize;
Expand Down
Loading

0 comments on commit ae6cc70

Please sign in to comment.