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

Add better diagnostic for unbounded Abst. Const #81544

Merged
merged 1 commit into from
Feb 3, 2021

Conversation

JulianKnodt
Copy link
Contributor

@JulianKnodt JulianKnodt commented Jan 30, 2021

In the case where a generic abst. const requires a trivial where bound: where TypeWithConst<const_fn(N)>: ,,
instead of requiring a where bound, just check that only consts are being substituted in to skip over where check.

This is pretty sketchy, but I think it works. Presumably, if there is checking for type bounds added later, it can first check nested requirements, and see if they're satisfied by the current ParamEnv.

Changed the diagnostic to add a better example, which is more practical than what was previously proposed.

r? @lcnr

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 30, 2021
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-9 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

1 error[E0080]: evaluation of constant value failed
-   --> $DIR/simple_fail.rs:9:48
-    |
- LL | fn test<const N: usize>() -> Arr<N> where [u8; N - 1]: Sized {
-    |                                                ^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow
Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=x86_64-unknown-linux-gnu
- error[E0080]: evaluation of constant value failed
8   --> $DIR/simple_fail.rs:6:33
9    |
9    |
10 LL | type Arr<const N: usize> = [u8; N - 1];

11    |                                 ^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow
+ error[E0080]: evaluation of constant value failed
+   --> $DIR/simple_fail.rs:9:48
+    |
+    |
+ LL | fn test<const N: usize>() -> Arr<N> where [u8; N - 1]: Sized {
+    |                                                ^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow
13 error: aborting due to 2 previous errors
14 



The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/const_evaluatable_checked/simple_fail.full/simple_fail.full.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args const-generics/const_evaluatable_checked/simple_fail.rs`

error in revision `full`: 1 errors occurred comparing output.
status: exit code: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/const-generics/const_evaluatable_checked/simple_fail.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--cfg" "full" "--error-format" "json" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zemit-future-incompat-report" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/const_evaluatable_checked/simple_fail.full" "-A" "unused" "-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/const_evaluatable_checked/simple_fail.full/auxiliary"
------------------------------------------

------------------------------------------
stderr:
stderr:
------------------------------------------
error[E0080]: evaluation of constant value failed
  --> /checkout/src/test/ui/const-generics/const_evaluatable_checked/simple_fail.rs:6:33
   |
LL | type Arr<const N: usize> = [u8; N - 1]; //[full]~ ERROR evaluation of constant
   |                                 ^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow
error[E0080]: evaluation of constant value failed
  --> /checkout/src/test/ui/const-generics/const_evaluatable_checked/simple_fail.rs:9:48
   |
   |
LL | fn test<const N: usize>() -> Arr<N> where [u8; N - 1]: Sized {
   |                                                ^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow
error: aborting due to 2 previous errors

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

---
test result: FAILED. 11224 passed; 1 failed; 88 ignored; 0 measured; 0 filtered out; finished in 114.06s



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" "--suite" "ui" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-9/bin/FileCheck" "--nodejs" "/usr/bin/node" "--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/python3" "--lldb-python" "/usr/bin/python3" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "9.0.0" "--llvm-components" "aarch64 aarch64asmparser aarch64codegen aarch64desc aarch64disassembler aarch64info aarch64utils aggressiveinstcombine all all-targets amdgpu amdgpuasmparser amdgpucodegen amdgpudesc amdgpudisassembler amdgpuinfo amdgpuutils analysis arm armasmparser armcodegen armdesc armdisassembler arminfo armutils asmparser asmprinter avr avrasmparser avrcodegen avrdesc avrdisassembler avrinfo binaryformat bitreader bitstreamreader bitwriter bpf bpfasmparser bpfcodegen bpfdesc bpfdisassembler bpfinfo codegen core coroutines coverage debuginfocodeview debuginfodwarf debuginfogsym debuginfomsf debuginfopdb demangle dlltooldriver engine executionengine fuzzmutate globalisel hexagon hexagonasmparser hexagoncodegen hexagondesc hexagondisassembler hexagoninfo instcombine instrumentation interpreter ipo irreader jitlink lanai lanaiasmparser lanaicodegen lanaidesc lanaidisassembler lanaiinfo libdriver lineeditor linker lto mc mca mcdisassembler mcjit mcparser mips mipsasmparser mipscodegen mipsdesc mipsdisassembler mipsinfo mirparser msp430 msp430asmparser msp430codegen msp430desc msp430disassembler msp430info native nativecodegen nvptx nvptxcodegen nvptxdesc nvptxinfo objcarcopts object objectyaml option orcjit passes perfjitevents powerpc powerpcasmparser powerpccodegen powerpcdesc powerpcdisassembler powerpcinfo profiledata remarks riscv riscvasmparser riscvcodegen riscvdesc riscvdisassembler riscvinfo riscvutils runtimedyld scalaropts selectiondag sparc sparcasmparser sparccodegen sparcdesc sparcdisassembler sparcinfo support symbolize systemz systemzasmparser systemzcodegen systemzdesc systemzdisassembler systemzinfo tablegen target textapi transformutils vectorize webassembly webassemblyasmparser webassemblycodegen webassemblydesc webassemblydisassembler webassemblyinfo windowsmanifest x86 x86asmparser x86codegen x86desc x86disassembler x86info x86utils xcore xcorecodegen xcoredesc xcoredisassembler xcoreinfo xray" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"


failed to run: /checkout/obj/build/bootstrap/debug/bootstrap --stage 2 test --exclude src/tools/tidy
Build completed unsuccessfully in 0:12:55

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-9 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

1 error[E0080]: evaluation of constant value failed
-   --> $DIR/simple_fail.rs:9:48
-    |
- LL | fn test<const N: usize>() -> Arr<N> where [u8; N - 1]: Sized {
Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=x86_64-unknown-linux-gnu
-    |                                                ^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow
- error[E0080]: evaluation of constant value failed
8   --> $DIR/simple_fail.rs:6:33
9    |
9    |
10 LL | type Arr<const N: usize> = [u8; N - 1];

11    |                                 ^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow
+ error[E0080]: evaluation of constant value failed
+   --> $DIR/simple_fail.rs:9:48
+    |
+    |
+ LL | fn test<const N: usize>() -> Arr<N> where [u8; N - 1]: Sized {
+    |                                                ^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow
13 error: aborting due to 2 previous errors
14 



The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/const_evaluatable_checked/simple_fail.full/simple_fail.full.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args const-generics/const_evaluatable_checked/simple_fail.rs`

error in revision `full`: 1 errors occurred comparing output.
status: exit code: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/const-generics/const_evaluatable_checked/simple_fail.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--cfg" "full" "--error-format" "json" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zemit-future-incompat-report" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/const_evaluatable_checked/simple_fail.full" "-A" "unused" "-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/const_evaluatable_checked/simple_fail.full/auxiliary"
------------------------------------------

------------------------------------------
stderr:
stderr:
------------------------------------------
error[E0080]: evaluation of constant value failed
  --> /checkout/src/test/ui/const-generics/const_evaluatable_checked/simple_fail.rs:6:33
   |
LL | type Arr<const N: usize> = [u8; N - 1]; //[full]~ ERROR evaluation of constant
   |                                 ^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow
error[E0080]: evaluation of constant value failed
  --> /checkout/src/test/ui/const-generics/const_evaluatable_checked/simple_fail.rs:9:48
   |
   |
LL | fn test<const N: usize>() -> Arr<N> where [u8; N - 1]: Sized {
   |                                                ^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow
error: aborting due to 2 previous errors

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

---
test result: FAILED. 11224 passed; 1 failed; 88 ignored; 0 measured; 0 filtered out; finished in 118.33s



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" "--suite" "ui" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-9/bin/FileCheck" "--nodejs" "/usr/bin/node" "--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/python3" "--lldb-python" "/usr/bin/python3" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "9.0.0" "--llvm-components" "aarch64 aarch64asmparser aarch64codegen aarch64desc aarch64disassembler aarch64info aarch64utils aggressiveinstcombine all all-targets amdgpu amdgpuasmparser amdgpucodegen amdgpudesc amdgpudisassembler amdgpuinfo amdgpuutils analysis arm armasmparser armcodegen armdesc armdisassembler arminfo armutils asmparser asmprinter avr avrasmparser avrcodegen avrdesc avrdisassembler avrinfo binaryformat bitreader bitstreamreader bitwriter bpf bpfasmparser bpfcodegen bpfdesc bpfdisassembler bpfinfo codegen core coroutines coverage debuginfocodeview debuginfodwarf debuginfogsym debuginfomsf debuginfopdb demangle dlltooldriver engine executionengine fuzzmutate globalisel hexagon hexagonasmparser hexagoncodegen hexagondesc hexagondisassembler hexagoninfo instcombine instrumentation interpreter ipo irreader jitlink lanai lanaiasmparser lanaicodegen lanaidesc lanaidisassembler lanaiinfo libdriver lineeditor linker lto mc mca mcdisassembler mcjit mcparser mips mipsasmparser mipscodegen mipsdesc mipsdisassembler mipsinfo mirparser msp430 msp430asmparser msp430codegen msp430desc msp430disassembler msp430info native nativecodegen nvptx nvptxcodegen nvptxdesc nvptxinfo objcarcopts object objectyaml option orcjit passes perfjitevents powerpc powerpcasmparser powerpccodegen powerpcdesc powerpcdisassembler powerpcinfo profiledata remarks riscv riscvasmparser riscvcodegen riscvdesc riscvdisassembler riscvinfo riscvutils runtimedyld scalaropts selectiondag sparc sparcasmparser sparccodegen sparcdesc sparcdisassembler sparcinfo support symbolize systemz systemzasmparser systemzcodegen systemzdesc systemzdisassembler systemzinfo tablegen target textapi transformutils vectorize webassembly webassemblyasmparser webassemblycodegen webassemblydesc webassemblydisassembler webassemblyinfo windowsmanifest x86 x86asmparser x86codegen x86desc x86disassembler x86info x86utils xcore xcorecodegen xcoredesc xcoredisassembler xcoreinfo xray" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"


failed to run: /checkout/obj/build/bootstrap/debug/bootstrap --stage 2 test --exclude src/tools/tidy
Build completed unsuccessfully in 0:13:24

@JulianKnodt JulianKnodt changed the title Remove requirement for where clause for generic abst. const. Add better diagnostic for unbounded Abst. Const Jan 31, 2021
Previously, it's not clear what exactly should be added in the suggested where clause,
so this adds an example to demonstrate.
@lcnr
Copy link
Contributor

lcnr commented Feb 2, 2021

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Feb 2, 2021

📌 Commit 6525671 has been approved by lcnr

@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 Feb 2, 2021
m-ou-se added a commit to m-ou-se/rust that referenced this pull request Feb 2, 2021
Add better diagnostic for unbounded Abst. Const

~~In the case where a generic abst. const requires a trivial where bound: `where TypeWithConst<const_fn(N)>: ,`,
instead of requiring a where bound, just check that only consts are being substituted in to skip over where check.~~

~~This is pretty sketchy, but I think it works. Presumably, if there is checking for type bounds added later, it can first check nested requirements, and see if they're satisfied by the current `ParamEnv`.~~

Changed the diagnostic to add a better example, which is more practical than what was previously proposed.

r? `@lcnr`
jackh726 added a commit to jackh726/rust that referenced this pull request Feb 2, 2021
Add better diagnostic for unbounded Abst. Const

~~In the case where a generic abst. const requires a trivial where bound: `where TypeWithConst<const_fn(N)>: ,`,
instead of requiring a where bound, just check that only consts are being substituted in to skip over where check.~~

~~This is pretty sketchy, but I think it works. Presumably, if there is checking for type bounds added later, it can first check nested requirements, and see if they're satisfied by the current `ParamEnv`.~~

Changed the diagnostic to add a better example, which is more practical than what was previously proposed.

r? ``@lcnr``
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 2, 2021
Rollup of 14 pull requests

Successful merges:

 - rust-lang#80593 (Upgrade Chalk)
 - rust-lang#81260 (Add .editorconfig)
 - rust-lang#81455 (Add AArch64 big-endian and ILP32 targets)
 - rust-lang#81517 (Remove remnants of the santizer runtime crates from bootstrap)
 - rust-lang#81530 (sys: use `process::abort()` instead of `arch::wasm32::unreachable()`)
 - rust-lang#81544 (Add better diagnostic for unbounded Abst. Const)
 - rust-lang#81588 (Add doc aliases for "delete")
 - rust-lang#81603 (rustbuild: Don't build compiler twice for error-index-generator.)
 - rust-lang#81634 (Add long explanation e0521)
 - rust-lang#81636 (Directly use `Option<&[T]>` instead of converting from `Option<&Vec<T>>` later on)
 - rust-lang#81647 (Fix bug with assert!() calling the wrong edition of panic!().)
 - rust-lang#81655 (Improve wording of suggestion about accessing field)
 - rust-lang#81665 (Fix out of date `Scalar` documentation)
 - rust-lang#81671 (Add more associated type tests)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 3aed8b1 into rust-lang:master Feb 3, 2021
@rustbot rustbot added this to the 1.51.0 milestone Feb 3, 2021
@JulianKnodt JulianKnodt deleted the sat_where branch February 3, 2021 14:09
@lcnr lcnr added the A-const-generics Area: const generics (parameters and arguments) label Dec 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants