Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow panicking with string literal messages inside constants #52011

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Jul 3, 2018

r? @eddyb

cc #51999

we can't implement things like panic!("foo: {}", x) right now because we can't call trait methods (most notably Display::fmt) inside constants. Also most of these impls probably have loops and conditions, so it's messy anyway.

But hey panic!("foo") works at least.

cc @japaric got any test ideas for #![no_std]?

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

This comment has been minimized.

@oli-obk oli-obk force-pushed the dont_you_hate_it_too_when_everything_panics_constantly branch from 70760f5 to a26713a Compare July 3, 2018 10:08
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 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:47:25] .........................i..........................................................................
[00:47:29] ................................................................................................i...
[00:47:33] ....................................................................................................
[00:47:39] ....................................................................................................
[00:47:44] ..............................................................................F.....................
[00:47:55] ....................................................................................................
[00:48:02] ....................................................................................................
[00:48:07] .i..................................................................................................
[00:48:13] i..ii...............................................................................................
---
[00:48:49] ---- [compile-fail] compile-fail/issue-32829.rs stdout ----
[00:48:49] 
[00:48:49] error: compiler panicked
[00:48:49] status: exit code: 101
[00:48:49] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/compile-fail/issue-32829.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/issue-32829/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/issue-32829/auxiliary" "-A" "unused"
[00:48:49] ------------------------------------------
[00:48:49] 
[00:48:49] ------------------------------------------
[00:48:49] stderr:
[00:48:49] stderr:
[00:48:49] ------------------------------------------
[00:48:49] {"message":"could not evaluate static initializer","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\nenumstart":1,"highlight_end":31},{"text":"$ msg , & ( file ! (  ) , line ! (  ) , __rust_unstable_column ! (  ) ) ) } )","highlight_start":1,"highlight_end":78},{"text":"; ( $ msg : expr , ) => ( { panic ! ( $ msg ) } ) ; (","highlight_start":1,"highlight_end":54},{"text":"$ fmt : expr , $ ( $ arg : tt ) + ) => (","highlight_start":1,"highlight_end":41},{"text":"{","highlight_start":1,"highlight_end":2},{"text":"$ crate :: rt :: begin_panic_fmt (","highlight_start":1,"highlight_end":35},{"text":"& format_args ! ( $ fmt , $ ( $ arg ) + ) , & (","highlight_start":1,"highlight_end":48},{"text":"file ! (  ) , line ! (  ) , __rust_unstable_column ! (  ) ) ) } ) ;","highlight_start":1,"highlight_end":68}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}}}],"children":[],"rendered":"error[E0080]: could not evaluate static initializer\n  --> /checkout/src/test/compile-fail/issue-32829.rs:11:22\n   |\nLL | static S : u64 = { { panic!(\"foo\"); 0 } };\n   |                      ^^^^^^^^^^^^^^ the evaluated program panicked at 'foo', /checkout/src/test/compile-fail/issue-32829.rs:11:22\n   |\n   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)\n\n"}
[00:48:49] {"message":"could not evaluate static initializer","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":"<panic macros>","byte_start":71,"byte_end":175,"line_start":3,"line_end":4,"column_start":1,"column_end":74,"is_primary":false,"text":[{"text":"$ crate :: rt :: begin_panic (","highlight_start":1,"highlight_end":31},{"text":"$ msg , & ( file ! (  ) , line ! (  ) , __rust_unstable_column ! (  ) ) ) } )","highlight_start":1,"highlight_end":74}],"label":"the evaluated program panicked at 'foo', /checkout/src/test/compile-fail/issue-32829.rs:11:22","suggested_replacement":null,"suggestion_applicability":null,"expansion":{"span":{"file_name":"/checkout/src/test/compile-fail/issue-32829.rs","byte_start":488,"byte_end":502,"line_start":11,"line_end":11,"column_start":22,"column_end":36,"is_primary":false,"text":[{"text":"static S : u64 = { { panic!(\"foo\"); 0 } };","highlight_start":22,"highlight_end":36}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null},"macro_decl_name":"panic!","def_site_span":{"file_name":"<panic macros>","byte_start":0,"byte_end":427,"line_start":1,"line_end":10,"column_start":1,"column_end":68,"is_primary":false,"text":[{"text":"(  ) => ( { panic ! ( \"explicit panic\" ) } ) ; ( $ msg : expr ) => (","highlight_start":1,"highlight_end":69},{"text":"{","highlight_start":1,"highlight_end":2},{"text":"$ crate :: rt :: begin_panic (","highlight_start":1,"highlight_end":31},{"text":"$ msg , & ( file ! (  ) , line ! (  ) , __rust_unstable_column ! (  ) ) ) } )","highlight_start":1,"highlight_end":78},{"text":"; ( $ msg : expr , ) => ( { panic ! ( $ msg ) } ) ; (","highlight_start":1,"highlight_end":54},{"text":"$ fmt : expr , $ ( $ arg : tt ) + ) => (","highlight_start":1,"highlight_end":41},{"text":"{","highlight_start":1,"highlight_end":2},{"text":"$ crate :: rt :: begin_panic_fmt (","highlight_start":1,"highlight_end":35},{"text":"& format_args ! ( $ fmt , $ ( $ arg ) + ) , & (","highlight_start":1,"highlight_end":48},{"text":"file ! (  ) , line ! (  ) , __rust_unstable_column ! (  ) ) ) } ) ;","highlight_start":1,"highlight_end":68}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}}},{"file_name":"/checkout/src/test/compile-fail/issue-32829.rs","byte_start":467,"byte_end":509,"line_start":11,"line_end":11,"column_start":1,"column_end":43,"is_primary":true,"text":[{"text":"static S : u64 = { { panic!(\"foo\"); 0 } };","highlight_start":1,"highlight_end":43}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"error[E0080]: could not evaluate static initializer\n  --> /checkout/src/test/compile-fail/issue-32829.rs:11:1\n   |\nLL | static S : u64 = { { panic!(\"foo\"); 0 } };\n   | ^^^^^^^^^^^^^^^^^^^^^--------------^^^^^^^\n   |                      |\n   |                      the evaluated program panicked at 'foo', /checkout/src/test/compile-fail/issue-32829.rs:11:22\n   |\n   = note: this error originates in a macro outside of the current crate (in Nightly buiown-linux-gnu" "--mode" "compile-fail" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-3.9/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" "3.9.1\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[00:48:49] 
[00:48:49] 
[00:48:49] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[00:48:49] Build completed unsuccessfully in 0:12:24
[00:48:49] Build completed unsuccessfully in 0:12:24
[00:48:49] Makefile:58: recipe for target 'check' failed
[00:48:49] make: *** [check] Error 1
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:003a9da0
travis_time:start:003a9da0
$ head -30 ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
head: cannot open ‘./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers’ for reading: No such file or directory
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:00ddf536
$ dmesg | grep -i kill

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

@oli-obk
Copy link
Contributor Author

oli-obk commented Jul 3, 2018

lol... uhm... there's a if line.contains(" panicked at ") { check in compiletest. Since my error message contains that, the check thinks that rustc panicked.

This seems very fragile (like if an --explain test message contained that).

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 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.
[01:17:06] travis_fold:start:test_stage1-std
travis_time:start:test_stage1-std
Testing std stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:17:07]    Compiling std v0.0.0 (file:///checkout/src/libstd)
[01:17:11] error[E0152]: duplicate lang item found: `begin_panic`.
[01:17:11]     |
[01:17:11]     |
[01:17:11] 402 | / pub fn begin_panic<M: Any + Send>(msg: M, file_line_col: &(&'static str, u32, u32)) -> ! {
[01:17:11] 403 | |     // Note that this should be the only allocation performed in this code path.
[01:17:11] 404 | |     // Currently this means that panic!() on OOM will invoke this code path,
[01:17:11] 405 | |     // but then again we're not really ready for panic on OOM anyway. If
[01:17:11] 437 | |     }
[01:17:11] 438 | | }
[01:17:11]     | |_^
[01:17:11]     |
[01:17:11]     |
[01:17:11]     = note: first defined in crate `std`.
[01:17:11] error: aborting due to previous error
[01:17:11] 
[01:17:11] For more information about this error, try `rustc --explain E0152`.
[01:17:11] error: Could not compile `std`.
[01:17:11] error: Could not compile `std`.
[01:17:11] 
[01:17:11] To learn more, run the command again with --verbose.
[01:17:11] 
[01:17:11] 
[01:17:11] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "test" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "panic-unwind jemalloc backtrace" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "-p" "std" "--" "--quiet"
[01:17:11] 
[01:17:11] 
[01:17:11] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:17:11] Build completed unsuccessfully in 0:34:12
[01:17:11] Build completed unsuccessfully in 0:34:12
[01:17:11] Makefile:58: recipe for target 'check' failed
[01:17:11] make: *** [check] Error 1

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:0fc58b90
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
---
travis_time:end:03730400:start=1530626213106057275,finish=1530626213113776165,duration=7718890
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:0fd23154
$ head -30 ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
head: cannot open ‘./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers’ for reading: No such file or directory
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:0f39f84f
$ 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)

@japaric
Copy link
Member

japaric commented Jul 5, 2018

@oli-obk I would test this both in rlib context and in binary context as the later requires the panic_impl lang item. The tests would look like this:

#![no_std]
#![crate_type = "lib"]

const Z: () = panic!("cheese");

const Y: () = unreachable!();

const X: () = unimplemented!();
#![crate_type = "bin"]
#![feature(lang_items)]
#![feature(panic_implementation)]
#![no_main]
#![no_std]

use core::panic::PanicInfo;

const Z: () = panic!("cheese");

const Y: () = unreachable!();

const X: () = unimplemented!();

#[lang = "eh_personality"]
fn eh() {}

#[panic_implementation]
fn panic(_info: &PanicInfo) -> ! {
    loop {}
}

core::panic! calls different functions than std::panic! so you may need another lang item.

@oli-obk
Copy link
Contributor Author

oli-obk commented Jul 6, 2018

core::panic! calls different functions than std::panic! so you may need another lang item.

I already had it implemented. I just failed at building the test cases

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 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:03:37] travis_fold:start:tidy
travis_time:start:tidy
tidy check
[00:03:37] tidy error: /checkout/src/test/ui/const-eval/const_panic_libcore_main.rs: missing trailing newline
[00:03:37] tidy error: /checkout/src/test/ui/const-eval/const_panic_libcore.rs: missing trailing newline
[00:03:38] some tidy checks failed
[00:03:38] 
[00:03:38] 
[00:03:38] 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:38] 
[00:03:38] 
[00:03:38] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:03:38] Build completed unsuccessfully in 0:00:47
[00:03:38] Build completed unsuccessfully in 0:00:47
[00:03:38] Makefile:79: recipe for target 'tidy' failed
[00:03:38] make: *** [tidy] Error 1

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:0a6a4fda
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
---
travis_time:end:0de69f3e:start=1530877447332960667,finish=1530877447340223048,duration=7262381
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:00e7a509
$ head -30 ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
head: cannot open ‘./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers’ for reading: No such file or directory
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:1ba04810
$ 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 dont_you_hate_it_too_when_everything_panics_constantly branch from 957ea32 to 203453a Compare July 6, 2018 11:55
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 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:57:01] ........................i...........................................................................
[00:57:06] ...............................................................................................i....
[00:57:10] ....................................................................................................
[00:57:17] ....................................................................................................
[00:57:23] .............................................................................F......................
[00:57:36] ....................................................................................................
[00:57:45] ....................................................................................................
[00:57:50] i..................................................................................................i
[00:57:57] ..ii................................................................................................
---
[00:58:41] error: /checkout/src/test/compile-fail/issue-32829.rs:11: expected error not found: could not evaluate static initializer
[00:58:41] 
[00:58:41] error: 0 unexpected errors found, 1 expected errors not found
[00:58:41] status: exit code: 101
[00:58:41] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/compile-fail/issue-32829.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/issue-32829/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/issue-32829/auxiliary" "-A" "unused"
[00:58:41]     Error {
[00:58:41]         line_num: 11,
[00:58:41]         kind: Some(
[00:58:41]             Error
[00:58:41]             Error
[00:58:41]         ),
[00:58:41]         msg: "could not evaluate static initializer"
[00:58:41] ]
[00:58:41] 
[00:58:41] 
[00:58:41] thread '[compile-fail] compile-fail/issue-32829.rs' panicked at 'explicit panic', tools/cndroid-cross-path" "" "--color" "always"
[00:58:41] 
[00:58:41] 
[00:58:41] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[00:58:41] Build completed unsuccessfully in 0:14:55
[00:58:41] Build completed unsuccessfully in 0:14:55
[00:58:41] Makefile:58: recipe for target 'check' failed
[00:58:41] make: *** [check] Error 1

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:22a8c3ec
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)

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 dont_you_hate_it_too_when_everything_panics_constantly branch from 203453a to 180df96 Compare July 6, 2018 14:33
@bors
Copy link
Contributor

