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

Fix various aspects around `let` bindings inside const functions #56160

Open
wants to merge 23 commits into
base: master
from

Conversation

Projects
None yet
8 participants
@oli-obk
Contributor

oli-obk commented Nov 22, 2018

  • forbid let bindings in const contexts that use short circuiting operators
  • harden analysis code against derefs of mutable references

Initially this PR was about stabilizing let bindings, but too many flaws were exposed that need some more testing on nightly

@rust-highfive

This comment was marked as outdated.

Collaborator

rust-highfive commented Nov 22, 2018

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:0889da40:start=1542894527475591056,finish=1542894581816479258,duration=54340888202
$ 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:46:27] .................................................................................................... 2100/5058
[00:46:31] .................................................................................................... 2200/5058
[00:46:34] .................................................................................................... 2300/5058
[00:46:38] .................................................................................................... 2400/5058
[00:46:41] ............................................................F....................................... 2500/5058
[00:46:48] .................................................................................................... 2700/5058
[00:46:52] .................................................................................................... 2800/5058
[00:46:54] .................................................................................................... 2900/5058
[00:46:58] .................................................................................................... 3000/5058
---
[00:47:43] .................................................................................................... 4600/5058
[00:47:46] .........................i.......................................................................... 4700/5058
[00:47:50] .................................................................................................... 4800/5058
[00:47:52] .................................................................................................... 4900/5058
[00:47:54] .................................................................................................i.. 5000/5058
" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[00:47:56] 
[00:47:56] 
[00:47:56] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[00:47:56] Build completed unsuccessfully in 0:03:36
[00:47:56] Build completed unsuccessfully in 0:03:36
[00:47:56] make: *** [check] Error 1
[00:47:56] Makefile:58: recipe for target 'check' failed
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:0e6da79e
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Thu Nov 22 14:37:46 UTC 2018

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)

@rust-highfive

This comment was marked as resolved.

Collaborator

rust-highfive commented Nov 22, 2018

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:0cbe476b:start=1542897965022585753,finish=1542898022678835707,duration=57656249954
$ 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:52:06] .................................................................................................... 100/5058
[00:52:09] .................................................................................................... 200/5058
[00:52:12] .............................ii............................................ii...................ii.. 300/5058
[00:52:14] ..............................................................................................iii... 400/5058
[00:52:17] .....iiiiiiii.iii............................iii...........................................i........ 500/5058
[00:52:24] .................................................................................................... 700/5058
[00:52:30] .............................................................................................i...... 800/5058
[00:52:34] .....i.............................................................................................. 900/5058
[00:52:37] ............iiiii..................ii.iiii.......................................................... 1000/5058
---
[00:53:17] .................................................................................................... 2300/5058
[00:53:21] .................................................................................................... 2400/5058
[00:53:25] .................................................................................................... 2500/5058
[00:53:29] .................................................................................................... 2600/5058
[00:53:33] .iiiiiiiii.......................................................................................... 2700/5058
[00:53:39] .................................................................................................... 2900/5058
[00:53:43] .................................................................................................... 3000/5058
[00:53:46] ...............................................................i.................................... 3100/5058
[00:53:50] .................................................................................................... 3200/5058
---
travis_time:start:test_compile-fail
Check compiletest suite=compile-fail mode=compile-fail (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:07:21] 
[01:07:21] running 22 tests
[01:07:22] thread 'main' panicked at 'Some tests failed', tools/compiletest/src/main.rs:503:22
[01:07:22] .....F................
[01:07:22] 
[01:07:22] ---- [compile-fail] compile-fail/const-fn-error.rs stdout ----
[01:07:22] 
[01:07:22] error: /checkout/src/test/compile-fail/const-fn-error.rs:16: expected message not found: let bindings in constant functions are unstable
[01:07:22] error: /checkout/src/test/compile-fail/const-fn-error.rs:16: expected message not found: let bindings in constant functions are unstable
[01:07:22] 
[01:07:22] error: /checkout/src/test/compile-fail/const-fn-error.rs:16: expected message not found: statements in constant functions are unstable
[01:07:22] 
[01:07:22] error: 0 unexpected errors found, 2 expected errors not found
[01:07:22] status: exit code: 1
[01:07:22] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/compile-fail/const-fn-error.rs" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/compile-fail/const-fn-error/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/compile-fail/const-fn-error/auxiliary" "-A" "unused"
[01:07:22]     Error {
[01:07:22]         line_num: 16,
[01:07:22]         kind: None,
[01:07:22]         kind: None,
[01:07:22]         msg: "let bindings in csr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "5.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[01:07:22] 
[01:07:22] 
[01:07:22] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:07:22] Build completed unsuccessfully in 0:19:16
[01:07:22] Build completed unsuccessfully in 0:19:16
[01:07:22] Makefile:58: recipe for target 'check' failed
[01:07:22] make: *** [check] Error 1
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:1d40e402
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Thu Nov 22 15:54:34 UTC 2018
---
travis_time:end:05bd04a8:start=1542902075776237364,finish=1542902075929449590,duration=153212226
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:267ac047
$ 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:17b99804
$ 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)

