Document array expression with a const. #914
Conversation
@RalfJung Sorry, bugging you to review another one. |
This sounds correct. However, do you want to mention the subtleties around |
Hm, yea, as mentioned in the description, I intentionally left that out because I was uncertain what to say. Since rust-lang/rust#74836 is unresolved, should it document that |
I would document it how it is now ( |
Sounds good. As to where to put this... I have little idea about the structure of the reference, so I'll leave that up to you. I would not document the same thing in multiple places, but adding cross-references might be a good idea. |
OK, I included a note on the |
greater than 1 then this requires that the type of `a` is | ||
[`Copy`](../special-types-and-traits.md#copy), or `a` must be a path to a | ||
constant item. | ||
constant item. When `b` evaluates to 0, the expression `a` is evaluated once |
RalfJung
Dec 27, 2020
Member
"the expression a
is evaluated once" is always true for non-constant-items. So I think it is a bit strange to make 0
sound like a special case here.
I'd describe this (probably in a separate paragraph) as:
- for constant items, the expression is instantiated
b
times. (So if b == 0
, it is not instantiated at all.)
- for other
a
, the expression is evaluated exactly once (and then the result is copied as needed).
"the expression a
is evaluated once" is always true for non-constant-items. So I think it is a bit strange to make 0
sound like a special case here.
I'd describe this (probably in a separate paragraph) as:
- for constant items, the expression is instantiated
b
times. (So ifb == 0
, it is not instantiated at all.) - for other
a
, the expression is evaluated exactly once (and then the result is copied as needed).
ehuss
Dec 28, 2020
Author
Collaborator
Oh, that makes sense and is much clearer to me now. Thanks for your patience!
Oh, that makes sense and is much clearer to me now. Thanks for your patience!
LGTM. :) |
Documentation for rust-lang/rust#79270.
I did not include any details about drop behavior with
[a; 0]
, as it seems like rust-lang/rust#74836 is unresolved, though I can add that if desired. (I'm not sure if that would go in the array-expr chapter, or the destructor chapter.)