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

associated item defined inside fn unable to be found outside of fn it was defined in #18439

Closed
jhgg opened this issue Oct 30, 2024 · 1 comment
Labels
C-bug Category: bug

Comments

@jhgg
Copy link
Contributor

jhgg commented Oct 30, 2024

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

rustc version: (eg. output of rustc -V) rustc 1.81.0 (eeb90cda1 2024-09-04)

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)

repository link (if public, optional): (eg. rust-analyzer)

code snippet to reproduce:

fn main() {
    hello::world();
    // E:  ^^^^^       no such associated item
}

struct hello {}
fn hello() {
    impl hello {
        pub fn world() {}
    }

    hello::world(); // this is fine.
}

I vaguely recall this being deliberate behavior, since r-a is not descending into function definitions to find impl's for use outside of that function, but I can't find an issue for it.

This is minimized from salsa3's salsa::tracked macro expansion, which creates a struct that is named the same of the function, and defines an impl inside of it. I think salsa can probably move the impl defintion outside of the fn to make rust-analyzer work if this isn't solvable in rust-analyzer.

@jhgg jhgg added the C-bug Category: bug label Oct 30, 2024
@ChayimFriedman2
Copy link
Contributor

This is indeed deliberate, @Veykril said they have no intent of changing this behavior, and salsa should be adapted. There is also a lint (non_local_definitions) in rustc that catch this cases (salsa allows it).

@ChayimFriedman2 ChayimFriedman2 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants