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

Wrap cast expressions inside of ValueTypeAscription #54938

Closed
wants to merge 1 commit into from

Conversation

KiChjang
Copy link
Member

@KiChjang KiChjang commented Oct 9, 2018

Fixes #54332.

@rust-highfive
Copy link
Collaborator

r? @zackmdavis

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 9, 2018
@nikomatsakis
Copy link
Contributor

r? @nikomatsakis

@nikomatsakis
Copy link
Contributor

i'm curious to see whether travis is happier now

@rust-highfive
Copy link
Collaborator

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

Click to expand the log.
[00:53:03] .................................................................................................... 300/4577
[00:53:07] .................................................................................................... 400/4577
[00:53:11] .................................................................................................... 500/4577
[00:53:16] .......................i............................................................................ 600/4577
[00:53:23] ..........................F...............................................F......................... 700/4577
[00:53:33] ...................................................iiiii............................................ 900/4577
[00:53:37] .................................................................................................... 1000/4577
[00:53:40] .................................................................................................... 1100/4577
[00:53:43] .................................................................................................... 1200/4577
---
[00:54:48] ....................................i............................................................... 3000/4577
[00:54:51] ................................................................................................i.i. 3100/4577
[00:54:55] .ii................................................................................................. 3200/4577
[00:54:58] .................................................................................................... 3300/4577
[00:55:02] .........F.....................................i.................................................... 3400/4577
[00:55:08] .................................................................................................... 3600/4577
[00:55:11] .................................................................................................... 3700/4577
[00:55:15] ..........................................................................................i......... 3800/4577
[00:55:20] .................................................................................................... 3900/4577
---
[00:55:42] 
[00:55:42] ---- [ui] ui/consts/const-eval/conditional_array_execution.rs stdout ----
[00:55:42] diff of stderr:
[00:55:42] 
[00:55:42] 21 LL |     println!("{}", FOO);
[00:55:42] 23 
[00:55:42] - error[E0080]: erroneous constant used
[00:55:42] + error[E0080]: could not evaluate constant
[00:55:42] 25   --> $DIR/conditional_array_execution.rs:19:20
[00:55:42] 25   --> $DIR/conditional_array_execution.rs:19:20
[00:55:42] 26    |
[00:55:42] 27 LL |     println!("{}", FOO);
[00:55:42] 
[00:55:42] 28    |                    ^^^ referenced constant has errors
[00:55:42] - error: aborting due to 2 previous errors
[00:55:42] + error[E0080]: constant evaluation error
[00:55:42] +   --> $DIR/conditional_array_execution.rs:15:1
[00:55:42] +    |
[00:55:42] +    |
[00:55:42] + LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
[00:55:42] +    |                   |
[00:55:42] +    |                   attempt to subtract with overflow
[00:55:42] + 
[00:55:42] + error: aborting due to 3 previous errors
[00:55:42] + error: aborting due to 3 previous errors
[00:55:42] 31 
[00:55:42] 32 For more information about this error, try `rustc --explain E0080`.
[00:55:42] 33 
[00:55:42] 
[00:55:42] 
[00:55:42] The actual stderr differed from the expected stderr.
[00:55:42] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/const-eval/conditional_array_execution/conditional_array_execution.stderr
[00:55:42] To update references, rerun the tests and pass the `--bless` flag
[00:55:42] To only update this specific test, also pass `--test-args consts/const-eval/conditional_array_execution.rs`
[00:55:42] error: 1 errors occurred comparing output.
[00:55:42] status: exit code: 1
[00:55:42] status: exit code: 1
[00:55:42] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/consts/const-eval/conditional_array_execution.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/ui/consts/const-eval/conditional_array_execution/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/ui/consts/const-eval/conditional_array_execution/auxiliary" "-A" "unused"
[00:55:42] ------------------------------------------
[00:55:42] 
[00:55:42] ------------------------------------------
[00:55:42] stderr:
[00:55:42] stderr:
[00:55:42] ------------------------------------------
[00:55:42] {"message":"this constant cannot be used","code":{"code":"const_err","explanation":null},"level":"warning","spans":[{"file_name":"/checkout/src/test/ui/consts/const-eval/conditional_array_execution.rs","byte_start":542,"byte_end":547,"line_start":15,"line_end":15,"column_start":19,"column_end":24,"is_primary":false,"text":[{"text":"const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];","highlight_start":19,"highlight_end":24}],"label":"attempt to subtract with overflow","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"/checkout/src/test/ui/consts/const-eval/conditional_array_execution.rs","byte_start":524,"byte_end":574,"line_start":15,"line_end":15,"column_start":1,"column_end":51,"is_primary":true,"text":[{"text":"const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];","highlight_start":1,"highlight_end":51}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"lint level defined here","code":null,"level":"note","spans":[{"file_name":"/checkout/src/test/ui/consts/const-eval/conditional_array_execution.rs","byte_start":475,"byte_end":484,"line_start":11,"line_end":11,"column_start":9,"column_end":18,"is_primary":true,"text":[{"text":"#![warn(const_err)]","highlight_start":9,"highlight_end":18}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expaexpansion":null},{"file_name":"/checkout/src/test/ui/consts/const-eval/conditional_array_execution.rs","byte_start":646,"byte_end":649,"line_start":19,"line_end":19,"column_start":20,"column_end":23,"is_primary":true,"text":[{"text":"    println!(\"{}\", FOO);","highlight_start":20,"highlight_end":23}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"error[E0080]: referenced constant has errors\n  --> /checkout/src/test/ui/consts/const-eval/conditional_array_execution.rs:19:20\n   |\nLL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];\n   |                   ----- attempt to subtract with overflow\n...\nLL |     println!(\"{}\", FOO);\n   |                    ^^^\n\n"}
[00:55:42] {"message":"could not evaluate constant","code":{"code":"E0080","explanation":"\nThis error indicates that the compiler was unable to sensibly evaluate an\nconstant expression that had to be evaluated. Attempting to divide by 0\nor causing integer overflow are two ways to induce this error. For example:\n\n```compile_fail,E0080\nenum Enum {\n    X = (1 << 500),\n    Y = (1 / 0)\n}\n```\n\nEnsure that the expressions given can be evaluated as the desired integer type.\nSee the FFI section of the Reference for more information about using a custom\ninteger type:\n\nhttps://doc.rust-lang.org/reference.html#ffi-attributes\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/consts/const-eval/conditional_array_execution.rs","byte_start":646,"byte_end":649,"line_start":19,"line_end":19,"column_start":20,"column_end":23,"is_primary":true,"text":[{"text":"    println!(\"{}\", FOO);","highlight_start":20,"highlight_end":23}],"label":"referenced constant has errors","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"error[E0080]: could not evaluate constant\n  --> /checkout/src/test/ui/consts/const-eval/conditional_array_execution.rs:19:20\n   |\nLL |     println!(\"{}\", FOO);\n   |                    ^^^ referenced constant has errors\n\n"}
[00:55:42] {"message":"constant evaluation error","code":{"code":"E0080","explanation":"\nThis error indicates that the compiler was unable to sensibly evaluate an\nconstant expression that had to be evaluated. Attempting to divide by 0\nor causing integer overflow are two ways to induce this error. For example:\n\n```compile_fail,E0080\nenum Enum {\n    X = (1 << 500),\n    Y = (1 / 0)\n}\n```\n\nEnsure that the expressions given can be evaluated as the desired integer type.\nSee the FFI section of the Reference for more information about using a custom\ninteger type:\n\nhttps://doc.rust-lang.org/reference.html#ffi-attributes\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/consts/const-eval/conditional_array_execution.rs","byte_start":542,"byte_end":547,"line_start":15,"line_end":15,"column_start":19,"column_end":24,"is_primary":false,"text":[{"text":"const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];","highlight_start":19,"highlight_end":24}],"label":"attempt to subtract with overflow","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"/checkout/src/test/ui/consts/const-eval/conditional_array_execution.rs","byte_start":524,"byte_end":574,"lin:42] +   --> $DIR/promoted_errors.rs:24:20
[00:55:42] +    |
[00:55:42] + LL |     println!("{}", 1/(false as u32));
[00:55:42] +    |                    ^^^^^^^^^^^^^^^^ attempt to divide by zero
[00:55:42] + 
[00:55:42] 37 warning: attempt to divide by zero
[00:55:42] 39    |
[00:55:42] 
[00:55:42] 
[00:55:42] The actual stderr differed from the expected stderr.
[00:55:42] The actual stderr differed from the expected stderr.
[00:55:42] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/const-eval/promoted_errors/promoted_errors.stderr
[00:55:42] To update references, rerun the tests and pass the `--bless` flag
[00:55:42] To only update this specific test, also pass `--test-args consts/const-eval/promoted_errors.rs`
[00:55:42] error: 1 errors occurred comparing output.
[00:55:42] status: exit code: 0
[00:55:42] status: exit code: 0
[00:55:42] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/consts/const-eval/promoted_errors.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/ui/consts/const-eval/promoted_errors/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-O" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/const-eval/promoted_errors/auxiliary" "-A" "unused"
[00:55:42] thread 'main' panicked at 'Some tests failed', tools/compiletest/src/main.rs:499:22
[00:55:42] ------------------------------------------
[00:55:42] 
[00:55:42] ------------------------------------------
[00:55:42] stderr:
[00:55:42] stderr:
[00:55:42] ------------------------------------------
[00:55:42] {"message":"this expression will panic at runtime","code":{"code":"const_err","explanation":null},"level":"warning","spans":[{"file_name":"/checkout/src/test/ui/consts/const-eval/promoted_errors.rs","byte_start":580,"byte_end":588,"line_start":17,"line_end":17,"column_start":14,"column_end":22,"is_primary":true,"text":[{"text":"    let _x = 0u32 - 1;","highlight_start":14,"highlight_end":22}],"label":"attempt to subtract with overflow","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"lint level defined here","code":null,"level":"note","spans":[{"file_name":"/checkout/src/test/ui/consts/const-eval/promoted_errors.rs","byte_start":475,"byte_end":484,"line_start":11,"line_end":11,"column_start":9,"column_end":18,"is_primary":true,"text":[{"text":"#![warn(const_err)]","highlight_start":9,"highlight_end":18}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":null}],"rendered":"warning: this expression will panic at runtime\n  --> /checkout/src/test/ui/consts/const-eval/promoted_errors.rs:17:14\n   |\nLL |     let _x = 0u32 - 1;\n   |              ^^^^^^^^ attempt to subtract with overflow\n   |\nnote: lint level defined here\n  --> /checkout/src/test/ui/consts/const-eval/promoted_errors.rs:11:9\n   |\nLL | #![warn(const_err)]\n   |         ^^^^^^^^^\n\n"}
[00:55:42] {"message":"attempt to divide by zero","code":{"code":"const_err","explanation":null},"level":"warning","spans":[{"file_name":"/checkout/src/test/ui/consts/const-eval/promoted_errors.rs","byte_start":633,"byte_end":640,"line_start":19,"line_end":19,"column_start":20,"column_end":27,"is_primary":true,"text":[{"text":"    println!(\"{}\", 1/(1-1));","highlight_start":20,"highlight_end":27}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"warning: attempt to divide by zero\n  --> /checkout/src/test/ui/consts/const-eval/promoted_errors.rs:19:20\n   |\nLL |     println!(\"{}\", 1/(1-1));\n   |                    ^^^^^^^\n\n"}
[00:55:42] {"message":"attempt to divide by zero","code":{"code":"const_err","explanation":null},"level":"warning","spans":[{"file_name":"/checkout/src/test/ui/consts/const-eval/promoted_errors.rs","byte_start":680,"byte_end":687,"line_start":21,"line_end":21,"column_start":14,"column_end":21,"is_primary":true,"text":[{"text":"    let _x = 1/(1-1);","highlight_start":14,"highlight_end":21}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"warning: attempt to divide by zero\n  --> /checkout/src/test/ui/consts/const-eval/promoted_errors.rs:21:14\n   |\nLL |     let _x = 1/(1-1);\n   |              ^^^^^^^\n\n"}
[00:55:42] {"message":"this expression will panic at runtime","code":{"code":"const_err","explanation":null},"level":"warning","spans":[{"file_name":"/checkout/src/test/ui/consts/const-eval/promoted_errors.rs","byte_start":680,"byte_end":687,"line_start":21,"line_end":21,"column_start":14,"column_end":21,"is_primary":true,"text":[{"text":"    let _x = 1/(1-1);","highlight_start":14,"highlight_end":21}],"label":"attempt to divide by zero","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"warning: this expression will panic at runtime\n  --> /checkout/src/test/ui/consts/const-eval/promoted_errors.rs:21:14\n   |\nLL |     let _x = 1/(1-1);\n   |              ^^^^^^^ attempt to divide by zero\n\n"}
[00:55:42] {"message":"attempt to divide by zero","code":{"code":"const_err","explanation":null},"level":"warning","spans":[{"file_name":"/checkout/src/test/ui/consts/const-eval/promoted_errors.rs","byte_start":756,"byte_end":772,"line_start":24,"line_end":24,"column_start":20,"column_end":36,"is_primary":true,"text":[{"text":"    println!(\"{}\", 1/(false as u32));","highlight_start":20,"highlight_end":36}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"warning: attempt to divide by zero\n  --> /checkout/src/test/ui/consts/const-eval/promoted_errors.rs:24:20\n   |\nLL |     println!(\"{}\", 1/(false as u32));\n   |                    ^^^^^^^^^^^^^^^^\n\n"}
[00:55:42] {"message":"this expression will panic at runtime","code":{"code":"const_err","explanation":null},"level":"warning","spans":[{"file_name":"/checkout/src/test/ui/consts/const-eval/promoted_errors.rs","byte_start":756,"byte_end":772,"line_start":24,"line_end":24,"column_start":20,"column_end":36,"is_primary":true,"text":[{"text":"    println!(\"{}\", 1/(false as u32));","highlight_start":20,"highlight_end":36}],"label":"attempt to divide by zero","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[] |\nLL |     let _x = 1/(false as u32);\n   |              ^^^^^^^^^^^^^^^^ attempt to divide by zero\n\n"}
[00:55:42] ------------------------------------------
[00:55:42] 
[00:55:42] thread '[ui] ui/consts/const-eval/promoted_errors.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:3267:9
[00:55:42] 
[00:55:42] 
[00:55:42] ---- [ui] ui/nll/user-annotations/cast_static_lifetime.rs stdout ----
[00:55:42] 
[00:55:42] error: ui test compiled successfully!
[00:55:42] status: exit code: 0
[00:55:42] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/nll/user-annotations/cast_static_lifetime.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/ui/nll/user-annotations/cast_static_lifetime/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/ui/nll/user-annotations/cast_static_lifetime/auxiliary" "-A" "unused"
[00:55:42] ------------------------------------------
[00:55:42] 
[00:55:42] ------------------------------------------
[00:55:42] stderr:
---
[00:55:42] 
[00:55:42] failures:
[00:55:42]     [ui] ui/consts/const-eval/conditebug/bootstrap test
[00:55:42] Build completed unsuccessfully in 0:04:00
[00:55:42] make: *** [check] Error 1
[00:55:42] Makefile:58: recipe for target 'check' failed

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:24d1583a
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
---
travis_time:end:098b245d:start=1539117543898765643,finish=1539117543912926418,duration=14160775
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:0115ff3a
$ 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:0df22160
$ 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)

@nikomatsakis
Copy link
Contributor

Welp, we have our answer. =)

@matthewjasper
Copy link
Contributor

Isn't there an issue open for deduplicating these messages? cc @oli-obk

@oli-obk
Copy link
Contributor

oli-obk commented Oct 9, 2018

Are you looking for #53821 ? that PR deduplicates all const eval error reporting

@nikomatsakis
Copy link
Contributor

Could that be the problem here?

@oli-obk
Copy link
Contributor

oli-obk commented Oct 10, 2018

I don't think so. This change changes the way the HAIR is structured for casts, thus having an effect on the generated MIR. I don't know what effect, but it looks to me like it causes the MIR to mention a constant twice, thus it being evaluated twice via https://github.com/rust-lang/rust/blob/master/src/librustc_mir/transform/const_prop.rs#L256

This can easily be verified by generating the MIR of one of the failing tests before and after this PR.

That said, the mentioned PR will definitely deduplicate this error, but we should probably have a look at why the MIR mentions this constant twice.

@nikomatsakis
Copy link
Contributor

Subsumed into #55152

@oli-obk

but it looks to me like it causes the MIR to mention a constant twice

oh I can definitely imagine how this would happen — we are now adding a MIR annotation that "asserts" that the constant has a given, user-provided type. Is this then "ok"? Maybe answer in #55152 though :P

@bors
Copy link
Contributor

bors commented Oct 19, 2018

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

@KiChjang KiChjang closed this Oct 20, 2018
@KiChjang KiChjang deleted the issue-54332 branch July 14, 2019 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants