Skip to content

lazy_normalization_consts breaks unsize coercion in rare cases #78369

Open
@lcnr

Description

@lcnr
#![feature(lazy_normalization_consts)]
struct P<T: ?Sized>([u8; 1 + 4], T);

fn main() {
    let x: Box<P<[u8; 0]>> = Box::new(P(Default::default(), [0; 0]));
    let _: Box<P<[u8]>> = x;
}

This works on stable but fails with the following error when using lazy_normalization_consts

error[E0308]: mismatched types
 --> src/main.rs:6:27
  |
6 |     let _: Box<P<[u8]>> = x;
  |            ------------   ^ expected slice `[u8]`, found array `[u8; 0]`
  |            |
  |            expected due to this
  |
  = note: expected struct `Box<P<[u8]>>`
             found struct `Box<P<[u8; 0]>>`

For this to fail the struct has to contain a type referencing an unevaluated constant, struct P<T: ?Sized>([u8; 5], T) does work.

assigning to myself, but won't get to this right away. If you are interested in working on this before that feel free to do so.

cc @nikomatsakis @varkor

Metadata

Metadata

Assignees

Labels

A-lazy-normalizationArea: Lazy normalization (tracking issue: #60471)C-bugCategory: This is a bug.F-generic_const_exprs`#![feature(generic_const_exprs)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions