rust-analyzer: Methods provided via Deref are not being found

rust-analyzer version: (eg. output of “rust-analyzer: Show RA Version” command, accessible in VSCode via <kbd>Ctrl/⌘</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd>)

rustc version: rust-analyzer version: 0.4.1202-standalone rustc 1.65.0-nightly (350cca3b6 2022-08-30)

relevant settings: VSCode remote, with a very large project (1000s of crates), no extra env settings for CHALK

Methods from OtherType that are defined for a type (ThisType) via implementing Deref<Target=OtherType> are not being found as valid symbols, and flagged as unresolvedReference.

Using the following struct:

struct Wrapper(pub String);

impl std::ops::Deref for Wrapper {
    type Target = str;

    fn deref(&self) -> &Self::Target {
        self.0.as_str()
    }
}

The following do not resolve .chars(): Screen Shot 2022-09-15 at 5 02 03 PM

But the following do resolve chars() correctly: Screen Shot 2022-09-15 at 5 02 11 PM

Full source (and proof that these work) at: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=d5c1d59fa47c1228df2be80042ec41a1

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 21 (17 by maintainers)

Most upvoted comments

I’ve got a PR up for our rust-project.json generation, which removes the explicit addition of the sysroot crates, and lets rust-analyzer infer it from the sysroot field.