@Centril

Additionally, here's a comprehensive run-pass test that would be nice to add: https://gist.github.com/Centril/a8df54dc8ee0b6bf0da46b5fba446acd

Show resolved Hide resolved src/test/ui/consts/const_let_assign2.rs Outdated
Show resolved Hide resolved src/test/ui/consts/const_let_assign2.rs Outdated
Show resolved Hide resolved src/test/ui/consts/const_let_assign.rs Outdated
Show resolved Hide resolved src/test/ui/feature-gates/feature-gate-const_let.rs

@Centril Centril added the relnotes label Nov 22, 2018

@@ -121,7 +121,7 @@
#![feature(const_slice_len)]
#![feature(const_str_as_bytes)]
#![feature(const_str_len)]
#![feature(const_let)]
#![cfg_attr(stage0, feature(const_let))]

This comment has been minimized.

@oli-obk

oli-obk Nov 23, 2018

Contributor

libcore now doesn't need this feature gate anymore -> some more const fns could be made stable after this PR

@rust-highfive

This comment was marked as resolved.

Collaborator

rust-highfive commented Nov 23, 2018

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:0b7af760:start=1542982218399679001,finish=1542982272372726294,duration=53973047293
$ 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:03:48] travis_fold:start:tidy
travis_time:start:tidy
tidy check
[00:03:49] tidy error: /checkout/src/test/ui/consts/const_let_eq.rs: missing trailing newline
[00:03:50] some tidy checks failed
[00:03:50] 
[00:03:50] 
[00:03:50] 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:03:50] 
[00:03:50] 
[00:03:50] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:03:50] Build completed unsuccessfully in 0:00:56
[00:03:50] Build completed unsuccessfully in 0:00:56
[00:03:50] make: *** [tidy] Error 1
[00:03:50] Makefile:79: recipe for target 'tidy' failed
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:09f01e60
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Fri Nov 23 14:15:11 UTC 2018
---
travis_time:end:0a25ad5c:start=1542982511741445939,finish=1542982511746780386,duration=5334447
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:08abd0a7
$ 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:1db09bde
travis_time:start:1db09bde
$ 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:0498f810
$ 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)

@eddyb

This comment has been minimized.

Member

eddyb commented Nov 23, 2018

@oli-obk Can we poison the MIR (i.e. add a flag that we set to true) if && or || are found and decide whether to allow const_let based on that?

@Centril

This comment has been minimized.

Contributor

Centril commented Nov 23, 2018

@oli-obk I remembered one thing now... floating points and assignment ops... we should make sure that they are not stabilized by including a test with all of the assignment ops for f32 & f64. :)

@Centril

This comment has been minimized.

Contributor

Centril commented Nov 23, 2018

Having reviewed the main tests, I pass on the torch to...
r? @eddyb

also cc @RalfJung and @nikomatsakis

@rust-highfive rust-highfive assigned eddyb and unassigned Centril Nov 23, 2018

Show resolved Hide resolved src/librustc_mir/transform/qualify_consts.rs Outdated
@eddyb

This comment has been minimized.

Member

eddyb commented Nov 23, 2018

@oli-obk Can you add tests for match with a single arm? I expect it to work.

@oli-obk

This comment has been minimized.

Contributor

oli-obk commented Nov 23, 2018

Can we poison the MIR (i.e. add a flag that we set to true) if && or || are found and decide whether to allow const_let based on that?

I had the exact same idea like an hour ago. I guess that means it wasn't a stupid idea

Show resolved Hide resolved src/librustc/mir/mod.rs Outdated
Show resolved Hide resolved src/libsyntax/feature_gate.rs Outdated
#![feature(nll)]
const FOO: Option<&[[u8; 3]]> = Some(&[*b"foo"]); //~ ERROR temporary value dropped while borrowed
const FOO: Option<&[[u8; 3]]> = Some(&[*b"foo"]);

This comment has been minimized.

@Centril

Centril Nov 24, 2018

Contributor

why is this permitted all of a sudden?

This comment has been minimized.

@eddyb

eddyb Nov 24, 2018

Member

* used to not get promoted, because we didn't know references were guaranteed valid, but I think nowadays promotion is much stricter so that shouldn't be a problem anymore.

This comment has been minimized.

@Centril

Centril Nov 24, 2018

Contributor

Alright; we need to note this in the set of stabilization changes then if we permit this in stable. :)

@RalfJung

This comment has been minimized.

Member

RalfJung commented Nov 24, 2018

Initial implementation was merged in May: #49172

Based on #56070 (which relaxes some restrictions around assignments, before that PR we only allowed x = 42; not x.y = 42;

These two seem to contradiction each other. Isn't this stabilizing behavior that has not even landed yet?

@oli-obk

This comment has been minimized.

Contributor

oli-obk commented Nov 26, 2018

I'm going to reintroduce the feature gate and let the final version bake a little more in nightly. I don't feel comfortable changing so many things and stabilizing at the same time.

@oli-obk

This comment has been minimized.

Contributor

oli-obk commented Nov 26, 2018

Single match arms lead to constant contains unimplemented expression type currently. (which happens when you call the not_const method, which happens a lot in const qualif)

@eddyb

This comment has been minimized.

Member

eddyb commented Nov 26, 2018

@oli-obk Maybe because of the Discriminant "fake read"?

@RalfJung

This comment has been minimized.

Member

RalfJung commented Nov 26, 2018

Nit all single-arm matches should work, IMO. Just things like match foo { x => ... }, where there is no pattern. Those should not have a Discriminant "fake read", there might not even be an enum involved.

@oli-obk oli-obk force-pushed the oli-obk:const_fn_let branch from e518293 to e07242f Nov 26, 2018

@rust-highfive

This comment has been minimized.

Collaborator

rust-highfive commented Nov 26, 2018

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:013a9fb3:start=1543234629401425363,finish=1543234630469987664,duration=1068562301
$ 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:03:15] travis_fold:start:tidy
travis_time:start:tidy
tidy check
[00:03:16] tidy error: /checkout/src/test/ui/consts/const_short_circuit.rs: missing trailing newline
[00:03:17] some tidy checks failed
[00:03:17] 
[00:03:17] 
[00:03:17] 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:03:17] 
[00:03:17] 
[00:03:17] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:03:17] Build completed unsuccessfully in 0:00:54
[00:03:17] Build completed unsuccessfully in 0:00:54
[00:03:17] make: *** [tidy] Error 1
[00:03:17] Makefile:79: recipe for target 'tidy' failed
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:23fb0a6d
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Mon Nov 26 12:20:36 UTC 2018
---
travis_time:end:017edeb5:start=1543234837050114553,finish=1543234837054237470,duration=4122917
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:113acf6c
$ 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:1ecac216
travis_time:start:1ecac216
$ 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:00fa9d6c
$ 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 oli-obk force-pushed the oli-obk:const_fn_let branch from 9b8ecfb to afe9e6e Nov 26, 2018

@rust-highfive

This comment has been minimized.

Collaborator

