rust-lang / rust-lang/rust-analyzer

`mismatched-arg-count` false positive in example with `required-features`

Open
#13,416 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-nameres C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

rust-analyzer version: 0.3.1238-standalone (61504c8d9 2022-10-08)

rustc version: 1.64.0 (a55dd71d5 2022-09-19)

I'm getting an error in the example for the following crate, even though it runs fine:

Cargo.toml

[package]
name = "bevy_test" # Not actually Bevy-related
version = "0.1.0"
edition = "2021"

[features]
feature = []

[[example]]
name = "example"
required-features = [ "feature" ]

src/lib.rs

#[derive(Default)]
pub struct Struct<T>(T);

impl Struct<Type1> {
    pub fn do_stuff(&self) {}
}

#[cfg(feature = "feature")]
impl Struct<Type2> {
    pub fn do_stuff(&self, _: i32) {}
}

#[derive(Default)]
pub struct Type1;

#[cfg(feature = "feature")]
#[derive(Default)]
pub struct Type2;

examples/example.rs (run with cargo run --example example --features feature)

use bevy_test::{Struct, Type2};

fn main() {
    Struct::<Type2>::default().do_stuff(0); // expected 0 arguments, found 1 rust-analyzer(mismatched-arg-count)
}

Thank you!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the diagnostic with the provided Cargo.toml, src/lib.rs, and examples/example.rs using cargo run --example example --features feature. Then trace how rust-analyzer handles required-features and conditional implementations; done means the valid call no longer reports mismatched-arg-count under the enabled feature.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.