Skip to content
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

type_changing_struct_update: regression in type inference #96878

Closed
Xiretza opened this issue May 9, 2022 · 0 comments · Fixed by #97705
Closed

type_changing_struct_update: regression in type inference #96878

Xiretza opened this issue May 9, 2022 · 0 comments · Fixed by #97705
Assignees
Labels
C-bug Category: This is a bug.

Comments

@Xiretza
Copy link
Contributor

Xiretza commented May 9, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
2 participants