rust-embedded / svd2rust

Generate Rust register maps (`struct`s) from SVD files
Apache License 2.0
675 stars 147 forks source link

Remove ref in ArrayElemAccessor to solve the `needless_borrow` warning #772

Closed duskmoon314 closed 7 months ago

duskmoon314 commented 7 months ago

TLDR: This PR contains 1 commit:

  1. remove ref (&) in ArrayElemAccessor to solve the needless_borrow warning

Currently, the generated code contains two parts:

  1. RawArrayAccessor takes an argument n and returns ref
  2. ArrayElemAccessor wraps RawArrayAccessor
// An example of generated code
#[doc = "0x58..0x74 - EMAC MAC Address High Register"]
#[inline(always)]
pub const fn emac_addr_high(&self, n: usize) -> &EMAC_ADDR_HIGH {
    #[allow(clippy::no_effect)]
    [(); 7][n];
    unsafe { &*(self as *const Self).cast::<u8>().add(88).add(8 * n).cast() }
}
#[doc = "0x58 - EMAC MAC Address High Register"]
#[inline(always)]
pub const fn emac_addr_high1(&self) -> &EMAC_ADDR_HIGH {
    &self.emac_addr_high(0)
}

It is needless to use & in emac_addr_high1.

Consideration

I haven't checked whether there is another situation that ArrayElemAccessor needs &. If so, this PR can be adjusted to ignore clippy warning.

burrbull commented 7 months ago

What version of cargo fmt do you use? Stable one with default configuration, please.

duskmoon314 commented 7 months ago

What version of rustfmt do you use? Stable one, please.

I'm checking.

duskmoon314 commented 7 months ago

Sorry, I used nightly by mistake. I'm fixing now.