rust-lang / rust-lang/rust-analyzer

rust-analyser doesn't provide suggestions/hover/types for `alloc` types with `Deref` when using a custom target

Open
#19,449 8 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-project-model A-ty C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

rust-analyzer version: rust-analyzer version: 0.4.2355-standalone (3ed13b4a91 2025-03-24) [~/.vscode/extensions/rust-lang.rust-analyzer-0.4.2355-darwin-arm64/server/rust-analyzer]

I also tested with the non pre-release version

rustc version: rustc 1.87.0-nightly (f8c27dfe1 2025-03-24)

editor or extension: VSCode, release and pre-release

relevant settings: "rust-analyzer.cargo.target": "mipsel-sony-psx.json"

repository link (if public, optional): https://github.com/matanui159/rust-analyzer-bug

code snippet to reproduce:

#![no_std]
extern crate alloc;

use core::cell::Ref;
use alloc::{rc::Rc, vec::Vec};

pub fn vec_end(vec: &Vec<i32>) -> *const i32 {
    let range = vec.as_ptr_range();
    range.end
}

pub fn get_inner(rc: &Rc<i32>) -> i32 {
    let inner = **rc;
    inner + 1
}

pub fn get_inner_borrow(borrow: &Ref<i32>) -> i32 {
    let inner = **borrow;
    inner + 1
}

The range and first inner variable have the type {unknown}. Meanwhile the second inner variable (which uses a type from core) has the correct i32 type. Additionally the as_ptr_range method was not suggested when typing and hovering does not provide any docs.

If the rust-analyser target is set to mipsel-sony-psx (without the .json, e.g. the official rust target), even with all other settings the same (still nightly with build-std) the types work again. The JSON file is a direct copy of the official target generated using:

rustc +nightly -Zunstable-options --target=mipsel-sony-psx --print=target-spec-json > mipsel-sony-psx.json

I didn't originally get this issue with this target specifically (hence why I needed a custom target) but using one of the official targets copied into a JSON ruled out any issues with the target config.

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

Start with the linked minimal reproduction and its rust-analyzer.cargo.target setting, comparing the custom mipsel-sony-psx.json target with the official mipsel-sony-psx target. Reproduce the missing suggestions, hover information, and {unknown} types for alloc::Vec, Rc, and Ref, then verify behavior against the core::cell::Ref case.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.