rust-lang / rust-lang/rust-analyzer

Feature Request: Completion for class function that is not inherent method

Open
#18,584 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-completion C-feature
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

According to Rust API guidelines,

Smart pointers do not add inherent methods (C-SMART-PTR)

Therefore, smart pointer structs, such as Box, Arc
have many class function that is not method,
and the first parameter is the type itself
such as Box::into_raw, Arc::into_inner

pub fn into_raw(b: Box<T, A>) -> *mut T

pub fn into_inner(this: Arc<T, A>) -> Option<T>

Is it possible to add these functions to completion, when I press the period character after the object variable?
The functions can be limited to the function whose first parameter is Self, &Self, &mut Self
For example

let foo = Arc::new(1);
let bar = foo.

Is it possible to show Arc::into_inner in the completion list?
When the completion is accepted, the code is automatically rewritten to

let foo = Arc::new(1);
let bar = Arc::into_inner(foo);

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source files or tests are named. Start by locating the completion entry point for a period after an expression, then trace how associated functions and their first parameter types are represented. Done means eligible functions using Self, &Self, or &mut Self appear for smart pointers and acceptance rewrites the call to the associated-function form.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.