Skip to content

FP type mismatch on DSTs  #16293

@matthiaskrgr

Description

@matthiaskrgr
// from src/tools/miri/tests/pass/issues/issue-23261.rs
// Matching on a DST struct should not trigger an LLVM assertion.

struct Foo<T: ?Sized> {
    a: i32,
    inner: T,
}

trait Get {
    fn get(&self) -> i32;
}

impl Get for i32 {
    fn get(&self) -> i32 {
        *self
    }
}

fn main() {
    // boom
    let foo: &Foo<[u8]> = &Foo { a: 32, inner: [1, 2, 3] };
    // boom
    let foo: &Foo<dyn Get> = &Foo { a: 32, inner: 32 };
}

edition 2015

ra reports a type mismatch here which rustc doesnt:

 rust-analyzer diagnostics  .
processing crate: bar, module: /tmp/bar/src/main.rs
Diagnostic { code: RustcHardError("E0308"), message: "expected &Foo<[u8]>, found &Foo<[i32; 3]>", range: FileRange { file_id: FileId(11), range: 336..368 }, severity: Error, unused: false, experimental: true, fixes: None, main_node: None }
Diagnostic { code: RustcHardError("E0308"), message: "expected &Foo<dyn Get>, found &Foo<i32>", range: FileRange { file_id: FileId(11), range: 411..436 }, severity: Error, unused: false, experimental: true, fixes: None, main_node: None }

diagnostic scan complete

Error: diagnostic error detected

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