Stream: t-compiler/rust-analyzer

Topic: problem with criterion

Eh2406 (Oct 21 2020 at 15:34, on Zulip):

I am switching from std benchmarking to criterion, and rust analyzer is freaking out and marking everything with a red underline

    "resource": "/c:/Users/finkelman/Documents/MyProjects/pubgrub-rs/benches/",
    "owner": "rustc",
    "code": "E0601",
    "severity": 8,
    "message": "`main` function not found in crate `large_case`\nconsider adding a `main` function to `benches\\`",
    "source": "rustc",
    "startLineNumber": 2,
    "startColumn": 1,
    "endLineNumber": 39,
    "endColumn": 26

main is provided by criterion_main

Eh2406 (Oct 21 2020 at 15:34, on Zulip):

Is this a known issue?

Laurențiu (Oct 21 2020 at 15:40, on Zulip):

I think it works for me:


Eh2406 (Oct 21 2020 at 15:42, on Zulip):

Hmmm... that is odd.

Eh2406 (Oct 21 2020 at 15:43, on Zulip):

Got it! My benchmarks use serde which is an optional feature. So I added #![cfg(feature = "serde")]
That is what triggers it

Laurențiu (Oct 21 2020 at 15:45, on Zulip):

Does putting that on the criterion_group! work?

Laurențiu (Oct 21 2020 at 15:46, on Zulip):

Because it's certainly missing main if you put it on the whole file and the feature is disabled

Eh2406 (Oct 21 2020 at 15:46, on Zulip):

Right makes sense.

Eh2406 (Oct 21 2020 at 15:48, on Zulip):
#[cfg(not(feature = "serde"))]
fn main() {
    eprintln!("please run benmarks with --all-features")

Thanks for the help!

Laurențiu (Oct 21 2020 at 15:48, on Zulip):

You can also put the feature in rust-analyzer.cargo.features

Eh2406 (Oct 21 2020 at 15:50, on Zulip):

this way a new contributor that runs cargo bench will get a helpful error message.

matklad (Oct 21 2020 at 18:29, on Zulip):

@Eh2406 isn't this the job for required-features feature of Cargo?

Eh2406 (Oct 21 2020 at 18:31, on Zulip):

Grate point!

Last update: Jul 24 2021 at 21:30UTC