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

rustc/rustc_mir: Implement RFC 2203. #61749

Merged
merged 5 commits into from Jul 19, 2019

Conversation

@davidtwco
Copy link
Member

commented Jun 11, 2019

This PR implements RFC 2203, allowing constants in array repeat
expressions. Part of #49147.

r? @eddyb

src/librustc/mir/mod.rs Outdated Show resolved Hide resolved

@davidtwco davidtwco force-pushed the davidtwco:rfc-2203-const-array-repeat-exprs branch from 0ec77d9 to fd8fc14 Jun 11, 2019

@rust-highfive

This comment was marked as outdated.

Copy link
Collaborator

commented Jun 11, 2019

The job x86_64-gnu-llvm-6.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:205aa18e:start=1560288898429687048,finish=1560288899253515366,duration=823828318
$ 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
$ export GCP_CACHE_BUCKET=rust-lang-ci-cache
$ export AWS_ACCESS_KEY_ID=AKIA46X5W6CZEJZ6XT55
---
travis_time:start:test_codegen
Check compiletest suite=codegen mode=codegen (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:13:32] 
[01:13:32] running 144 tests
[01:13:34] i..iii.....iii..iiii.....i......................i..i............F....i.....i..........ii.i..i..i.ii. 100/144
[01:13:36] .............i.........ii.i..F...iii........
[01:13:36] 
[01:13:36] ---- [codegen] codegen/issue-56927.rs stdout ----
[01:13:36] 
[01:13:36] 
[01:13:36] error: verification with 'FileCheck' failed
[01:13:36] status: exit code: 1
[01:13:36] command: "/usr/lib/llvm-6.0/bin/FileCheck" "--input-file" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen/issue-56927/issue-56927.ll" "/checkout/src/test/codegen/issue-56927.rs"
[01:13:36] ------------------------------------------
[01:13:36] 
[01:13:36] ------------------------------------------
[01:13:36] stderr:
[01:13:36] stderr:
[01:13:36] ------------------------------------------
[01:13:36] /checkout/src/test/codegen/issue-56927.rs:40:11: error: expected string not found in input
[01:13:36] // CHECK: store i32 6, i32* %{{.+}}, align 4
[01:13:36]           ^
[01:13:36] /checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen/issue-56927/issue-56927.ll:96:19: note: scanning from here
[01:13:36] define void @test4(%S* align 16 dereferenceable(16)) unnamed_addr #0 {
[01:13:36]                   ^
[01:13:36] /checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen/issue-56927/issue-56927.ll:114:2: note: possible intended match here
[01:13:36]  store i32 %3, i32* %7, align 4
[01:13:36] 
[01:13:36] ------------------------------------------
[01:13:36] 
[01:13:36] 
[01:13:36] 
[01:13:36] ---- [codegen] codegen/slice-init.rs stdout ----
[01:13:36] 
[01:13:36] error: verification with 'FileCheck' failed
[01:13:36] status: exit code: 1
[01:13:36] command: "/usr/lib/llvm-6.0/bin/FileCheck" "--input-file" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen/slice-init/slice-init.ll" "/checkout/src/test/codegen/slice-init.rs"
[01:13:36] ------------------------------------------
[01:13:36] 
[01:13:36] ------------------------------------------
[01:13:36] stderr:
[01:13:36] stderr:
[01:13:36] ------------------------------------------
[01:13:36] /checkout/src/test/codegen/slice-init.rs:26:12: error: expected string not found in input
[01:13:36]  // CHECK: call void @llvm.memset.p0i8.i[[WIDTH:[0-9]+]](i8* {{.*}}, i8 7, i[[WIDTH]] 4
[01:13:36]            ^
[01:13:36] /checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen/slice-init/slice-init.ll:88:24: note: scanning from here
[01:13:36] define void @byte_array() unnamed_addr #1 {
[01:13:36]                        ^
[01:13:36] /checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen/slice-init/slice-init.ll:95:2: note: possible intended match here
[01:13:36]  call void @llvm.memset.p0i8.i64(i8* %2, i8 %1, i64 4, i32 1, i1 false)
[01:13:36] /checkout/src/test/codegen/slice-init.rs:51:12: error: expected string not found in input
[01:13:36] /checkout/src/test/codegen/slice-init.rs:51:12: error: expected string not found in input
[01:13:36]  // CHECK: call void @llvm.memset.p0i8.i[[WIDTH:[0-9]+]](i8* {{.*}}, i8 0, i[[WIDTH]] 16
[01:13:36]            ^
[01:13:36] /checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen/slice-init/slice-init.ll:128:34: note: scanning from here
[01:13:36] define void @zeroed_integer_array() unnamed_addr #1 {
[01:13:36]                                  ^
[01:13:36] /checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen/slice-init/slice-init.ll:132:2: note: possible intended match here
[01:13:36]  call void @llvm.lifetime.start.p0i8(i64 16, i8* %0)
[01:13:36] 
[01:13:36] ------------------------------------------
[01:13:36] 
[01:13:36] 
---
[01:13:36] thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:521:22
[01:13:36] note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
[01:13:36] 
[01:13:36] 
[01:13:36] 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/codegen" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "codegen" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-6.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Cdebuginfo=0 -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" "6.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:13:36] 
[01:13:36] 
[01:13:36] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:13:36] Build completed unsuccessfully in 1:03:15
---
travis_time:end:03c27a8f:start=1560293364623921289,finish=1560293364681370992,duration=57449703
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:0299a8c4
$ 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:1d645bf8
$ 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)

.span_label(span, &format!(
"the trait `{}` is not implemented for `{}`",
copy_path, ty,
))

This comment has been minimized.

Copy link
@eddyb

eddyb Jun 12, 2019

Member

cc @nikomatsakis @matthewjasper This is not a proper trait error, so it would miss the "backtrace" that one might get otherwise - any suggestions on how to fix that?

This comment has been minimized.

Copy link
@davidtwco

davidtwco Jun 12, 2019

Author Member

I've started re-using some existing functions for diagnostics in this PR. It appears to work correctly but it might not produce the full "backtrace" that you want.

@eddyb

This comment has been minimized.

Copy link
Member

commented Jun 12, 2019

To expand on #61749 (comment), this example:

#[derive(Copy, Clone)]
struct Foo<T>(T);
fn main() {
    [Foo(String::new()); 4];
}

Currently errors with:

error[E0277]: the trait bound `std::string::String: std::marker::Copy` is not satisfied
 --> src/main.rs:4:5
  |
4 |     [Foo(String::new()); 4];
  |     ^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `std::string::String`
  |
  = note: required because of the requirements on the impl of `std::marker::Copy` for `Foo<std::string::String>`
  = note: the `Copy` trait is required because the repeated element will be copied

The "required because of the requirements on the impl of ..." part would now be missing, I think.
There might be a relatively easy way to produce a proper trait error, even from the NLL type_check.
Either way, it would be good to have tests like this to properly compare the effect.

@davidtwco

This comment has been minimized.

Copy link
Member Author

commented Jun 12, 2019

Either way, it would be good to have tests like this to properly compare the effect.

I've added this example as a test.

@eddyb

This comment has been minimized.

Copy link
Member

commented Jun 12, 2019

@davidtwco Sadly, without adding a test like this (or a more complex one) on master first, it's hard to see the changes in diagnostics.

@rust-highfive

This comment was marked as outdated.

Copy link
Collaborator

commented Jun 12, 2019

The job x86_64-gnu-llvm-6.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:03f329a0:start=1560326174685578468,finish=1560326264097964842,duration=89412386374
$ 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
$ export GCP_CACHE_BUCKET=rust-lang-ci-cache
$ export AWS_ACCESS_KEY_ID=AKIA46X5W6CZEJZ6XT55
---
travis_time:start:tidy
tidy check
[00:03:47] * 576 error codes
[00:03:47] * highest error code: E0731
[00:03:49] tidy error: Found 1 features without a gate test.
[00:03:49] Expected a gate test for the feature 'const_in_array_repeat_expressions'.
[00:03:49] Hint: create a failing test file named 'feature-gate-const_in_array_repeat_expressions.rs'
[00:03:49]       in the 'ui' test suite, with its failures due to
[00:03:49]       missing usage of #![feature(const_in_array_repeat_expressions)].
[00:03:49] Hint: If you already have such a test and don't want to rename it,
[00:03:49]       you can also add a // gate-test-const_in_array_repeat_expressions line to the test file.
[00:03:51] some tidy checks failed
[00:03:51] 
[00:03:51] 
[00:03:51] 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:51] 
[00:03:51] 
[00:03:51] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:03:51] Build completed unsuccessfully in 0:01:11
---
travis_time:end:20c5df26:start=1560326506144344571,finish=1560326506148810799,duration=4466228
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:09bc35c8
$ 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:07db5222
travis_time:start:07db5222
$ 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:11db4d18
$ 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)

