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

"Run Doctest" lens shows up on compile_fail tests #19103

Open
PRO-2684 opened this issue Feb 6, 2025 · 2 comments
Open

"Run Doctest" lens shows up on compile_fail tests #19103

PRO-2684 opened this issue Feb 6, 2025 · 2 comments
Labels
A-ide general IDE features C-bug Category: bug

Comments

@PRO-2684
Copy link

PRO-2684 commented Feb 6, 2025

rust-analyzer version: 0.3.2291-standalone

rustc version: 1.83.0 (90b35a623 2024-11-26)

editor or extension: VSCode, r-a v0.3.2291

relevant settings: N/A

repository link (if public, optional): https://github.com/PRO-2684/rust-test/blob/36aed888c00cf79c7497ef99f93b0fdd192c4a93/src/lib.rs#L1-L12

code snippet to reproduce:

Clone the repo and navigate to src/lib.rs. You should see a "Run Doctest" button before the following code:

/// ```rust compile_fail
/// let x = 5;
/// x += 1;
/// ```
///
/// ```rust
/// let x = 5;
/// x + 1;
/// ```
pub fn add(left: u64, right: u64) -> u64 {
    left + right
}

"Run Doctest" button

Click it and see how r-a reports error in src/lib.rs:

r-a reported error

Notice that although cargo test exited successfully, the spawned shell also reported error (I'm not sure whether it is r-a's issue):

spawned shell error

@PRO-2684 PRO-2684 added the C-bug Category: bug label Feb 6, 2025
@lnicola lnicola added the A-ide general IDE features label Feb 8, 2025
@lnicola lnicola changed the title Reporting compiler errors on doctests that shouldn't compile (compile_fail) "Run Doctest" lens shows up on compile_fail tests Feb 8, 2025
@ChayimFriedman2
Copy link
Contributor

This issue arises from how VSCode defines problem matchers and the output Cargo emits. I'm not sure how we can solve this, but perhaps the Cargo team can make it not print the compiler's errors even when --show-output is used.

@PRO-2684
Copy link
Author

PRO-2684 commented Feb 11, 2025

@lnicola The edited title might not be very accurate. When there's only compile_fail tests, the "Run Doctest" lens does not show up as expected. The problem only arises when both compile_fail tests and other tests are present at the same time.

Image

https://github.com/PRO-2684/rust-test/blob/ab7caeb2a40a6207fd4ce770e8a619197b5958c2/src/lib.rs#L1-L27

But hiding "Run Doctest" if there's any compile_fail test does not seem to be a good solution - maybe we want to test other doctests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ide general IDE features C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

3 participants