Skip to content

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

@matanui159

Description

@matanui159

rust-analyzer version: rust-analyzer version: 0.4.2355-standalone (3ed13b4 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-project-modelproject model and workspace related issuesA-tytype system / type inference / traits / method resolutionC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions