intellij-rust / intellij-rust

Rust plugin for the IntelliJ Platform
https://intellij-rust.github.io
MIT License
4.54k stars 381 forks source link

Build ignores problems in test modules #9790

Open wcarmon opened 1 year ago

wcarmon commented 1 year ago

Environment

Problem description

Steps to reproduce

  1. create 1 rust file with a any syntax bug in a test module (eg. referenced an non-existent identifier)
  2. IDE should show red underline to indicate the problem
  3. close that file (imagine you have hundreds of *.rs files and don't know where the issue is)
  4. run cargo build, it passes (correctly)
  5. run cargo test, it fails (correctly)
  6. use rust plugin to build (CTRL+F9), it passes (somewhat correctly, but not helpful)
  7. Open Problems view, no errors appear

Is there a way to get "build" to show problems in test modules?

mchernyavsky commented 1 year ago

What command (highlighted line) does the plugin show when performing a build in your case?

Screenshot 2022-11-24 at 04 40 05
wcarmon commented 1 year ago

Here's an MWE:

in main.rs

mod erase;

fn main() {
    println!("hi");
}

in erase.rs (same directory as main.rs)

struct A {}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn foo() {
        nothing; // <-- this is not defined anywhere, so fails on cargo test, but succeeds on cargo build
    }
}

Console output after CTRL+F9:

/home/wcarmon/.cargo/bin/cargo build --message-format=json-diagnostic-rendered-ansi --color=always --bin my-project --manifest-path /path/to/my-project/Cargo.toml
   Compiling my-project v0.0.1 (/path/to/my-project)
    Finished dev [unoptimized + debuginfo] target(s) in 0.51s
Process finished with exit code 0

it looks like your build command runs cargo build with --all and --all-targets. How do I get that behavior for CTRL+F9?

wcarmon commented 1 year ago

settings-1