rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.21k stars 1.6k forks source link

type-mismatch false positive on unsizing coercion #13864

Open jDomantas opened 1 year ago

jDomantas commented 1 year ago

rust-analyzer version: rust-analyzer version: 0.3.1334-standalone (74ae2dd30 2022-12-25)

rustc version: rustc 1.66.0 (69f9c33d7 2022-12-12)

relevant settings: in vscode's settings.json: "rust-analyzer.diagnostics.experimental.enable": true, "rust-analyzer.checkOnSave.enable": false (to opt-in into type checking diagnostics)

This code:

struct Foo<T: ?Sized> {
    leading: u32,
    trailing: T,
}

fn unsize(x: Box<Foo<[u32; 4]>>) -> Box<Foo<[u32]>> {
    x
}

compiles fine with rustc, but vscode shows type error from rust-analyzer:

image

lowr commented 1 year ago

The cause of this bug boils down to this FIXME. #13112 implements it and would resolve this, but it's blocked on another issue.