Skip to content

Incorrect inferred type when first used as a pointer #15246

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

Closed
xxshady opened this issue Jul 9, 2023 · 0 comments · Fixed by #15271
Closed

Incorrect inferred type when first used as a pointer #15246

xxshady opened this issue Jul 9, 2023 · 0 comments · Fixed by #15271
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug

Comments

@xxshady
Copy link

xxshady commented Jul 9, 2023

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) {}
@xxshady xxshady added the C-bug Category: bug label Jul 9, 2023
@HKalbasi HKalbasi added the A-ty type system / type inference / traits / method resolution label Jul 9, 2023
@bors bors closed this as completed in 037844c Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants