stm32-rs / stm32l0xx-hal

A hardware abstraction layer (HAL) for the STM32L0 series microcontrollers written in Rust
BSD Zero Clause License
96 stars 60 forks source link

Fix error "assigning to &T is undefined behavior" and clippy warnings #232

Closed azerupi closed 7 months ago

azerupi commented 8 months ago

Since Rust 1.73.0 there seems to be a new deny-by-default lint to catch invalid casting from references to mutable pointers.

As far as I understand the compiler is making assumptions that references are read only and passing those assumptions on to LLVM. The only way to tell the compiler to not make those assumptions is to use UnsafeCell.

So this PR is essentially wrapping those casts with UnsafeCell and getting the mutable pointer through it.

In addition to that I fixed some warnings from compiler lints and clippy lints.

jamwaffles commented 7 months ago

Gonna call this one good. Thanks for the fix, and sorry for the delay!

azerupi commented 7 months ago

No worries, thank you very much!