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

Rust Analyzer passive or doesn't locate available methods and macros #19116

Open
wmstack opened this issue Feb 8, 2025 · 4 comments
Open

Rust Analyzer passive or doesn't locate available methods and macros #19116

wmstack opened this issue Feb 8, 2025 · 4 comments
Labels
A-nameres name, path and module resolution C-bug Category: bug

Comments

@wmstack
Copy link

wmstack commented Feb 8, 2025

rust-analyzer version: rust-analyzer version: 0.3.2291-standalone (f3998f7f8a 2025-02-02)

rustc version: rustc 1.84.1 (e71f9a9a9 2025-01-27)

editor or extension: Vscode Rust Analyzer rust-lang.rust-analyzer

relevant settings: Regular Programming in a Simple Crate with cargo init

code snippet to reproduce:

use core::str;


fn main() {
  str::fr
}

Expected output

Image

Actual Output

Image

Issue

Rust Analyzer refuses to look into core::str for methods even though this would be acceptable by the Rust compiler to use directly.

Related Issue

use core::str;
use std::{
  io::stdout,
  process::Command,
};

fn main() {
  let output = Command::new("ls")
    .arg("-a")
    .arg("--color")
    .output()
    .unwrap();
    
    println!("{}", str::from_utf8(output.stdout.refm^));
}
Image Image

Macros ref and refm are not visible when writing .ref. It is kind of impossible to access .ref

@wmstack wmstack added the C-bug Category: bug label Feb 8, 2025
@wmstack
Copy link
Author

wmstack commented Feb 8, 2025

@ShoyuVanilla ShoyuVanilla added the A-nameres name, path and module resolution label Feb 8, 2025
@ChayimFriedman2
Copy link
Contributor

This is not as easy. For one, str can resolve to either core::str or the builtin type str - and while we do have the ability in r-a to make it resolve to either (and in fact we resolve it correctly in analysis), here we will need to resolve it as both, and that (I imagine) will require some deep changes (although perhaps we can have some completion-specific hack).

See also #19088, although it is about resolving it after it's fully typed, which is easier.

@wmstack
Copy link
Author

wmstack commented Feb 8, 2025

Okay I am less concerned by str constructors as it seems they are going to be merged with the primitive type:
rust-lang/rust#131114

However, I am more concerned with why the .ref macro doesn't consistently show up, in a field where usually Rust Analyzer knows a reference is suitable?

Desirable Behaviour (.ref not even needed as &stdout field shows)

Image

Undesirable Behaviour 1: Rust Analyzer forgets &stdout is useful

Image

Follow Up Attempt to invoke .ref macro:

Image

The only difference is first one is direct, and the other is in a macro println! call.

@ChayimFriedman2
Copy link
Contributor

The problem with ref is that output.stdout.ref is not a valid expression (due to ref being a keyword), therefore macro expansion fails, therefore we cannot provide completions. It does complete (down the list) when you type re (or refm, as you noticed yourself). This is something we can't fix easily, but we expect to fix once the switch to new Salsa is done and its DB forking feature is implemented.

The problem with & not auto-suggested inside a macro is a different issue - can you open a new issue for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-nameres name, path and module resolution C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

3 participants