rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.37k stars 1.62k forks source link

function import get replaced by a module import #18347

Open wiiznokes opened 1 month ago

wiiznokes commented 1 month ago

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

0.3.2146-standalone

rustc version: (eg. output of rustc -V)

rustc 1.84.0-nightly (3ed6e3cc6 2024-10-17)

editor or extension: (eg. VSCode, Vim, Emacs, etc. For VSCode users, specify your extension version; for users of other editors, provide the distribution if applicable)

VSCode

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME)

code snippet to reproduce:

#[doc(inline)]
pub use tooltip::{tooltip, Tooltip};
pub mod tooltip {
    use crate::Element;
    use std::borrow::Cow;

    pub use iced::widget::tooltip::Position;

    pub type Tooltip<'a, Message> =
        iced::widget::Tooltip<'a, Message, crate::Theme, crate::Renderer>;

    pub fn tooltip<'a, Message>(
        content: impl Into<Element<'a, Message>>,
        tooltip: impl Into<Element<'a, Message>>,
        position: Position,
    ) -> Tooltip<'a, Message> {
        let xxs = crate::theme::active().cosmic().space_xxs();

        Tooltip::new(content, tooltip, position)
            .class(crate::theme::Container::Tooltip)
            .padding(xxs)
            .gap(1)
    }
}

This code is from libcosmic.

My current import is:

use cosmic::{
    iced::{Color, Length},
    iced_widget::{pick_list, toggler},
    prelude::CollectionWidget,
    widget::{
        button, column, container, dropdown, horizontal_space, row,
        segmented_button::Entity, settings::section, text, text_input, tooltip, tooltip::Position,
        Row,
    },
    Element,
};

When I import stmg from libcosmic, let's say mouse_arena, this is what imported:

use cosmic::{
    iced::{Color, Length},
    iced_widget::{pick_list, toggler},
    prelude::CollectionWidget,
    widget::{
        button, column, container, dropdown, horizontal_space, mouse_area, row, segmented_button::Entity, settings::section, text, text_input, tooltip::{self, Position}, Row
    },
    Element,
};

Notice the tooltip::{self, Position}. This cause this error: error[E0423]: expected function, found moduletooltip``

rwakulszowa commented 1 month ago

I can take a look at this. @rustbot claim

rwakulszowa commented 1 month ago

A simpler repro

  1. Start with this

    // main.rs
    use lsp_test::foo;
    
    fn main() {
      println!("{:}", foo());
    }
    // lib.rs
    pub fn foo() -> u32 {
      44
    }
    
    pub mod foo {
      pub fn bar() -> u32 {
          88
      }
    }

    Compiles and works fine.

  2. Call bar in main.

    // main.rs
    use lsp_test::foo::{self, bar};  // auto imported
    
    fn main() {
      println!("{:} {:}", foo(), bar());
    }

    // expected function, found module foo