The Wayback Machine - https://web.archive.org/web/20201228172938/https://github.com/rust-lang/reference/pull/914
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

Document array expression with a const. #914

Open
wants to merge 3 commits into
base: master
from

Conversation

@ehuss
Copy link
Collaborator

@ehuss ehuss commented Dec 22, 2020

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.)

@ehuss
Copy link
Collaborator Author

@ehuss ehuss commented Dec 22, 2020

@RalfJung Sorry, bugging you to review another one.

@RalfJung
Copy link
Member

@RalfJung RalfJung commented Dec 26, 2020

This sounds correct. However, do you want to mention the subtleties around drop? See rust-lang/rust#79270 (comment) and the surrounding discussion.

@ehuss
Copy link
Collaborator Author

@ehuss ehuss commented Dec 26, 2020

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 [non_const_expr; 0] evaluates once and then drops, and then include a note that this is not working as intended? Or just leave that part out completely and only say [CONST; 0] does not evaluate CONST (it seems a little weird to say that without contrasting it with the non-const example). Also, would you recommend putting that in the Destructors chapter, the Array Expression chapter, the Constant Evaluation chapter, or maybe in multiple locations?

@Havvy
Copy link
Collaborator

@Havvy Havvy commented Dec 26, 2020

I would document it how it is now ([CONST; 0]) does not evaluate CONST), but include a warning directly after contrasting this behavior with the non-const example.

@RalfJung
Copy link
Member

@RalfJung RalfJung commented Dec 26, 2020

I would document it how it is now ([CONST; 0]) does not evaluate CONST), but include a warning directly after contrasting this behavior with the non-const example.

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.

@ehuss
Copy link
Collaborator Author

@ehuss ehuss commented Dec 27, 2020

OK, I included a note on the [a; 0] behavior. I waffled a little on whether or not to note the bug. We talked about the policy a little bit in #599, and it seemed like the consensus is that it doesn't hurt to include the occasional note about a bug. I can remove it whenever rust-lang/rust#74836 is closed.

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

This comment has been minimized.

@RalfJung

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).

This comment has been minimized.

@ehuss

ehuss Dec 28, 2020
Author Collaborator

Oh, that makes sense and is much clearer to me now. Thanks for your patience!

@ehuss ehuss force-pushed the ehuss:array-const branch from 3d5a774 to a2e5a14 Dec 28, 2020
@RalfJung
Copy link
Member

@RalfJung RalfJung commented Dec 28, 2020

LGTM. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.