esp-rs / rust

Rust for the xtensa architecture. Built in targets for the ESP32 and ESP8266
https://www.rust-lang.org
Other
743 stars 39 forks source link

Clippy error in test_result.rs #244

Closed cs-clarence closed 2 weeks ago

cs-clarence commented 2 weeks ago

Reopening for https://github.com/esp-rs/rust/issues/231

Min repro: https://github.com/cs-clarence/esp-rs-min-repro

MCU: esp32s3 Rust Version: 1.82 Edition: 2021

Steps to reproduce:

  1. Generate a project cargo generate esp-rs/esp-idf-template cargo
  2. Create a lib.rs in src folder
  3. Restart rust analyzer

image

found a related PR for this https://github.com/esp-rs/rust/pull/232

cc @MabezDev

ivmarkov commented 2 weeks ago

@cs-clarence

The TL;DR is that if you wait a couple of weeks or a month (and update to latest Rust nightly and/or esp toolchain), the problem might likely resolve itself because of this and then you won't need the harness = false workaround anymore.

Elaboration: The problem is very deep actually. Here's the context:

Now, what can we do? Maybe a short-term solution and a log-term solution:

cs-clarence commented 2 weeks ago

@ivmarkov thanks for the in-depth reply to this. I don't really get the harness = false workaround. The minimal reproduction is generated from the template esp-rs/esp-idf-template which already has the harness = false set. When the file is only main.rs the program compiles fine, however once I create the lib.rs it triggers the clippy error. Initially I thought that it might be my installation is broken but after seeing the github action here https://github.com/cs-clarence/esp-rs-min-repro/actions/runs/11762240597/job/32764909696 I'm convinced that the issue is not just because of my development setup.

ivmarkov commented 2 weeks ago

@ivmarkov thanks for the in-depth reply to this. I don't really get the harness = false workaround. The minimal reproduction is generated from the template esp-rs/esp-idf-template which already has the harness = false set. When the file is only main.rs the program compiles fine, however once I create the lib.rs it triggers the clippy error.

esp-idf-template's harness = false only applies the workaround for binary crates, as that's what esp-idf-template generates. The moment you put a lib.rs in your crate, you are in fact creating a mixed crate that is simultaneously a binary one and a library one. So you need to then also add to Cargo.toml:

[lib]
harness = false
cs-clarence commented 2 weeks ago

@ivmarkov thanks for the in-depth reply to this. I don't really get the harness = false workaround. The minimal reproduction is generated from the template esp-rs/esp-idf-template which already has the harness = false set. When the file is only main.rs the program compiles fine, however once I create the lib.rs it triggers the clippy error.

esp-idf-template's harness = false only applies the workaround for binary crates, as that's what esp-idf-template generates. The moment you put a lib.rs in your crate, you are in fact creating a mixed crate that is simultaneously a binary one and a library one. So you need to then also add to Cargo.toml:

[lib]
harness = false

Ah I see. I didn't know this one. That fixed it. image

Thanks. I'll be closing this now