Add tests (and a bit of cleanup) for interior mut handling in promotion and const-checking by RalfJung · Pull Request #121893 · rust-lang/rust (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation10 Commits3 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

RalfJung

@RalfJung

@rustbot rustbot added S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

T-compiler

Relevant to the compiler team, which will review and decide on the PR/issue.

labels

Mar 2, 2024

oli-obk

@oli-obk

oli-obk

//~^ERROR: mutable pointer in final value of constant
// In contrast, this one works since it is being promoted.
const NONE: &'static Option<Cell> = &None;

Choose a reason for hiding this comment

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

Maybe show off the promotion somewhere other than the trailing expression?

Choose a reason for hiding this comment

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

Good point, I didn't even realize that's possible -- I will add

// Making it clear that this is promotion, not "outer scope". const NONE_EXPLICIT_PROMOTED: &'static Option<Cell> = { let x = &None; x };

Choose a reason for hiding this comment

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

Interestingly, the behavior of this example changed between stable and nightly. On nightly it just says "can't drop String in const", on stable it additionally says "temporary value dropped while borrowed". I hope that's just suppressing two errors from the same location and not secretly actually doing promotion...

oli-obk

@RalfJung

@RalfJung

@RalfJung

@bors

📌 Commit fb802f2 has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

and removed S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

labels

Mar 11, 2024

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Mar 11, 2024

@matthiaskrgr

… r=oli-obk

Add tests (and a bit of cleanup) for interior mut handling in promotion and const-checking

Basically these are the parts of rust-lang#121786 that can be salvaged.

r? @oli-obk

bors added a commit to rust-lang-ci/rust that referenced this pull request

Mar 11, 2024

@bors

…kingjubilee

Rollup of 15 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request

Mar 11, 2024

@rust-timer

Rollup merge of rust-lang#121893 - RalfJung:const-interior-mut-tests, r=oli-obk

Add tests (and a bit of cleanup) for interior mut handling in promotion and const-checking

Basically these are the parts of rust-lang#121786 that can be salvaged.

r? @oli-obk

@RalfJung RalfJung deleted the const-interior-mut-tests branch

March 11, 2024 20:52

Labels

S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

T-compiler

Relevant to the compiler team, which will review and decide on the PR/issue.