fix: Exclude impls with errors from impl enumeration#22619
Conversation
|
Not opposed to this, it sounds like the right thing to do here, but why is cfg(test) set for you in tokio which I presume is a dependency of your workspace? That asks for weird issues |
|
Yeah, this is the curse of a monorepo: we don't really know which libraries you're actively working on, so I defensively set It looks like I should modify rust-project to exclude cfg(test) on imported libraries like tokio, since our monorepo (using reindeer) doesn't actually have dev-dependencies for imported libraries so The bug was a spooky action-at-a-distance issue: adding tokio to the transitive set of dependencies causes spurious red squiggles and it took me a while to get to the bottom of it. This fix does feel appropriately defensive. I see CI is red, I'll fix that too. |
Previously, rust-analyzer would include impl methods from `impl Foo
for NoSuchType`, which would lead to rust-analyzer reporting
nonexistent type errors.
This is noticeable when depending on tokio with feature="fs" and cfg(test)
enabled. The following code would produce an invalid type error.
use std::io::Read;
fn f<T>(mut o: Option<T>) {
o.take().unwrap();
}
rust-analyzer was incorrectly resolving the `.take()` to `Read::take()`
instead of `Option::take()`.
Inside tokio, it uses mockall:mock! to create a MockFile, and then
does `impl Read for &'_ MockFile`. However, since `mockall` is a dev
dependency of tokio and we don't include dev dependencies of
dependencies, rust-analyzer just sees `impl Read for &'_ NoSuchType`.
Instead, exclude traits whose self type is error.
AI disclosure: Partially written by Codex and GPT-5.5
46ed697 to
4b20283
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
Summary: We should only set `cfg(test)` when we actually have the test dependencies, and reindeer-imported crates don't have their test-only dev-dependencies. If we set `cfg(test)` without dependencies, rust-analyzer tries to run type inference without having all the types, which can lead to issues like [this upstream issue](rust-lang/rust-analyzer#22619). Instead, only set `cfg(test)` on first party code. Reviewed By: michel-slm Differential Revision: D109321780 fbshipit-source-id: 9399e597061539d9006e8c70c4a57f0fbc4a0041
Previously, rust-analyzer would include impl methods from
impl Foo for NoSuchType, which would lead to rust-analyzer reporting nonexistent type errors.This is noticeable when depending on tokio with feature="fs" and cfg(test) enabled. The following code would produce an invalid type error.
rust-analyzer was incorrectly resolving the
.take()toRead::take()instead ofOption::take().Inside tokio, it uses
mockall:mock!to define aMockFile, and then doesimpl Read for &'_ MockFile. However, sincemockallis a dev dependency of tokio and we don't include dev dependencies of dependencies, rust-analyzer just seesimpl Read for &'_ NoSuchType.Instead, exclude traits whose self type is error.
AI disclosure: Partially written by Codex and GPT-5.5