Skip to content

type-mismatch when struct is defined in block expression #14443

Closed
@jhgg

Description

@jhgg

minimization:

trait T {}

fn dyn_t(d: &dyn T) {}

fn main() {
    struct A;
    impl T for A {}

    let a = A;

    let b = {
        struct B;
        impl T for B {}

        B
    };

    dyn_t(&a);
    dyn_t(&b);
    //    ^^ type-mismatch: expected &dyn T, found &B
}

this is minimized from code that prost generates: https://github.com/tokio-rs/prost/blob/34d0e2b309a1c8fa33871ccd8404573dc3b81b15/prost-derive/src/field/scalar.rs#L220 -> https://github.com/tokio-rs/prost/blob/34d0e2b309a1c8fa33871ccd8404573dc3b81b15/prost-derive/src/field/mod.rs#L149

rust-analyzer version: 0.4.1453-standalone
rustc version: rustc 1.66.1 (90743e729 2023-01-10)

Metadata

Metadata

Assignees

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