Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defmt issue when crate name starts with number #30

Open
jessetp opened this issue Aug 28, 2022 · 7 comments
Open

defmt issue when crate name starts with number #30

jessetp opened this issue Aug 28, 2022 · 7 comments
Labels
status: needs design This feature needs design work to move forward type: bug Something isn't working

Comments

@jessetp
Copy link

jessetp commented Aug 28, 2022

defmt does not work when the crate name starts with a number (e.g. 01_hello_extended.rs). I used the app template generator as suggested in the Knurling-session-20q4.

Dependencies used in Cargo.toml:

[dependencies]
nrf52840-hal = "0.15.1"
embedded-hal = "0.2.7"
cortex-m = "0.7.6"
cortex-m-rt = "0.7.1"
defmt = "0.3.2"
defmt-rtt = "0.3.2"
panic-probe = { version = "0.3.0", features = ["print-defmt"] }
nb = "1.0.0"
crc_all = "0.2.2"
@Urhengulas
Copy link
Member

Hi @jessetp, what error message are you getting?

@Urhengulas Urhengulas added status: needs design This feature needs design work to move forward type: bug Something isn't working labels Aug 29, 2022
@jessetp
Copy link
Author

jessetp commented Aug 29, 2022

error: `03_temperature` is not a valid identifier
  --> src/bin/01_temperature_03.rs:32:5
   |
32 |     defmt::info!("{=f32} °C", temperature);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the macro `defmt::info` (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile `co2-app` due to previous error

@Urhengulas
Renaming the file to start with an alphabetic character fixes the error.

@Urhengulas
Copy link
Member

Thank you. Can you please also share the whole example code?

@jessetp
Copy link
Author

jessetp commented Aug 29, 2022

@Urhengulas , I've attached the zipped project, minus the target folder (for size limits).

co2-app.zip

@Urhengulas
Copy link
Member

I am able to reproduce your issue by renaming src/bin/temperature_03.rs to src/bin/01_temperature_03.rs and running it:

$ # download and extract zip
$ cd co2-app/

$ cargo run --bin temperature_03
<this suceeds>

$ mv src/bin/temperature_03.rs src/bin/01_temperature_03.rs
$ cargo run --bin 01_temperature_03
error: `01_temperature_03` is not a valid identifier
  --> src/bin/01_temperature_03.rs:32:5
   |
32 |     defmt::info!("{=f32} °C", temperature);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the macro `defmt::info` (in Nightly builds, run with -Z macro-backtrace for more info)

I am tried to run cargo expand but this doesn't give more info atm and notably also doesn't include the expanded defmt::info call:

$ DEFMT_LOG=info cargo expand --bin 01_temperature_03
#![feature(prelude_import)]
#![no_main]
#![no_std]
#[prelude_import]
use core::prelude::rust_2018::*;
#[macro_use]
extern crate core;
#[macro_use]
extern crate compiler_builtins;
use co2_app as _;
use embedded_hal::blocking::delay::DelayMs;
use nrf52840_hal::{self as hal, Temp, Timer};
#[doc(hidden)]
#[export_name = "main"]
pub unsafe extern "C" fn __cortex_m_rt_main_trampoline() {
    __cortex_m_rt_main()
}
fn __cortex_m_rt_main() -> ! {
    let board = hal::pac::Peripherals::take().unwrap();
    let mut timer = Timer::new(board.TIMER0);
    let mut temp = Temp::new(board.TEMP);
    loop {
        let temperature: f32 = temp.measure().to_num();
        timer.delay_ms(2000_u32);
    }
}

I also tried to run it with -Z macro-backtrace as the error message suggests, but couldn't get that to run, despite running it on nightly.

Will continue later.

@Urhengulas
Copy link
Member

Urhengulas commented Sep 5, 2022

The error ...

@Urhengulas
Copy link
Member

I tried one approach to fixing this, which is just ignoring leading numbers: https://github.com/knurling-rs/defmt/tree/accept-crate-names-with-leading-numbers

It works for bin names like 123_hello.rs, 123hello.rs, but not 123.rs, which (surprising to me) is a valid bin name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs design This feature needs design work to move forward type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants