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

Allow assignments in const contexts #56070

Merged
merged 15 commits into from
Nov 26, 2018
Merged

Allow assignments in const contexts #56070

merged 15 commits into from
Nov 26, 2018

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Nov 19, 2018

fixes #54098
fixes #51251
fixes #52613

@rust-highfive
Copy link
Collaborator

r? @petrochenkov

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 19, 2018
@rust-highfive

This comment has been minimized.

@rust-highfive

This comment has been minimized.

@petrochenkov
Copy link
Contributor

r? @RalfJung

@rust-highfive

This comment has been minimized.

@RalfJung
Copy link
Member

r=me with tidy happy:

[00:03:46] tidy error: /checkout/src/test/ui/consts/promote_const_let.rs: missing trailing newline
[00:03:47] some tidy checks failed

@oli-obk
Copy link
Contributor Author

oli-obk commented Nov 20, 2018

@bors r=RalfJung

@bors
Copy link
Contributor

bors commented Nov 20, 2018

📌 Commit 37fcd5c has been approved by RalfJung

@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 Nov 20, 2018
Place::Local(index) => break *index,
// projections are transparent for assignments
// we qualify the entire destination at once, even if just a field would have
// stricter qualification
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem correct - if you assign something with less qualifications to a field of a value with more, you turn those bits off.

@eddyb
Copy link
Member

eddyb commented Nov 21, 2018

In the future, please cc me on qualify_consts changes.

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 21, 2018
// projections are transparent for assignments
// we qualify the entire destination at once, even if just a field would have
// stricter qualification
Place::Projection(proj) => dest = &proj.base,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Continuing with

the mindset when dealing with [const qualif] should be "how do I break this?"

Projections would include Deref, which isn't a problem because we can't have mutable references at all inside const contexts. Still something to think about.

Downcast also can't happen, because we'd need match for that.

Maybe we should just whitelist field projections for now.

Copy link
Member

@eddyb eddyb Nov 21, 2018

Choose a reason for hiding this comment

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

The problem is something like this:

const FOO: &(Cell<usize>, bool) = &{
    let mut foo = (Cell::new(0), false);
    foo.1 = true; // resets `qualif(foo)` to `qualif(true)`
    foo
};

I suspect that will actually compile with this PR, although I'd like a confirmation.

We could add this as a testcase, but you might be able to come up with something simpler/more general.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This indeed compiles successfully with this PR

Copy link
Member

Choose a reason for hiding this comment

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

My suggestion is field (or projections in general) assignment should combine qualifications (i.e. |=) instead of replacing them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I now reuse the existing projection checks for reading values. These checks replace the qualification with NOT_CONST, so there's no real use in combining I think?

@RalfJung
Copy link
Member

In the future, please cc me on qualify_consts changes.

I'll happily hand them over to you. ;)

r? @eddyb

@rust-highfive rust-highfive assigned eddyb and unassigned RalfJung Nov 21, 2018
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:065e7ce8:start=1542793454701620808,finish=1542793512762261299,duration=58060640491
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#Pull-Requests-and-Security-Restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-5.0
---

[00:04:52] travis_fold:start:tidy
travis_time:start:tidy
tidy check
[00:04:52] tidy error: /checkout/src/test/ui/consts/projection_qualif.rs: missing trailing newline
[00:04:52] tidy error: /checkout/src/test/ui/consts/partial_qualif.rs: missing trailing newline
[00:04:53] some tidy checks failed
[00:04:53] 
[00:04:53] 
[00:04:53] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor" "--quiet"
[00:04:53] 
[00:04:53] 
[00:04:53] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:04:53] Build completed unsuccessfully in 0:01:02
[00:04:53] Build completed unsuccessfully in 0:01:02
[00:04:53] Makefile:79: recipe for target 'tidy' failed
[00:04:53] make: *** [tidy] Error 1
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:2218e2ff
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Wed Nov 21 09:50:16 UTC 2018
---
travis_time:end:22c719fc:start=1542793817090665327,finish=1542793817095606984,duration=4941657
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:0497bbba
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:00f12be8
travis_time:start:00f12be8
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:0ef37a6f
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@oli-obk
Copy link
Contributor Author

oli-obk commented Nov 21, 2018

@bors r=eddyb

@bors
Copy link
Contributor

bors commented Nov 21, 2018

📌 Commit 6db8c6c has been approved by eddyb

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 21, 2018
@bors
Copy link
Contributor

bors commented Nov 26, 2018

⌛ Testing commit 6db8c6c with merge b51632e...

bors added a commit that referenced this pull request Nov 26, 2018
Allow assignments in const contexts

fixes #54098
fixes #51251
fixes #52613
@bors
Copy link
Contributor

bors commented Nov 26, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: eddyb
Pushing b51632e to master...

@bors bors merged commit 6db8c6c into rust-lang:master Nov 26, 2018
@bors bors mentioned this pull request Nov 26, 2018
@oli-obk oli-obk deleted the const_let branch December 17, 2018 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
6 participants