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

fully qualified call required to determine trait method type #12247

Closed
jimblandy opened this issue May 13, 2022 · 3 comments · Fixed by #14750
Closed

fully qualified call required to determine trait method type #12247

jimblandy opened this issue May 13, 2022 · 3 comments · Fixed by #14750
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug

Comments

@jimblandy
Copy link

Sometimes rust-analyzer cannot determine the type returned by calling a trait method, unless fully qualified call syntax is used. It may be that it cannot even determine which method is being called.

The branch https://github.com/jimblandy/wgpu/tree/placate-rust-analyzer shows an example: without the change in jimblandy/wgpu@7746829, rust-analyzer cannot determine the type of cmd_buf. Switching to fully-qualified syntax and providing some trait type parameters allows rust-analyzer to see that cmd_buf should have type &mut CommandBuffer<A>.

Here's the change:

modified   wgpu-core/src/command/compute.rs
@@ -309,8 +309,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
         let (device_guard, mut token) = hub.devices.read(&mut token);
 
         let (mut cmd_buf_guard, mut token) = hub.command_buffers.write(&mut token);
-        let cmd_buf = CommandBuffer::get_encoder_mut(&mut *cmd_buf_guard, encoder_id)
-            .map_pass_err(init_scope)?;
+        let result = CommandBuffer::get_encoder_mut(&mut *cmd_buf_guard, encoder_id);
+        // Call using fully qualified syntax, to placate rust-analyzer.
+        let cmd_buf = MapPassErr::<&mut CommandBuffer<A>, _>::map_pass_err(result, init_scope)?;
         // will be reset to true if recording is done without errors
         cmd_buf.status = CommandEncoderStatus::Error;
         let raw = cmd_buf.encoder.open();
@flodiebold flodiebold added A-ty type system / type inference / traits / method resolution C-bug Category: bug labels May 13, 2022
@jimblandy
Copy link
Author

Here's another fix that works:

modified   wgpu-core/src/command/compute.rs
@@ -309,7 +309,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
         let (device_guard, mut token) = hub.devices.read(&mut token);
 
         let (mut cmd_buf_guard, mut token) = hub.command_buffers.write(&mut token);
-        let cmd_buf = CommandBuffer::get_encoder_mut(&mut *cmd_buf_guard, encoder_id)
+        // Spell out the type, to placate rust-analyzer.
+        // https://github.com/rust-lang/rust-analyzer/issues/12247
+        let cmd_buf: &mut CommandBuffer<A> = CommandBuffer::get_encoder_mut(&mut *cmd_buf_guard, encoder_id)
             .map_pass_err(init_scope)?;
         // will be reset to true if recording is done without errors
         cmd_buf.status = CommandEncoderStatus::Error;

@jimblandy
Copy link
Author

In case GitHub doesn't keep that other commit around, here's a commit that made it to master where, before the commit, rust-analyzer can't determine cmd_buf's type, but after the commit, it can:

gfx-rs/wgpu@284ed46

jimblandy added a commit to jimblandy/wgpu that referenced this issue Jun 14, 2022
jimblandy added a commit to jimblandy/wgpu that referenced this issue Jun 14, 2022
cwfitzgerald pushed a commit to gfx-rs/wgpu that referenced this issue Jun 15, 2022
bitgaoshu added a commit to bitgaoshu/rust-analyzer that referenced this issue Dec 10, 2022
bitgaoshu added a commit to bitgaoshu/rust-analyzer that referenced this issue Dec 10, 2022
bitgaoshu added a commit to bitgaoshu/rust-analyzer that referenced this issue Jan 28, 2023
bitgaoshu added a commit to bitgaoshu/rust-analyzer that referenced this issue Feb 4, 2023
@HKalbasi
Copy link
Member

HKalbasi commented May 4, 2023

I believe this will be fixed once #14279 becomes fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants