-
Notifications
You must be signed in to change notification settings - Fork 17
promotion tweaks #31
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
promotion tweaks #31
Conversation
This looks good to me apart from the mention about promotion of references to types with interior mutability. Perhaps we could include the following as an example? const X: Cell<i32> = Cell::new(5); // ok
fn main() {
let x: &'static _ = &X; // not ok
} |
Done. |
at compile-time, so we do not have to check the initializer. However, the | ||
restrictions described above still apply for the *result* of the promoted | ||
computation: in particular, it must be a valid `const` (i.e., it cannot | ||
introduce interior mutability) and it must not require dropping. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's worth noting that these restrictions apply only in the context lifetime extension. We can initialize an array, which also uses the implicit rules, with a constant containing interior mutability (i.e. [CELL; 4]
). My revisions failed to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But [&CELL; 4]
gets rejected, I hope?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That compiles on stable because &T
is Copy
for all T
. Any use of it will cause a borrow check error since the access to CELL
has a temporary lifetime. Promotion fails for &CELL
even if it's in an array initializer if that's what you're asking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Promotion fails for &CELL even if it's in an array initializer if that's what you're asking.
Good.
But then behavior seems to be the same for arrays and lifetime extension? It's just that lifetime extension always involves a borrow.
@ecstatic-morse any more concerns/comments? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me
r? @oli-obk @ecstatic-morse