rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

Fill match prioritises unimported Type over imported Type when names are the same

Open jroddev opened this issue 3 years ago • 4 comments

Diagnostics correctly shows Direction as imported - Up, Down, Left, Right This is Direction from crate::core::Direction Screenshot_20220707_192035

Code Action incorrectly fills match with bevy::ui::Direction - Inherit, LeftToRight, RightToLeft Bevy is included in this project, but not imported in this file. Screenshot_20220707_192124

  • match works correctly if bevy is not included in the project (even if installed on system)
  • match works correctly in the file that my Direction is declared

NeoVim with LSP rust-analyzer version: rust-analyzer 0.0.0 (427061da1 2022-06-19) rustc version: rustc 1.62.0 (a8314ef7d 2022-06-27)

jroddev avatar Jul 07 '22 09:07 jroddev

Can you provide the code for this, or a separate reproduction?

flodiebold avatar Jul 11 '22 09:07 flodiebold

This is the repo it occurs in for me: https://github.com/jroddev/bevy_snake I open src/food.rs in neovim with lsp+rust_analyzer add this piece of code

use crate::core::Direction;

fn use_dir(dir: &Direction) {
    match dir {
    }
}

instead of filling with create::core::Direction it fills with bevy::ui::Direction. CLion fills crate::core::Direction here as expected.

I have tried to reproduce the issue in a smaller repository but it works as expected there.

jroddev avatar Jul 16 '22 07:07 jroddev

Ah there is a use bevy::prelude::*; in this file, I imagine some part of the code is getting confused and picks the glob imported Direction over the explicit import...

Veykril avatar Jul 16 '22 08:07 Veykril

Looked into this a bit, the following is a repro:

//- minicore: derive
//- /lib.rs crate:lib deps:dep
use crate::z::Direction;

mod z {
    use dep::*;

    #[derive()]
    pub struct Direction {}
             //^^^^^^^^^
}

fn use_dir(dir: &Direction$0) {}

//- /dep.rs crate:dep
pub struct Direction {}

This goto_def test fails, the important part is the derive, remove that and it succeeds...

Veykril avatar Sep 18 '22 16:09 Veykril

Fixed by #13602

Veykril avatar Nov 11 '22 13:11 Veykril

Oh my, how could I forget to link this when it is the very issue I started with :sweat_smile:

@Veykril Thanks for catching it, and also for your reduced repro, it helped a ton!

lowr avatar Nov 11 '22 15:11 lowr