bors commented Jul 11, 2018

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

msg: String,
line: u32,
col: u32,
file: String,
Copy link
Member

Choose a reason for hiding this comment

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

You want to use Symbol for msg and file.

let len = len.to_bits(ecx.memory.pointer_size())?;
let bytes = ecx.memory.read_bytes(ptr, Size::from_bytes(len as u64))?;
let str = ::std::str::from_utf8(bytes).map_err(|err| EvalErrorKind::ValidationFailure(err.to_string()))?;
Ok(str.to_string())
Copy link
Member

Choose a reason for hiding this comment

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

... and intern to Symbol here, without allocating a copy of the string slice!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, because the original value also came from a symbol? Or for making cloning the error cheap?

}
}

fn to_num<'a, 'tcx, 'mir>(
Copy link
Member

Choose a reason for hiding this comment

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

This could be named to_u32.

#![no_std]
#![crate_type = "lib"]

const Z: () = panic!("cheese");
Copy link
Member

Choose a reason for hiding this comment

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

This appears to require no feature-gate - I don't think this should be insta-stable. Or is it impossible to feature-gate because panic! has allow_internal_unstable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Curious. I should be able to work around this easily. Maybe const stability of const fns should not be allowed to be circumvented by rustc macros?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried. I have no idea how this test is still passing. We seem to be having a stability hole.

LL | const Z: () = panic!("cheese");
| ^^^^^^^^^^^^^^----------------^
| |
| evaluated panic invocation 'cheese', $DIR/const_panic_libcore.rs:14:15
Copy link
Member

Choose a reason for hiding this comment

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

"evaluated" doesn't feel right in user output. Maybe mimick the runtime output and say:

panicked at 'cheese', $DIR/const_panic_libcore.rs:14:15

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had that. Our test suite is not able to cope with that because it greps for panicked at and reports a compiler panic. Once the test suite is adjusted, I can fix the message

Copy link
Member

Choose a reason for hiding this comment

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

Maybe something like const panic at 'cheese' instead?

Copy link
Member

Choose a reason for hiding this comment

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

Why not just change the test suite to search for ' panicked at ', i.e. take advantage of the fact that there should be a non-space character before the space before "panicked"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Once #52197 is merged we don't need any more text hacks. I'll just wait for that

@eddyb
Copy link
Member

eddyb commented Jul 12, 2018

cc @alexcrichton @nikomatsakis on #52011 (comment) (insta-stable feature)

@oli-obk oli-obk force-pushed the dont_you_hate_it_too_when_everything_panics_constantly branch from 180df96 to 188e451 Compare July 12, 2018 14:53
@eddyb eddyb added the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Jul 13, 2018
@kennytm
Copy link
Member

kennytm commented Jul 14, 2018

(For easy checking: this PR is blocked on #52197.)

@bors
Copy link
Contributor

bors commented Jul 15, 2018

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

@oli-obk oli-obk force-pushed the dont_you_hate_it_too_when_everything_panics_constantly branch from 188e451 to 6633df0 Compare July 19, 2018 16:36
@oli-obk oli-obk removed the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Jul 19, 2018
@oli-obk
Copy link
Contributor Author

oli-obk commented Jul 19, 2018

Unblocked and fixed

@pietroalbini
Copy link
Member

Ping from triage @eddyb! This PR needs your review.

@pietroalbini
Copy link
Member

Ping from triage! This PR needs a review, can @eddyb or someone else from @rust-lang/compiler review this?

Also @oli-obk, there are a few merge conflicts you should address.

@bors bors added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 18, 2018
@bjorn3
Copy link
Member

bjorn3 commented Aug 18, 2018

Failure log:
[...]
failures:
---- [ui] ui\const-eval\const_panic_libcore_main.rs stdout ----
diff of stderr:
-	error: this constant cannot be used
-	  --> $DIR/const_panic_libcore_main.rs:20:1
-	   |
-	LL | const Z: () = panic!("cheese");
-	   | ^^^^^^^^^^^^^^----------------^
-	   |               |
-	   |               the evaluated program panicked at 'cheese', $DIR/const_panic_libcore_main.rs:20:15
-	   |
-	   = note: #[deny(const_err)] on by default
-	   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
+	error: language item required, but not found: `eh_unwind_resume`
11	
-	error: this constant cannot be used
-	  --> $DIR/const_panic_libcore_main.rs:23:1
-	   |
-	LL | const Y: () = unreachable!();
-	   | ^^^^^^^^^^^^^^--------------^
-	   |               |
-	   |               the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic_libcore_main.rs:23:15
-	   |
-	   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
-	
-	error: this constant cannot be used
-	  --> $DIR/const_panic_libcore_main.rs:26:1
-	   |
-	LL | const X: () = unimplemented!();
-	   | ^^^^^^^^^^^^^^----------------^
-	   |               |
-	   |               the evaluated program panicked at 'not yet implemented', $DIR/const_panic_libcore_main.rs:26:15
-	   |
-	   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
-	
-	error: aborting due to 3 previous errors
+	error: aborting due to previous error
33	
34	
The actual stderr differed from the expected stderr.
[...]
stdout:
------------------------------------------
------------------------------------------
stderr:
------------------------------------------
{"message":"language item required, but not found: `eh_unwind_resume`","code":null,"level":"error","spans":[],"children":[],"rendered":"error: language item required, but not found: `eh_unwind_resume`\n\n"}
{"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error\n\n"}
------------------------------------------
thread '[ui] ui\const-eval\const_panic_libcore_main.rs' panicked at 'explicit panic', tools\compiletest\src\runtest.rs:3189:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.
failures:
    [ui] ui\const-eval\const_panic_libcore_main.rs
[...]

@kennytm kennytm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 18, 2018
@bors
Copy link
Contributor

bors commented Aug 19, 2018

⌛ Testing commit 768ffb714d0ebab8faa9ff6d97307219615016ca with merge 741e7c3c07a2b4a7630b9c35516eec4105991fca...

@bors
Copy link
Contributor

bors commented Aug 19, 2018

💔 Test failed - status-appveyor

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 19, 2018
@kennytm
Copy link
Member

kennytm commented Aug 19, 2018

A lang item is not defined. Same error as #52011 (comment).

 ---- [ui] ui\const-eval\const_panic_libcore_main.rs stdout ----
 diff of stderr:
-	error: this constant cannot be used
-	  --> $DIR/const_panic_libcore_main.rs:20:1
-	   |
-	LL | const Z: () = panic!("cheese");
-	   | ^^^^^^^^^^^^^^----------------^
-	   |               |
-	   |               the evaluated program panicked at 'cheese', $DIR/const_panic_libcore_main.rs:20:15
-	   |
-	   = note: #[deny(const_err)] on by default
-	   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
+	error: language item required, but not found: `eh_unwind_resume`
11	
-	error: this constant cannot be used
-	  --> $DIR/const_panic_libcore_main.rs:23:1
-	   |
-	LL | const Y: () = unreachable!();
-	   | ^^^^^^^^^^^^^^--------------^
-	   |               |
-	   |               the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic_libcore_main.rs:23:15
-	   |
-	   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
-	
-	error: this constant cannot be used
-	  --> $DIR/const_panic_libcore_main.rs:26:1
-	   |
-	LL | const X: () = unimplemented!();
-	   | ^^^^^^^^^^^^^^----------------^
-	   |               |
-	   |               the evaluated program panicked at 'not yet implemented', $DIR/const_panic_libcore_main.rs:26:15
-	   |
-	   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
-	
-	error: aborting due to 3 previous errors
+	error: aborting due to previous error
33	
34	

@kennytm kennytm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 19, 2018
@bors
Copy link
Contributor

bors commented Aug 20, 2018

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

@oli-obk oli-obk force-pushed the dont_you_hate_it_too_when_everything_panics_constantly branch from 768ffb7 to 0db77dd Compare August 22, 2018 16:29
@oli-obk oli-obk force-pushed the dont_you_hate_it_too_when_everything_panics_constantly branch from 0db77dd to bd6ae6a Compare August 22, 2018 16:32
@oli-obk
Copy link
Contributor Author

oli-obk commented Aug 22, 2018

rebased and added lang item to test

@bors r=eddyb

@bors
Copy link
Contributor

bors commented Aug 22, 2018

📌 Commit bd6ae6a has been approved by eddyb

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 22, 2018
} else {
bug!("panic arg is not a str")
}
}
Copy link
Member

Choose a reason for hiding this comment

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

We have that same code in miri...^^

@bors
Copy link
Contributor

bors commented Aug 22, 2018

⌛ Testing commit bd6ae6a with merge 917945d...

bors added a commit that referenced this pull request Aug 22, 2018
…anics_constantly, r=eddyb

Allow panicking with string literal messages inside constants

r? @eddyb

cc #51999

we can't implement things like `panic!("foo: {}", x)` right now because we can't call trait methods (most notably `Display::fmt`) inside constants. Also most of these impls probably have loops and conditions, so it's messy anyway.

But hey `panic!("foo")` works at least.

cc @japaric got any test ideas for `#![no_std]`?
@bors
Copy link
Contributor

bors commented Aug 23, 2018

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

@bors bors merged commit bd6ae6a into rust-lang:master Aug 23, 2018
@bors bors mentioned this pull request Aug 23, 2018
@oli-obk oli-obk deleted the dont_you_hate_it_too_when_everything_panics_constantly branch August 26, 2018 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants