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
Closed

[[T]] is allowed in structs #25692

kornelski opened this issue May 21, 2015 · 10 comments
Labels
A-dst Area: Dynamically Sized Types P-medium Medium priority T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@kornelski
Copy link
Contributor

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
Copy link
Contributor

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
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
Copy link
Contributor

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.

@Aatch Aatch added A-dst Area: Dynamically Sized Types I-wrong labels May 22, 2015
@Manishearth
Copy link
Member

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
Copy link
Member

See also: #21748

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

@eddyb
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
Copy link
Contributor

brson commented May 27, 2015

Nominating because rustc accepts bogus syntax.

@nikomatsakis nikomatsakis added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Jun 2, 2015
@nikomatsakis
Copy link
Contributor

triage: P-medium

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

@TimNN
Copy link
Contributor

TimNN commented Apr 25, 2016

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

@alexcrichton
Copy link
Member

Yay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-dst Area: Dynamically Sized Types P-medium Medium priority T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.