Stream: t-compiler/help

Topic: const-generics: coerce of `[usize; 0] -> [usize; 0]` fails


Bastian Kauschke (Apr 10 2020 at 18:32, on Zulip):
#![feature(const_generics)]

struct Const<const V: [usize; 0]> {}
type MyConst = Const<{ [] }>;

fn main() {
    let _x = Const::<{ [] }> {}; // ERROR
    let _y = MyConst {}; // ERROR
}

currently fails in coerce::try(https://github.com/rust-lang/rust/blob/dbc3cfdd25ccd56edf3ea364f86ab32967636c26/src/librustc_typeck/check/coercion.rs#L813)
for

coercion::try(
   Expr {
       hir_id: HirId { owner: DefId(0:8 ~ whooosagoodboi[317d]::main[0]), local_id: 6 },
       kind: Block(Block { stmts: [],
       expr: Some(
            Expr { hir_id: HirId { owner: DefId(0:8 ~ whooosagoodboi[317d]::main[0]), local_id: 4 }, kind: Array([]), attrs: ThinVec(None), span: //home/programming/rust/src/test/ui/__check/whooosagoodboi.rs:9:24: 9:26 }),
       hir_id: HirId { owner: DefId(0:8 ~ whooosagoodboi[317d]::main[0]), local_id: 5 }, rules: DefaultBlock, span: /home/programming/rust/src/test/ui/__check/whooosagoodboi.rs:9:22: 9:28, targeted_by_break: false }, None ),
        attrs: ThinVec(None),
        span: /home/programming/rust/src/test/ui/__check/whooosagoodboi.rs:9:22: 9:28
    }: [usize; 0] -> [usize; 0]
)

It seems to try coerce_unsized which then fails.

While I am currently looking into this myself, @eddyb @varkor do you have some ideas why this might happen?

Bastian Kauschke (Apr 10 2020 at 18:32, on Zulip):

https://github.com/rust-lang/rust/issues/68615

eddyb (Apr 10 2020 at 18:33, on Zulip):

nope, other than the types being wrong some time earlier

Bastian Kauschke (Apr 10 2020 at 18:45, on Zulip):

nevermind, it fails one call later when trying to coerce [usize; 0] -> _ for whatever reason :sweat_smile:

Bastian Kauschke (Apr 10 2020 at 19:06, on Zulip):

What is the meaning of use_lub? https://doc.rust-lang.org/nightly/nightly-rustc/rustc_typeck/check/coercion/struct.Coerce.html#structfield.use_lub

Bastian Kauschke (Apr 10 2020 at 19:07, on Zulip):

Lest upper bound i guess :shrug:

Bastian Kauschke (Apr 10 2020 at 19:10, on Zulip):

coercion has a horrible stack depth :neutral: at least when inspecting it for the first time

eddyb (Apr 10 2020 at 19:11, on Zulip):

use_lub is for when you have e.g. [x, y] and so x and y's types have to merge into a common type

eddyb (Apr 10 2020 at 19:11, on Zulip):

and Rust has subtyping

Bastian Kauschke (Apr 10 2020 at 21:13, on Zulip):

ayy! progress :laughing: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_infer/infer/combine/struct.CombineFields.html#method.instantiate returns ConstMismatch with with expected == found...

Bastian Kauschke (Apr 10 2020 at 22:13, on Zulip):

fk https://github.com/rust-lang/rust/blob/9682f0e14db95076454559a24c26287bcad57955/src/librustc_middle/ty/relate.rs#L562
the last 5 hours weren't as productive as I have hoped.

eddyb (Apr 10 2020 at 22:16, on Zulip):

lol

Bastian Kauschke (Apr 10 2020 at 22:16, on Zulip):

@eddyb Can we just compare the relevant section of the allocations here?

eddyb (Apr 10 2020 at 22:16, on Zulip):

@Bastian Kauschke maybe look at destructure_const?

eddyb (Apr 10 2020 at 22:16, on Zulip):

what are you trying to fix?

eddyb (Apr 10 2020 at 22:17, on Zulip):

0 can't be ByRef

Bastian Kauschke (Apr 10 2020 at 22:17, on Zulip):

this https://github.com/rust-lang/rust/issues/68615

Bastian Kauschke (Apr 10 2020 at 22:17, on Zulip):

[DEBUG rustc_middle::ty::relate] super_relate_tys: a=Foo<ByRef { alloc: Allocation { bytes: [], relocations: Relocations(SortedMap { data: [] }), undef_mask: UndefMask { blocks: [], len: Size { raw: 0 } }, size: Size { raw: 0 }, align: Align { pow2: 3 }, mutability: Not, extra: () }, offset: Size { raw: 0 } }: [usize; 0]> b=Foo<ByRef { alloc: Allocation { bytes: [], relocations: Relocations(SortedMap { data: [] }), undef_mask: UndefMask { blocks: [], len: Size { raw: 0 } }, size: Size { raw: 0 }, align: Align { pow2: 3 }, mutability: Not, extra: () }, offset: Size { raw: 0 } }: [usize; 0]>

eddyb (Apr 10 2020 at 22:17, on Zulip):

aaaaaaaah

Bastian Kauschke (Apr 10 2020 at 22:18, on Zulip):

named Const to Foo in this log

eddyb (Apr 10 2020 at 22:18, on Zulip):

it's an []: [usize; 0] value

eddyb (Apr 10 2020 at 22:18, on Zulip):

not a [usize; 0] type

eddyb (Apr 10 2020 at 22:18, on Zulip):

yeah okay ByRef

eddyb (Apr 10 2020 at 22:18, on Zulip):

@Bastian Kauschke check out destructure_const ;;)

eddyb (Apr 10 2020 at 22:19, on Zulip):

I have an unfinished PR to use it to print consts nicely

eddyb (Apr 10 2020 at 22:19, on Zulip):

maybe you want to wait for that? idk

Bastian Kauschke (Apr 10 2020 at 22:23, on Zulip):

maybe you want to wait for that? idk

This should be a fairly straightforward fix now afaict :thinking:
I think I will at least try this without waiting.

Good night. I am done for today :exhausted:

Last update: Sep 28 2020 at 16:30UTC