@davidtwco

This comment has been minimized.

Copy link
Member Author

commented Jun 12, 2019

@eddyb I've ran that example with another working directory (at most 24 hours old behind master) and this is the current error:

error[E0277]: the trait bound `std::string::String: std::marker::Copy` is not satisfied
 --> ../rust0/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/trait-error.rs:8:5
  |
8 |     [Foo(String::new()); 4];
  |     ^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `std::string::String`
  |
  = note: required because of the requirements on the impl of `std::marker::Copy` for `Foo<std::string::String>`
  = note: the `Copy` trait is required because the repeated element will be copied

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.

@davidtwco davidtwco force-pushed the davidtwco:rfc-2203-const-array-repeat-exprs branch from 3c7ee48 to 99ebd9a Jun 12, 2019

@rust-highfive

This comment was marked as outdated.

Copy link
Collaborator

commented Jun 12, 2019

The job x86_64-gnu-llvm-6.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:0f63872d:start=1560333044749588691,finish=1560333135047260837,duration=90297672146
$ 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
$ export GCP_CACHE_BUCKET=rust-lang-ci-cache
$ export AWS_ACCESS_KEY_ID=AKIA46X5W6CZEJZ6XT55
---
[00:56:49] .................................................................................................... 400/5678
[00:56:52] .................................................................................................... 500/5678
[00:56:56] ...................................i................................................................ 600/5678
[00:57:00] .................................................................................................... 700/5678
[00:57:04] ..................................F................................................................. 800/5678
[00:57:14] ...........................................i...........i............................................ 1000/5678
[00:57:17] ........................................................................iiiii....................... 1100/5678
[00:57:21] .................................................................................................... 1200/5678
[00:57:23] .................................................................................................... 1300/5678
---
[01:00:12] 5    |            ^^^^^^^^^^^^^^
[01:00:12] 6 
[01:00:12] - error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied
[01:00:12] -   --> $DIR/issue-61336.rs:9:5
[01:00:12] + error: array lengths can't depend on generic parameters
[01:00:12] 9    |
[01:00:12] 9    |
[01:00:12] 10 LL |     [x; N]
[01:00:12] -    |     ^^^^^^ the trait `std::marker::Copy` is not implemented for `T`
[01:00:12] + 
[01:00:12] + 
[01:00:12] + error: array lengths can't depend on generic parameters
[01:00:12] 12    |
[01:00:12] -    = help: consider adding a `where T: std::marker::Copy` bound
[01:00:12] -    = note: the `Copy` trait is required because the repeated element will be copied
[01:00:12] -    = note: the `Copy` trait is required because the repeated element will be copied
[01:00:12] + LL |     [x; N]
[01:00:12] 15 
[01:00:12] - error: aborting due to previous error
[01:00:12] + error: aborting due to 2 previous errors
[01:00:12] 17 
[01:00:12] 17 
[01:00:12] - For more information about this error, try `rustc --explain E0277`.
[01:00:12] 19 
[01:00:12] 
[01:00:12] 
[01:00:12] The actual stderr differed from the expected stderr.
[01:00:12] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/issue-61336/issue-61336.stderr
[01:00:12] To update references, rerun the tests and pass the `--bless` flag
[01:00:12] To only update this specific test, also pass `--test-args const-generics/issue-61336.rs`
[01:00:12] error: 1 errors occurred comparing output.
[01:00:12] status: exit code: 1
[01:00:12] status: exit code: 1
[01:00:12] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/const-generics/issue-61336.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/issue-61336" "-Crpath" "-O" "-Cdebuginfo=0" "-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/ui/const-generics/issue-61336/auxiliary" "-A" "unused"
[01:00:12] ------------------------------------------
[01:00:12] 
[01:00:12] ------------------------------------------
[01:00:12] stderr:
[01:00:12] stderr:
[01:00:12] ------------------------------------------
[01:00:12] warning: the feature `const_generics` is incomplete and may cause the compiler to crash
[01:00:12]   --> /checkout/src/test/ui/const-generics/issue-61336.rs:1:12
[01:00:12]    |
[01:00:12] LL | #![feature(const_generics)]
[01:00:12]    |            ^^^^^^^^^^^^^^
[01:00:12] 
[01:00:12] error: array lengths can't depend on generic parameters
[01:00:12]    |
[01:00:12]    |
[01:00:12] LL |     [x; N]
[01:00:12] 
[01:00:12] 
[01:00:12] error: array lengths can't depend on generic parameters
[01:00:12]    |
[01:00:12]    |
[01:00:12] LL |     [x; N]
[01:00:12] 
[01:00:12] error: aborting due to 2 previous errors
[01:00:12] 
[01:00:12] 
---
[01:00:12] thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:521:22
[01:00:12] note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
[01:00:12] 
[01:00:12] 
[01:00:12] 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/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-6.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Cdebuginfo=0 -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" "6.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:00:12] 
[01:00:12] 
[01:00:12] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:00:12] Build completed unsuccessfully in 0:56:00
---
travis_time:end:11ea5cca:start=1560336758377335251,finish=1560336758382347724,duration=5012473
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:02240859
$ 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:cr

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)

@davidtwco davidtwco force-pushed the davidtwco:rfc-2203-const-array-repeat-exprs branch 2 times, most recently from 55546ac to fbf884b Jun 12, 2019

@davidtwco davidtwco force-pushed the davidtwco:rfc-2203-const-array-repeat-exprs branch from fbf884b to 72ec9d7 Jun 12, 2019

@bors

This comment was marked as outdated.

Copy link
Contributor

commented Jun 17, 2019

☔️ The latest upstream changes (presumably #61857) made this pull request unmergeable. Please resolve the merge conflicts.

@davidtwco davidtwco force-pushed the davidtwco:rfc-2203-const-array-repeat-exprs branch from b9cae48 to 9d0ce71 Jun 17, 2019

@bors

This comment was marked as outdated.

Copy link
Contributor

commented Jun 19, 2019

☔️ The latest upstream changes (presumably #58351) made this pull request unmergeable. Please resolve the merge conflicts.

@davidtwco davidtwco force-pushed the davidtwco:rfc-2203-const-array-repeat-exprs branch from 9d0ce71 to 2c10ded Jun 19, 2019

@bors

This comment was marked as outdated.

Copy link
Contributor

commented Jun 23, 2019

☔️ The latest upstream changes (presumably #60861) made this pull request unmergeable. Please resolve the merge conflicts.

@davidtwco davidtwco force-pushed the davidtwco:rfc-2203-const-array-repeat-exprs branch from 2c10ded to 4a185c0 Jun 23, 2019

@eddyb

This comment has been minimized.

Copy link
Member

commented Jun 25, 2019

What is this blocked on, if anything?

@davidtwco

This comment has been minimized.

Copy link
Member Author

commented Jun 25, 2019

I'm not aware of any outstanding concerns, only that it isn't a proper trait error with a backtrace being emitted.

@bors

This comment was marked as outdated.

Copy link
Contributor

commented Jun 25, 2019

☔️ The latest upstream changes (presumably #60732) made this pull request unmergeable. Please resolve the merge conflicts.

@davidtwco davidtwco force-pushed the davidtwco:rfc-2203-const-array-repeat-exprs branch from 4a185c0 to a357743 Jun 25, 2019

@bors

This comment was marked as outdated.

Copy link
Contributor

commented Jul 3, 2019

☔️ The latest upstream changes (presumably #61775) made this pull request unmergeable. Please resolve the merge conflicts.

@bors

This comment has been minimized.

Copy link
Contributor

commented Jul 5, 2019

☔️ The latest upstream changes (presumably #62407) made this pull request unmergeable. Please resolve the merge conflicts.

@davidtwco davidtwco force-pushed the davidtwco:rfc-2203-const-array-repeat-exprs branch from e8d1f28 to 8168d22 Jul 5, 2019

@bors

This comment has been minimized.

Copy link
Contributor

commented Jul 7, 2019

☔️ The latest upstream changes (presumably #62467) made this pull request unmergeable. Please resolve the merge conflicts.

davidtwco added some commits May 26, 2019

rustc/rustc_mir: Implement RFC 2203.
This commit implements RFC 2203, allowing constants in array repeat
expressions.

Firstly, the check that the array repeat expression implements `Copy` is
removed and re-implemented in `rustc_mir::borrow_check::nll::type_check`
by emitting an error when the MIR contains a `Operand::Move` and the
type does not implement `Copy`.

Next, the `qualify_consts` pass is modified to construct a
`Candidate::Repeat` when it would be correct to promote a array repeat
expression.

Finally, the `promote_consts` pass is modified to promote the candidates
previously identified.
syntax: Add feature gate.
This commit adds a `const_in_array_repeat_expressions` feature gate and
only create `Candidate::Repeat` if it is enabled.
rustc_mir: Re-use `report_selection_error`.
This commit replaces the new error that was being emitted in NLL type
check with a call to `report_selection_error` so that the same trait
error as before this PR is emitted.

@davidtwco davidtwco force-pushed the davidtwco:rfc-2203-const-array-repeat-exprs branch from 8168d22 to 4b1bc2d Jul 7, 2019

@eddyb

This comment has been minimized.

Copy link
Member

commented Jul 11, 2019

r? @matthewjasper or @nikomatsakis - We need a way to report proper trait errors, with their cause/origin backtraces.

@rust-highfive rust-highfive assigned matthewjasper and unassigned eddyb Jul 11, 2019

@eddyb

This comment has been minimized.

Copy link
Member

commented Jul 18, 2019

@davidtwco I'm sorry for blocking this, I don't think the diagnostic regressions are worth the wait.
Especially given situations like #53491 (comment).

@@ -3,11 +3,12 @@

fn f<T: Copy, const N: usize>(x: T) -> [T; N] {
[x; {N}]
//~^ ERROR array lengths can't depend on generic parameters

This comment has been minimized.

Copy link
@eddyb

eddyb Jul 18, 2019

Member

Huh I don't remember this error.

This comment has been minimized.

Copy link
@eddyb

eddyb Jul 18, 2019

Member

Oh it's for [x; n] expressions, not types. Makes sense (although it should use a ty::Const instead of hardcoding an integer, cc @varkor @oli-obk ).

@eddyb

eddyb approved these changes Jul 18, 2019

@eddyb

This comment has been minimized.

Copy link
Member

commented Jul 18, 2019

@bors r+ p=2 rollup=never

@bors

This comment has been minimized.

Copy link
Contributor

commented Jul 18, 2019

📌 Commit 4b1bc2d has been approved by eddyb

@bors

This comment has been minimized.

Copy link
Contributor

commented Jul 18, 2019

⌛️ Testing commit 4b1bc2d with merge a336998...

bors added a commit that referenced this pull request Jul 18, 2019

Auto merge of #61749 - davidtwco:rfc-2203-const-array-repeat-exprs, r…
…=eddyb

rustc/rustc_mir: Implement RFC 2203.

This PR implements RFC 2203, allowing constants in array repeat
expressions. Part of #49147.

r? @eddyb
@bors

This comment has been minimized.

Copy link
Contributor

commented Jul 19, 2019

☀️ Test successful - checks-azure
Approved by: eddyb
Pushing a336998 to master...

@bors bors added the merged-by-bors label Jul 19, 2019

@bors bors merged commit 4b1bc2d into rust-lang:master Jul 19, 2019

4 checks passed

homu Test successful
Details
pr Build #20190707.58 succeeded
Details
pr (Linux mingw-check) Linux mingw-check succeeded
Details
pr (Linux x86_64-gnu-llvm-6.0) Linux x86_64-gnu-llvm-6.0 succeeded
Details

@davidtwco davidtwco deleted the davidtwco:rfc-2203-const-array-repeat-exprs branch Jul 19, 2019

|
= help: the following implementations were found:
<std::option::Option<T> as std::marker::Copy>
= note: the `Copy` trait is required because the repeated element will be copied

This comment has been minimized.

Copy link
@Centril

Centril Jul 26, 2019

Member

This doesn't mention the feature gate :(

)) = self.body[bb].statements[stmt_idx].kind {
promoted_temps.insert(index);
}
}

This comment has been minimized.

Copy link
@eddyb

eddyb Aug 14, 2019

Member

I just realized, this is unnecessary, only Candidate::Ref cares (it removes StorageDead from the temp that would need to be 'static).

_,
box Rvalue::Ref(_, _, Place::Base(PlaceBase::Local(index)))
) = self.body[bb].statements[stmt_idx].kind {
promoted_temps.insert(index);

This comment has been minimized.

Copy link
@eddyb

eddyb Aug 14, 2019

Member

@oli-obk Wow this is wrong?! const FOO: &i32 = { let x = &(5, false).0; x }; fails because of it, lol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.