rust-highfive commented Nov 26, 2018

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:1526d206:start=1543244844698815642,finish=1543244846101994454,duration=1403178812
$ 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:51:02] .................................................................................................... 100/5069
[00:51:05] .................................................................................................... 200/5069
[00:51:08] .............................ii............................................ii...................ii.. 300/5069
[00:51:11] ..............................................................................................iii... 400/5069
[00:51:14] .....iiiiiiii.iii............................iii............................................i....... 500/5069
[00:51:22] .................................................................................................... 700/5069
[00:51:27] ...................................................................................................i 800/5069
[00:51:31] ...........i........................................................................................ 900/5069
[00:51:35] ..................iiiii..................ii.iiii.................................................... 1000/5069
[00:51:35] ..................iiiii..................ii.iiii.................................................... 1000/5069
[00:51:37] .............................................................................................iiiiiii 1100/5069
[00:51:42] .................................................................................................... 1300/5069
[00:51:44] .................................................................................................... 1400/5069
[00:51:46] ................................................i................................................... 1500/5069
[00:51:50] .................i.........ii.........................................................i............. 1600/5069
---
[00:52:15] .................................................................................................... 2300/5069
[00:52:19] .................................................................................................... 2400/5069
[00:52:23] .................................................................................................... 2500/5069
[00:52:26] .................................................................................................... 2600/5069
[00:52:30] .....iiiiiiiii...................................................................................... 2700/5069
[00:52:36] .................................................................................................... 2900/5069
[00:52:40] .................................................................................................... 3000/5069
[00:52:43] ....................................................................i............................... 3100/5069
[00:52:46] .................................................................................................... 3200/5069
---
[00:53:54] .................................................................................................... 100/2886
[00:54:05] .................................................................................i.................. 200/2886
[00:54:13] .................................................................................................... 300/2886
[00:54:24] .................................................................................................... 400/2886
[00:54:33] ........................................F........................................................... 500/2886
[00:54:45] .................................F.................................................................. 600/2886
[00:55:11] .................................................................................................... 800/2886
[00:55:20] .................................................................................................... 900/2886
[00:55:36] .................................................................................................... 1000/2886
[00:55:49] .................................................................................................... 1100/2886
---
[01:00:10] failures:
[01:00:10] 
[01:00:10] ---- [run-pass] run-pass/consts/const-binops.rs stdout ----
[01:00:10] normalized stderr:
[01:00:10] warning: boolean short circuiting operators in constants do not actually short circuit. Thus new const eval features are not accessible in constants.
[01:00:10]    |
[01:00:10]    |
[01:00:10] LL | static N: bool = true && false;
[01:00:10]    |                       ^^ help: use a bit operator instead: `&`
[01:00:10] 
[01:00:10] warning: boolean short circuiting operators in constants do not actually short circuit. Thus ures are not accessible in constants.","code":null,"level":"warning","spans":[{"file_name":"/checkout/src/test/run-pass/consts/const-binops.rs","byte_start":1029,"byte_end":1031,"line_start":37,"line_end":37,"column_start":23,"column_end":25,"is_primary":true,"text":[{"text":"static N: bool = true && false;","highlight_start":23,"highlight_end":25}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"use a bit operator instead","code":null,"level":"help","spans":[{"file_name":"/checkout/src/test/run-pass/consts/const-binops.rs","byte_start":1029,"byte_end":1031,"line_start":37,"line_end":37,"column_start":23,"column_end":25,"is_primary":true,"text":[{"text":"static N: bool = true && false;","highlight_start":23,"highlight_end":25}],"label":null,"suggested_replacement":"&","suggestion_applicability":"MachineApplicable","expansion":null}],"children":[],"rendered":null}],"rendered":"warning: boolean short circuiting operators in constants do not actually short circuit. Thus new const eval features are not accessible in constants.\n  --> /checkout/src/test/run-pass/consts/const-binops.rs:37:23\n   |\nLL | static N: bool = true && false;\n   |                       ^^ help: use a bit operator instead: `&`\n\n"}
[01:00:10] {"message":"boolean short circuiting operators in constants do not actually short circuit. Thus new const eval features are not accessible in constants.","code":null,"level":"warning","spans":[{"file_name":"/checkout/src/test/run-pass/consts/const-binops.rs","byte_start":1062,"byte_end":1064,"line_start":39,"line_end":39,"column_start":23,"column_end":25,"is_primary":true,"text":[{"text":"static O: bool = true || false;","highlight_start":23,"highlight_end":25}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"use a bit operator instead","code":null,"level":"help","spans":[{"file_name":"/checkout/src/test/run-pass/consts/const-binops.rs","byte_start":1062,"byte_end":1064,"line_start":39,"line_end":39,"column_start":23,"column_end":25,"is_primary":true,"text":[{"text":"static O: bool = true || false;","highlight_start":23,"highlight_end":25}],"label":null,"suggested_replacement":"|","suggestion_applicability":"MachineApplicable","expansion":null}],"children":[],"rendered":null}],"rendered":"warning: boolean short circuiting operators in constants do not actually short circuit. Thus new const eval features are not accessible in constants.\n  --> /checkout/src/test/run-pass/consts/const-binops.rs:39:23\n   |\nLL | static O: bool = true || false;\n   |                       ^^ help: use a bit operator instead: `|`\n\n"}
[01:00:10] ------------------------------------------
[01:00:10] 
[01:00:10] thread '[run-pass] run-pass/consts/const-binops.rs' panicked at 'explicit panic', src/tools/compiletest/src/runtest.rs:3282:9
[01:00:10] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[01:00:10] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[01:00:10] 
[01:00:10] ---- [run-pass] run-pass/ctfe/issue-37550.rs stdout ----
[01:00:10] 
[01:00:10] error: test compilation failed although it shouldn't!
[01:00:10] status: exit code: 1
[01:00:10] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/run-pass/ctfe/istable (see issue #48821)\n  --> /checkout/src/test/run-pass/ctfe/issue-37550.rs:19:13\n   |\nLL |     let x = || t;\n   |             ^^^^\n   |\n   = help: add #![feature(const_let)] to the crate attributes to enable\n\n"}
[01:00:10] {"message":"statements in constant functions are unstable (see issue #48821)","code":{"code":"E0658","explanation":"\nAn unstable feature was used.\n\nErroneous code example:\n\n```compile_fail,E658\n#[repr(u128)] // error: use of unstable library feature 'repr128'\nenum Foo {\n    Bar(u64),\n}\n```\n\nIf you're using a stable or a beta version of rustc, you won't be able to use\nany unstable features. In order to do so, please switch to a nightly version of\nrustc (by using rustup).\n\nIf you're using a nightly version of rustc, just add the corresponding feature\nto be able to use it:\n\n```\n#![feature(repr128)]\n\n#[repr(u128)] // ok!\nenum Foo {\n    Bar(u64),\n}\n```\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/run-pass/ctfe/issue-37550.rs","byte_start":597,"byte_end":601,"line_start":19,"line_end":19,"column_start":13,"column_end":17,"is_primary":true,"text":[{"text":"    let x = || t;","highlight_start":13,"highlight_end":17}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"add #![feature(const_let)] to the crate attributes to enable","code":null,"level":"help","spans":[],"children":[],"rendered":null}],"rendered":"error[E0658]: statements in constant functions are unstable (see issue #48821)\n  --> /checkout/src/test/run-pass/ctfe/issue-37550.rs:19:13\n   |\nLL |     let x = || t;\n   |             ^^^^\n   |\n   = help: add #![feature(const_let)] to the crate attributes to enable\n\n"}
[01:00:10] {"message":"aborting due to 4 previous errors","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to 4 previous errors\n\n"}
[01:00:10] {"message":"For more information about this error, try `rustc --explain E0658`.","code":null,"level":"","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0658`.\n"}
[01:00:10] ------------------------------------------
[01:00:10] 
[01:00:10] thread '[run-pass] run-pass/ctfe/issue-37550.rs' panicked at 'explicit panic', src/tools/compiletest/src/runtest.rs:3282:9
[01:00:10] 
---
[01:00:10] test result: FAILED. 2874 passed; 2 failed; 10 ignored; 0 measured; 0 filtered out
[01:00:10] 
[01:00:10] 
[01:00:10] 
[01:00:10] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/run-pass" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass" "--stage-id" "statravis_time:end:05e0f16a:start=1543244855514386408,finish=1543248465863742996,duration=3610349356588
travis_time:start:028e9d18
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Mon Nov 26 16:07:45 UTC 2018
Mon, 26 Nov 2018 16:07:45 GMT

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)

@rust-highfive

This comment has been minimized.

Collaborator

rust-highfive commented Nov 26, 2018

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:0104bf87:start=1543249917871308749,finish=1543249920342909632,duration=2471600883
$ 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:51:10] .................................................................................................... 100/5069
[00:51:13] .................................................................................................... 200/5069
[00:51:15] .............................ii............................................ii...................ii.. 300/5069
[00:51:18] ..............................................................................................iii... 400/5069
[00:51:21] .....iiiiiiii.iii............................iii...........................................i........ 500/5069
[00:51:28] .................................................................................................... 700/5069
[00:51:34] ...................................................................................................i 800/5069
[00:51:38] ...........i........................................................................................ 900/5069
[00:51:41] ..................iiiii..................ii.iiii.................................................... 1000/5069
[00:51:41] ..................iiiii..................ii.iiii.................................................... 1000/5069
[00:51:44] .............................................................................................iiiiiii 1100/5069
[00:51:48] .................................................................................................... 1300/5069
[00:51:51] .................................................................................................... 1400/5069
[00:51:53] ................................................i................................................... 1500/5069
[00:51:56] .................i.........ii.........................................................i............. 1600/5069
---
[00:52:21] .................................................................................................... 2300/5069
[00:52:25] .................................................................................................... 2400/5069
[00:52:29] .................................................................................................... 2500/5069
[00:52:33] .................................................................................................... 2600/5069
[00:52:36] .....iiiiiiiii...................................................................................... 2700/5069
[00:52:42] .................................................................................................... 2900/5069
[00:52:46] .................................................................................................... 3000/5069
[00:52:49] ....................................................................i............................... 3100/5069
[00:52:52] .................................................................................................... 3200/5069
---
travis_time:start:test_compile-fail
Check compiletest suite=compile-fail mode=compile-fail (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:06:18] 
[01:06:18] running 22 tests
[01:06:18] .....F................
[01:06:18] failures:
[01:06:18] 
[01:06:18] ---- [compile-fail] compile-fail/const-fn-error.rs stdout ----
[01:06:18] 
[01:06:18] 
[01:06:18] error: /checkout/src/test/compile-fail/const-fn-error.rs:16: unexpected error: '16:19: 16:20: let bindings in constant functions are unstable (see issue #48821) [E0658]'
[01:06:18] 
[01:06:18] error: /checkout/src/test/compile-fail/const-fn-error.rs:16: unexpected error: '16:19: 16:20: statements in constant functions are unstable (see issue #48821) [E0658]'
[01:06:18] error: 2 unexpected errors found, 0 expected errors not found
[01:06:18] status: exit code: 1
[01:06:18] status: exit code: 1
[01:06:18] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/compile-fail/const-fn-error.rs" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/compile-fail/const-fn-error/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/compile-fail/const-fn-error/auxiliary" "-A" "unused"
[01:06:18]     Error {
[01:06:18]         line_num: 16,
[01:06:18]         kind: Some(
[01:06:18]             Error
[01:06:18]             Error
[01:06:18]         ),
[01:06:18]         msg: "16:19: 16:20: let bindings in constant functions are unstable (see issue #48821) [E0658]"
[01:06:18]     Error {
[01:06:18]         line_num: 16,
[01:06:18]         kind: Some(
[01:06:18]             Error
[01:06:18]             Error
[01:06:18]         ),
[01:06:18]         msg: "16:19: 16:20: statements in constant functions are unstable (see issue #48821) [E0658]"
[01:06:18] ]
[01:06:18] 
[01:06:18] thread '[compile-fail] compile-fail/const-fn-error.rs' panicked at 'explicit panic', src/tools/compiletest/src/runtest.rs:1358:13
[01:06:18] note: Run with `RUST_BACKTRACE=1` for a backtrace.
---
[01:06:18] test result: FAILED. 21 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out
[01:06:18] 
[01:06:18] 
[01:06:18] 
[01:06:18] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/compile-fail" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/compile-fail" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "compile-fail" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-5.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zunstable-options " "--target-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "5.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[01:06:18] 
[01:06:18] 
[01:06:18] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:06:18] Build completed unsuccessfully in 0:19:06
[01:06:18] Build completed unsuccessfully in 0:19:06
[01:06:18] make: *** [check] Error 1
[01:06:18] Makefile:58: recipe for target 'check' failed
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:0e7b7e5f
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Mon Nov 26 17:38:28 UTC 2018
---
travis_time:end:02ed1eb8:start=1543253911122263484,finish=1543253911264944937,duration=142681453
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:0811310e
$ 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:036d364f
$ 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 oli-obk changed the title from Stabilize `let` bindings inside const functions to Fix various aspects around `let` bindings inside const functions Nov 27, 2018

@oli-obk oli-obk force-pushed the oli-obk:const_fn_let branch from 63f45e2 to e6e08c6 Nov 30, 2018

@Dylan-DPC

This comment has been minimized.

Member

Dylan-DPC commented Dec 10, 2018

ping from triage @eddyb waiting for your review

@@ -1748,6 +1759,8 @@ pub enum StatementKind<'tcx> {
/// (e.g. inspecting constants and discriminant values), and the
/// kind of pattern it comes from. This is in order to adapt potential
/// error messages to these specific patterns.
///
/// Note that this also is emitted for regular `let` bindings to aid destructuring diagnostics

This comment has been minimized.

@eddyb

This comment has been minimized.

@nikomatsakis

nikomatsakis Dec 11, 2018

Contributor

I believe this is not the correct reason. The reason we add FakeRead is documented on FakeReadCause::ForLet -- basically it is to ensure that we give errors in some cases where we generate more optimized IR (not just for diagnostics).

@eddyb

eddyb approved these changes Dec 10, 2018

@eddyb

This comment has been minimized.

Member

eddyb commented Dec 10, 2018

LGTM, r? @nikomatsakis

@rust-highfive rust-highfive assigned nikomatsakis and unassigned eddyb Dec 10, 2018

@@ -320,6 +320,10 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> {
}
}
fn const_let_allowed(&self) -> bool {

This comment has been minimized.

@nikomatsakis

nikomatsakis Dec 11, 2018

Contributor

Seems like a great place for a comment =) in particular, documenting the logic behind these rules.

