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

[[T]] is allowed in structs #25692

Closed
kornelski opened this Issue May 21, 2015 · 10 comments

Comments

Projects
None yet
@kornelski
Copy link
Contributor

kornelski commented May 21, 2015

The following construct compiles:

struct Foo {
 foo: [[u8]],
}

Even though let foo: [[u8]] doesn't. From my very limited understanding this type doesn't make sense, so it'd be nice if the compiler rejected it at the point of definition.

@abonander

This comment has been minimized.

Copy link
Contributor

abonander commented May 21, 2015

Because of [[u8]], Foo is an unsized struct, or a dynamically sized type (DST), which means it can only be bound by let behind a pointer, e.g. &Foo or Box<Foo>. It's the same with a bare [[u8]].

@Diggsey

This comment has been minimized.

Copy link
Contributor

Diggsey commented May 21, 2015

No, pornel is right, [u8] is a DST, but [[u8]] is an invalid type - you can't have a slice of DSTs because arrays/slices require that all of their elements are the same size.

@abonander

This comment has been minimized.

Copy link
Contributor

abonander commented May 21, 2015

That makes sense now. The let foo: [[u8]] part threw me off, made it sound like the problem was simpler than that. You can't bind DST to the stack.

@Manishearth

This comment has been minimized.

Copy link
Member

Manishearth commented May 22, 2015

The same goes for [str], as was brought up in irc yesterday.

These aren't types that can ever be constructed, and the compiler doesn't know how to handle them, so they should be forbidden in all places.

@Manishearth

This comment has been minimized.

Copy link
Member

Manishearth commented May 22, 2015

See also: #21748

The generic issue is that [T] should be [T] where T: Sized internally.

@eddyb

This comment has been minimized.

Copy link
Member

eddyb commented May 25, 2015

[[T]] makes perfect sense as exists N, M.[[T; N]; M], it's just not implemented - that's the main reason we should require T: Sized in [T] for now.

@brson

This comment has been minimized.

Copy link
Contributor

brson commented May 27, 2015

Nominating because rustc accepts bogus syntax.

@brson brson added the I-nominated label May 27, 2015

@nikomatsakis nikomatsakis added the T-lang label Jun 2, 2015

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Jun 3, 2015

triage: P-medium

Assigning medium priority since it's hard to construct useful programs that rely on this, as far as I know.

@TimNN

This comment has been minimized.

Copy link
Contributor

TimNN commented Apr 25, 2016

This seems to have been fixed on stable: http://is.gd/P0QUd6

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Apr 25, 2016

Yay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.