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

Reevaluate syntax for fixed-length vector types #9879

Closed
brson opened this issue Oct 15, 2013 · 16 comments
Closed

Reevaluate syntax for fixed-length vector types #9879

brson opened this issue Oct 15, 2013 · 16 comments
Labels
A-grammar Area: The grammar of Rust
Milestone

Comments

@brson
Copy link
Contributor

brson commented Oct 15, 2013

let foo: [int, .. N]? As a type name it's pretty unsightly. Some would like to go back to the drawing board here.

@brson
Copy link
Contributor Author

brson commented Oct 15, 2013

Nominating.

@kud1ing
Copy link

kud1ing commented Oct 16, 2013

Maybe something like let foo: [int]{N}: first the list declaration [int] and than an additional length constraint in some form.

@jdm
Copy link
Contributor

jdm commented Oct 16, 2013

Perhaps let foo: [int:N]?

@huonw
Copy link
Member

huonw commented Oct 16, 2013

Do we want this to match the repeat syntax? I could imagine both

let x = [10u]{128};
let x = [10u: 128];

have problems; the first one would make something like let x = [1 + 2 + 3 + ... + n]{100}; require arbitrary look-ahead to work out if it is a vector of length 1 or a repeat expression (edit: although I guess we already have this with [1 + 2 + ... + n, .. 100]; but this syntax makes the error for forgetting the ; in let x = [0]; { /* scope */ } weird, and it also makes if x == [0] { ... } impossible). The last one conflicts with the proposed use of : for type-ascription.

@nikomatsakis
Copy link
Contributor

the first one would make something like let x = [1 + 2 + 3 + ... + n]{100}; require arbitrary look-ahead to work out if it is a vector
of length 1 or a repeat expression.

Not to endorse [10u]{128} as a possible syntax, but it does not
require arbitrary lookahead because it is not necessary to distinguish
between vectors of length 1 and repeat expressions until the end of
the expression (this is distinct from, say, foo<T>, where we would
need to know before we parse T whether it is an expression or a
type).

@catamorphism
Copy link
Contributor

1.0, high (not committing to change it yet, just to discuss it)

@bstrie
Copy link
Contributor

bstrie commented Oct 30, 2013

IMO, Rust got it right by putting the inner type of a vector inside rather than before the braces (i.e. [int] rather than int[]). I'm eager in preserving that property, even if it does make the fixed-length syntax a little more unsightly.

Personally I don't have an issue with [T, ..n] on its own. However, now that we've introduced the three-dot ellipsis into the parser (as per #10064), I do worry a little that we'll be tempted to use it elsewhere, and without a clear and memorable meaning for these symbols we risk people never being able to remember when to use .. vs when to use .... So then, is .. our "repeat" operator? And is this consistent with all the contexts in which it is used?

As for proposals, I really want to avoid overloading : even more (especially if we plan on going through with pcwalton's generalized type ascription syntax one day). Maybe we could do something with #? [int#5], perhaps. Though I don't think that really looks any better than the current syntax.

@Kimundi
Copy link
Member

Kimundi commented Oct 30, 2013

I think keeping [T, ..N] is fine as a mirror to the construction expression, and also on it's own: "A vector of T, repeated N times"

@nikomatsakis
Copy link
Contributor

I am basically happy with the current syntax, except that I think I'd prefer .... Or possibly just prefer that we use either .. or ... but not both. (cc #10064) Compare: [int, ...32] vs [int, ..32]. Three dots somehow looks more intensional to me, whereas .. looks like it could have been a typo. But is this vague reasoning enough to cause us to modify existing code? Probably not. I should have spoken up earlier I guess!

@brendanzab
Copy link
Member

@nikomatsakis ... takes up a great deal of room. The terseness of .. is nice.

But yeah, I don't have any issues with the current syntax. Makes me smile actually (yes, very good reasoning there). We used to have [T * N] which probably made more sense, but it was confusing when combined with constexprs.

@brson
Copy link
Contributor Author

brson commented Jan 1, 2014

It sounds like there's not a lot of momentum to change this, and there aren't a lot of good options. Wontfix?

@brson
Copy link
Contributor Author

brson commented Jan 24, 2014

Note that with DST we're probably going to need a fixed length string syntax, so this may come up again.

@brson
Copy link
Contributor Author

brson commented Feb 17, 2014

Nominating to close, assuming we're ok with reusing this syntax for fixed-length strings if we need to.

@Kimundi
Copy link
Member

Kimundi commented Feb 17, 2014

I think long-term str could move to the library with DST, so even if we need a special syntax at the beginning, it would likely be temporary anyway.

@brson
Copy link
Contributor Author

brson commented Feb 18, 2014

Wontfix.

@brson brson closed this as completed Feb 18, 2014
@liigo
Copy link
Contributor

liigo commented Feb 19, 2014

int[N] is still the best

flip1995 pushed a commit to flip1995/rust that referenced this issue Nov 21, 2022
Fix `#[allow]` for `module_name_repetitions` & `single_component_path_imports`

Fixes rust-lang#7511
Fixes rust-lang#8768
Fixes rust-lang#9401

`single_component_path_imports` needed some changes to the lint itself, it now buffers the found single component paths to emit in the equivalent `check_item`

changelog: Fix `#[allow(clippy::module_name_repetitions)]` and `#[allow(clippy::single_component_path_imports)]`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-grammar Area: The grammar of Rust
Projects
None yet
Development

No branches or pull requests

10 participants