rust-embedded / bare-metal

Abstractions common to microcontrollers
Apache License 2.0
114 stars 16 forks source link

Beta / 2018 Edition compatibility complications #11

Closed therealprof closed 4 years ago

therealprof commented 6 years ago

I was just checking how well my crates would play with the 2018 edition and I was able to work around most quirks except for a few with the most major probably being that it seems to be impossible to share peripherals via the good old Mutex<RefCell<Option<_>>> static mechanism due to the inavailability of const_fn:

error[E0015]: calls in statics are limited to tuple structs and tuple variants
  --> examples/i2c_haldriver_printmagserial.rs:31:62
   |
31 | static MAG3110: Mutex<RefCell<Option<Mag3110<I2c<TWI1>>>>> = Mutex::new(RefCell::new(None));
   |                                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: a limited form of compile-time function evaluation is available on a nightly compiler via `const fn`
  --> examples/i2c_haldriver_printmagserial.rs:31:62
   |
31 | static MAG3110: Mutex<RefCell<Option<Mag3110<I2c<TWI1>>>>> = Mutex::new(RefCell::new(None));
   |                                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Is there any good workaround we can use here? Not being able to pass around peripherals and data safely into/out of interrupt handlers would be pretty bad, IMHO.

TeXitoi commented 5 years ago

In your Cargo.toml, you can just

bare-metal = { version = "0.2.4", features = ["const-fn"] }

It works on stable.

Maybe it should be the default now?

adamgreig commented 4 years ago

@therealprof we can close this now, right?