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

make `CStr::from_bytes_with_nul_unchecked()` a const fn #54745

Merged
merged 2 commits into from Oct 3, 2018

Conversation

Projects
None yet
5 participants
@abonander
Contributor

abonander commented Oct 2, 2018

closes #54678

@rust-highfive

This comment has been minimized.

Show comment
Hide comment
@rust-highfive

rust-highfive Oct 2, 2018

Collaborator

r? @dtolnay

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

Collaborator

rust-highfive commented Oct 2, 2018

r? @dtolnay

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

@abonander

This comment has been minimized.

Show comment
Hide comment
@abonander

abonander Oct 2, 2018

Contributor

Not sure if this needs a test to confirm the ability to use this in a const, I guess as a regression test if this were to be removed.

Contributor

abonander commented Oct 2, 2018

Not sure if this needs a test to confirm the ability to use this in a const, I guess as a regression test if this were to be removed.

@rust-highfive

This comment has been minimized.

Show comment
Hide comment
@rust-highfive

rust-highfive Oct 2, 2018

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:04:58]    Compiling alloc v0.0.0 (/checkout/src/liballoc)
[00:04:59]    Compiling alloc_system v0.0.0 (/checkout/src/liballoc_system)
[00:04:59]    Compiling panic_abort v0.0.0 (/checkout/src/libpanic_abort)
[00:05:03]    Compiling panic_unwind v0.0.0 (/checkout/src/libpanic_unwind)
[00:05:08] error: call to unsafe function is unsafe and unsafe operations are not allowed in const fn
[00:05:08]      |
[00:05:08]      |
[00:05:08] 1044 |         mem::transmute(bytes)
[00:05:08]      |         ^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
[00:05:08]      |
[00:05:08]      = note: consult the function's documentation for information on how to avoid undefined behavior
[00:05:08] error: aborting due to previous error
[00:05:08] 
[00:05:08] error: Could not compile `std`.
[00:05:08] 
[00:05:08] 
[00:05:08] To learn more, run the command again with --verbose.
[00:05:08] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "panic-unwind jemalloc backtrace" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "--message-format" "json"
[00:05:08] expected success, got: exit code: 101
[00:05:08] thread 'main' panicked at 'cargo must succeed', bootstrap/compile.rs:1112:9
[00:05:08] travis_fold:end:stage0-std

[00:05:08] travis_time:end:stage0-std:start=1538477459977074430,finish=1538477497042180674,duration=37065106244

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)

Collaborator

rust-highfive commented Oct 2, 2018

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

Click to expand the log.
[00:04:58]    Compiling alloc v0.0.0 (/checkout/src/liballoc)
[00:04:59]    Compiling alloc_system v0.0.0 (/checkout/src/liballoc_system)
[00:04:59]    Compiling panic_abort v0.0.0 (/checkout/src/libpanic_abort)
[00:05:03]    Compiling panic_unwind v0.0.0 (/checkout/src/libpanic_unwind)
[00:05:08] error: call to unsafe function is unsafe and unsafe operations are not allowed in const fn
[00:05:08]      |
[00:05:08]      |
[00:05:08] 1044 |         mem::transmute(bytes)
[00:05:08]      |         ^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
[00:05:08]      |
[00:05:08]      = note: consult the function's documentation for information on how to avoid undefined behavior
[00:05:08] error: aborting due to previous error
[00:05:08] 
[00:05:08] error: Could not compile `std`.
[00:05:08] 
[00:05:08] 
[00:05:08] To learn more, run the command again with --verbose.
[00:05:08] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "panic-unwind jemalloc backtrace" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "--message-format" "json"
[00:05:08] expected success, got: exit code: 101
[00:05:08] thread 'main' panicked at 'cargo must succeed', bootstrap/compile.rs:1112:9
[00:05:08] travis_fold:end:stage0-std

[00:05:08] travis_time:end:stage0-std:start=1538477459977074430,finish=1538477497042180674,duration=37065106244

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)

@abonander

This comment has been minimized.

Show comment
Hide comment
@abonander

abonander Oct 2, 2018

Contributor

@oli-obk little snag with const_transmute here

Contributor

abonander commented Oct 2, 2018

@oli-obk little snag with const_transmute here

@oli-obk

This comment has been minimized.

Show comment
Hide comment
@oli-obk

oli-obk Oct 2, 2018

Contributor

Not sure if this needs a test to confirm the ability to use this in a const, I guess as a regression test if this were to be removed.

A test would be great, yes.

Contributor

oli-obk commented Oct 2, 2018

Not sure if this needs a test to confirm the ability to use this in a const, I guess as a regression test if this were to be removed.

A test would be great, yes.

@abonander

This comment has been minimized.

Show comment
Hide comment
@abonander

abonander Oct 2, 2018

Contributor
Contributor

abonander commented Oct 2, 2018

@rust-highfive rust-highfive assigned oli-obk and unassigned dtolnay Oct 2, 2018

@@ -1040,7 +1040,8 @@ impl CStr {
/// ```
#[inline]
#[stable(feature = "cstr_from_bytes", since = "1.10.0")]
pub unsafe fn from_bytes_with_nul_unchecked(bytes: &[u8]) -> &CStr {
#[rustc_const_unstable]
pub const unsafe fn from_bytes_with_nul_unchecked(bytes: &[u8]) -> &CStr {

This comment has been minimized.

@abonander

abonander Oct 2, 2018

Contributor

@oli-obk preferred ordering of the attributes? shortest to longest or doesn't really matter?

@abonander

abonander Oct 2, 2018

Contributor

@oli-obk preferred ordering of the attributes? shortest to longest or doesn't really matter?

This comment has been minimized.

@oli-obk

oli-obk Oct 2, 2018

Contributor

I don't think it matters. I ususally put the const unstable attribute below the stable attribute

@oli-obk

oli-obk Oct 2, 2018

Contributor

I don't think it matters. I ususally put the const unstable attribute below the stable attribute

This comment has been minimized.

@abonander

abonander Oct 2, 2018

Contributor

Done, and added it to the crate feature flags as well.

@abonander

abonander Oct 2, 2018

Contributor

Done, and added it to the crate feature flags as well.

@rust-highfive

This comment has been minimized.

Show comment
Hide comment
@rust-highfive

rust-highfive Oct 2, 2018

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:04:52]    Compiling alloc v0.0.0 (/checkout/src/liballoc)
[00:04:53]    Compiling alloc_system v0.0.0 (/checkout/src/liballoc_system)
[00:04:53]    Compiling panic_abort v0.0.0 (/checkout/src/libpanic_abort)
[00:04:57]    Compiling panic_unwind v0.0.0 (/checkout/src/libpanic_unwind)
[00:04:59] error[E0548]: incorrect stability attribute type
[00:04:59]      |
[00:04:59] 1043 |     #[rustc_const_unstable]
[00:04:59]      |     ^^^^^^^^^^^^^^^^^^^^^^^
[00:04:59] 
---
[00:05:01] 
[00:05:01] To learn more, run the command again with --verbose.
[00:05:01] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "panic-unwind jemalloc backtrace" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "--message-format" "json"
[00:05:01] expected success, got: exit code: 101
[00:05:01] thread 'main' panicked at 'cargo must succeed', bootstrap/compile.rs:1112:9
[00:05:01] travis_fold:end:stage0-std

[00:05:01] travis_time:end:stage0-std:start=1538479266326394735,finish=1538479303466363965,duration=37139969230


[00:05:01] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap build
[00:05:01] Build completed unsuccessfully in 0:00:38
[00:05:01] make: *** [all] Error 1
[00:05:01] Makefile:28: recipe for target 'all' failed

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:08ccbdf5
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
---
travis_time:end:26a7a514:start=1538479304164944651,finish=1538479304170228523,duration=5283872
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:072432a7
$ 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:03aefab2
travis_time:start:03aefab2
$ 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:0965d8e0
$ 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)

Collaborator

rust-highfive commented Oct 2, 2018

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

Click to expand the log.
[00:04:52]    Compiling alloc v0.0.0 (/checkout/src/liballoc)
[00:04:53]    Compiling alloc_system v0.0.0 (/checkout/src/liballoc_system)
[00:04:53]    Compiling panic_abort v0.0.0 (/checkout/src/libpanic_abort)
[00:04:57]    Compiling panic_unwind v0.0.0 (/checkout/src/libpanic_unwind)
[00:04:59] error[E0548]: incorrect stability attribute type
[00:04:59]      |
[00:04:59] 1043 |     #[rustc_const_unstable]
[00:04:59]      |     ^^^^^^^^^^^^^^^^^^^^^^^
[00:04:59] 
---
[00:05:01] 
[00:05:01] To learn more, run the command again with --verbose.
[00:05:01] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "panic-unwind jemalloc backtrace" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "--message-format" "json"
[00:05:01] expected success, got: exit code: 101
[00:05:01] thread 'main' panicked at 'cargo must succeed', bootstrap/compile.rs:1112:9
[00:05:01] travis_fold:end:stage0-std

[00:05:01] travis_time:end:stage0-std:start=1538479266326394735,finish=1538479303466363965,duration=37139969230


[00:05:01] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap build
[00:05:01] Build completed unsuccessfully in 0:00:38
[00:05:01] make: *** [all] Error 1
[00:05:01] Makefile:28: recipe for target 'all' failed

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:08ccbdf5
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
---
travis_time:end:26a7a514:start=1538479304164944651,finish=1538479304170228523,duration=5283872
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:072432a7
$ 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:03aefab2
travis_time:start:03aefab2
$ 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:0965d8e0
$ 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

This comment has been minimized.

Show comment
Hide comment
@oli-obk

oli-obk Oct 2, 2018

Contributor

@bors r+

Contributor

oli-obk commented Oct 2, 2018

@bors r+

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Oct 2, 2018

Contributor

📌 Commit e0caaec has been approved by oli-obk

Contributor

bors commented Oct 2, 2018

📌 Commit e0caaec has been approved by oli-obk

pietroalbini added a commit to pietroalbini/rust that referenced this pull request Oct 2, 2018

Rollup merge of rust-lang#54745 - abonander:cstr-const, r=oli-obk
make `CStr::from_bytes_with_nul_unchecked()` a const fn

closes rust-lang#54678

bors added a commit that referenced this pull request Oct 2, 2018

Auto merge of #54763 - pietroalbini:rollup, r=pietroalbini
Rollup of 10 pull requests

Successful merges:

 - #54269 (#53840: Consolidate pattern check errors)
 - #54391 (suggest `crate::...` for "local" paths in 2018)
 - #54603 (Add `crate::` to trait suggestions in Rust 2018.)
 - #54648 (Update Cargo's submodule)
 - #54680 (make run-pass tests with empty main just compile-pass tests)
 - #54687 (Use impl_header_lifetime_elision in libcore)
 - #54699 (Re-export `getopts` so custom drivers can reference it.)
 - #54702 (do not promote comparing function pointers)
 - #54728 (Renumber `proc_macro` tracking issues)
 - #54745 (make `CStr::from_bytes_with_nul_unchecked()` a const fn)

Failed merges:

r? @ghost

pietroalbini added a commit to pietroalbini/rust that referenced this pull request Oct 2, 2018

Rollup merge of rust-lang#54745 - abonander:cstr-const, r=oli-obk
make `CStr::from_bytes_with_nul_unchecked()` a const fn

closes rust-lang#54678

bors added a commit that referenced this pull request Oct 2, 2018

Auto merge of #54767 - pietroalbini:rollup, r=pietroalbini
Rollup of 10 pull requests

Successful merges:

 - #54269 (#53840: Consolidate pattern check errors)
 - #54458 (Allow both explicit and elided lifetimes in the same impl header)
 - #54603 (Add `crate::` to trait suggestions in Rust 2018.)
 - #54648 (Update Cargo's submodule)
 - #54680 (make run-pass tests with empty main just compile-pass tests)
 - #54687 (Use impl_header_lifetime_elision in libcore)
 - #54699 (Re-export `getopts` so custom drivers can reference it.)
 - #54702 (do not promote comparing function pointers)
 - #54728 (Renumber `proc_macro` tracking issues)
 - #54745 (make `CStr::from_bytes_with_nul_unchecked()` a const fn)

Failed merges:

r? @ghost

@bors bors merged commit e0caaec into rust-lang:master Oct 3, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment