Skip to content

type_changing_struct_update: regression in type inference #96878

Closed
@Xiretza

Description

@Xiretza

I tried this code:

#![feature(type_changing_struct_update)]

#[derive(Default)]
struct NonGeneric {
    field1: usize,
}

#[derive(Default)]
struct Generic<T, U> {
    field1: T,
    field2: U,
}

fn main() {
    let default = NonGeneric {
        ..Default::default()
    };
    let default: Generic<i32, f32> = Generic {
        ..Default::default()
    };
}

I expected to see this happen: Compilation succeeds, the two variables are assigned their default values.

Instead, this happened:

error[E0308]: mismatched types
  --> src/main.rs:16:11
   |
16 |         ..Default::default()
   |           ^^^^^^^^^^^^^^^^^^ expected struct `NonGeneric`, found inferred type
   |
   = note: expected struct `NonGeneric`
                found type `_`

error[E0308]: mismatched types
  --> src/main.rs:19:11
   |
19 |         ..Default::default()
   |           ^^^^^^^^^^^^^^^^^^ expected struct `Generic`, found inferred type
   |
   = note: expected struct `Generic<i32, f32>`
                found type `_`

Meta

rustc --version --verbose:

rustc 1.62.0-nightly (cb1219871 2022-05-08)
binary: rustc
commit-hash: cb121987158d69bb894ba1bcc21dc45d1e0a488f
commit-date: 2022-05-08
host: x86_64-unknown-linux-gnu
release: 1.62.0-nightly
LLVM version: 14.0.1

This was originally reported in #86618 (comment).
cc #86555

Metadata

Metadata

Labels

C-bugCategory: This is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions