Skip to content

Incorrect inferred type when first used as a pointer #15246

Closed
@xxshady

Description

@xxshady

rust-analyzer version: 0.4.1581-standalone (fdb8aa2 2023-07-08)

rustc version: 1.70.0 (same on 1.69.0)

изображение

Reproduction code

fn main() {
    // should be [bool; 1]
    let mut static_array = Default::default();

    // `std::any::type_name_of_val` is not stable yet
    fn value_type_name<T>(_v: T) -> &'static str {
        std::any::type_name::<T>()
    }

    // rust compiler is right here
    dbg!(value_type_name(static_array)); // [bool; 1]

    // this call breaks inference of the type
    expects_static_array_ptr(&mut static_array as *mut _);

    expects_static_array(static_array);
}

fn expects_static_array(_static_array: [bool; 1]) {}

fn expects_static_array_ptr(_static_array_ptr: *mut bool) {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-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