Stream: t-lang

Topic: _ in array type


Jane Lusby (May 12 2020 at 00:25, on Zulip):

Is there any specific reason why _ isn't allowed in array types to infer the length?

Jane Lusby (May 12 2020 at 00:25, on Zulip):
let a = [1, 2, 3]; // works
let b: [u32; _] = [1, 2, 3]; // extremely surprised but this doesn't work
simulacrum (May 12 2020 at 00:28, on Zulip):

today's compiler treats it as a separate inference context, iirc, but I believe lang recently discussed this as part of the _ for array-typed consts rfc and decided that at least for lets it's a 'definitely should work' -- but I may be misrepresenting, and definitely it wasn't full attendance from lang in that meeting

Jane Lusby (May 12 2020 at 00:29, on Zulip):

okay, so presumably this doesn't need an RFC and some sort of pushing for it to eventually be added to the lang, given that other people are already talking about it

Josh Triplett (May 12 2020 at 00:30, on Zulip):

It does need some sort of push.

Josh Triplett (May 12 2020 at 00:30, on Zulip):

https://github.com/rust-lang/rfcs/pull/2545

simulacrum (May 12 2020 at 00:30, on Zulip):

I think for lets though we felt that we could likely land with a PR?

simulacrum (May 12 2020 at 00:30, on Zulip):

Maybe I'm misremembering :)

That's definitely my opinion -- I think const items are the harder question

Jane Lusby (May 12 2020 at 00:31, on Zulip):

ooh cool but the rfc is already done

Josh Triplett (May 12 2020 at 00:31, on Zulip):

Oh, let.

Josh Triplett (May 12 2020 at 00:31, on Zulip):

Yeah, it's more obvious for let, since you can already infer the entire type.

Josh Triplett (May 12 2020 at 00:31, on Zulip):

I'm more eager to have it for const, where you have to specify the type.

simulacrum (May 12 2020 at 00:33, on Zulip):

Yes -- I think consts are not a "no duh" case due to potential interaction with "global inference" and it being perhaps somewhat tough to specify exactly to what extent we avoid that (though maybe not, not sure -- seems like it could be hard but may not be). But let seems to be, IMO there's it's more so "just a bug" in some sense

lcnr (May 12 2020 at 07:51, on Zulip):

Also see https://github.com/rust-lang/rust/issues/70754 for the more general case with const generics.

scottmcm (May 13 2020 at 18:33, on Zulip):

Last this came up in a meeting I think we said that for lets in particular, this (or something very similar) is expected to happen as part of the const generics work, but that we wouldn't push for specific situations of it before then.

But thanks for the reminder, I forgot to do a follow-up from a previous design meeting about consts...

Last update: Jun 05 2020 at 23:10UTC