This comment has been minimized.

@nikomatsakis

nikomatsakis Dec 11, 2018

Contributor

Something like:


Currently, without a feature gate, let is only allowed in const fn. With a feature gate, it can appear anywhere.

This comment has been minimized.

@oli-obk

oli-obk Dec 12, 2018

Contributor

We decided on not doing this dual-scheme. Instead we're poisoning constants that use short circuiting operators so they can't also have let bindings.

I'll remove the function and move back to checking the feature gate directly

cx.control_flow_destroyed.push((
op.span,
"`&&` operator".into(),
));
ExprKind::Binary {

This comment has been minimized.

@nikomatsakis

nikomatsakis Dec 11, 2018

Contributor

Woah. I don't think I realized we do this sort of conversion.

if context.is_mutating_use() {
this.not_const()
} else {
this.qualif = Qualif::NOT_CONST;

This comment has been minimized.

@nikomatsakis

nikomatsakis Dec 11, 2018

Contributor

Is this intentionally overriding all other Qualif flags? (vs invoking add)? Why is that? Maybe a comment?

This comment has been minimized.

@oli-obk

oli-obk Dec 12, 2018

Contributor

That is an accidental leftover from the larger refactorings. I undid the change and added comments

@nikomatsakis

This comment has been minimized.

Contributor

nikomatsakis commented Dec 11, 2018

First round of review -- I'd like to take one more look before r+ and in particular to know the answer to this question

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment