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

const expression can borrow static items #1610

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dingxiangfei2009
Copy link

@dingxiangfei2009 dingxiangfei2009 commented Sep 11, 2024

Tracked by rust-lang/rust#119618

Blocked on rust-lang/rust#129759

Stabilization report: rust-lang/rust#128183

This PR updates the documentation to mention that now static items can be used for borrowing, explicitly or implicitly, which permits general use of them in const context.

@ehuss ehuss added the S-waiting-on-stabilization Waiting for a stabilization PR to be merged in the main Rust repository label Sep 11, 2024
@dingxiangfei2009 dingxiangfei2009 changed the title const expression can borrow static items const expression can borrow static items Sep 11, 2024
Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also update https://github.com/rust-lang/reference/blob/master/src/items/static-items.md which mentions this isn't possible?

I'm wondering if this might be confusion (and perhaps my understanding is missing) with regards to what counts as a borrow. IIUC, statics have an implied &, is that correct? For example, if you see const C: i32 = SOME_STATIC;, there's no obvious borrow there.

@dingxiangfei2009
Copy link
Author

@ehuss I updated the wording to include simply "use of statics".

I have updated static-items page as well with tweaks on wording.

@traviscross
Copy link
Contributor

We probably want to update the constant-items page that currently says:

Constants may refer to the address of other constants...

Since it'd now make sense for that to also address the fact that constants may refer to statics with some limitations.

@traviscross
Copy link
Contributor

Also in const_eval.md, where it says:

Paths to statics. These are only allowed within the initializer of a static.

...that seems to need to change also.

@traviscross
Copy link
Contributor

traviscross commented Sep 17, 2024

More generally, it seems what we need to do here is to loosen the various places in the Reference that have these restrictions, and in loosening them, add the necessary caveats, e.g. with respect to Freeze as described in rust-lang/rust#128183.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-stabilization Waiting for a stabilization PR to be merged in the main Rust repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants