Skip to content

Reverse regression: unsized coercion from array to slice in Arc::from started compiling in 1.74.0 #120541

Closed
@BGR360

Description

@BGR360

Code

The following code compiles successfully on 1.74.0 and stable (1.75.0) (playground):

use std::sync::Arc;

fn takes_arc_slice(_: Arc<[u8]>) {}

fn no_binding() {
    takes_arc_slice(if true {
        Arc::from([255])
    } else {
        Arc::from([])
    });
}

fn with_binding() {
    let binding = if true {
        Arc::from([255])
    } else {
        Arc::from([])
    };
    takes_arc_slice(binding);
}

fn main() {
    no_binding();
    with_binding();
}

It fails to compile on 1.73.0 with the following error:

error[E0308]: `if` and `else` have incompatible types
  --> arc-slice.rs:17:9
   |
14 |       let buffers = if true {
   |  ___________________-
15 | |         Arc::from([255])
   | |         ---------------- expected because of this
16 | |     } else {
17 | |         Arc::from([])
   | |         ^^^^^^^^^^^^^ expected an array with a fixed size of 1 element, found one with 0 elements
18 | |     };
   | |_____- `if` and `else` have incompatible types
   |
   = note: expected struct `Arc<[{integer}; 1]>`
              found struct `Arc<[_; 0]>`

Only the with_binding version fails, interestingly.

This was reported in pola-rs/polars#14134. A user tried to compile the latest polars version on rustc 1.73.0 and got the above error.

Repro of the failure on godbolt.

Despite polars not having a documented MSRV, I feel that this kind of change in what is allowed to compile is non-obvious and wouldn't make the average MSRV-minded Rust developer think twice if it compiled on stable. The 1.74.0 release notes don't mention anything about a change here.

Request: at minimum, we should add a regression test to make sure this code continues to compile.

Version it worked on

The code failed to compile in 1.73.0.

Version with regression

The code started compiling in 1.74.0.

@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged +A-array +A-coercions +A-slice +A-inference +T-compiler

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-arrayArea: `[T; N]`A-coercionsArea: implicit and explicit `expr as Type` coercionsA-inferenceArea: Type inferenceA-sliceArea: `[T]`C-bugCategory: This is a bug.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions