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

Made some functions in time module const #50545

Merged
merged 1 commit into from
May 12, 2018
Merged

Conversation

rizakrko
Copy link
Contributor

@rizakrko rizakrko commented May 8, 2018

They may be const, or i missed something?

@rizakrko rizakrko changed the title Make some functions in time module const Made some functions in time module const May 8, 2018
Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

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

I think it would be good to have some tests for these functions showing various conversions between different duration units

@@ -204,7 +204,7 @@ impl Duration {
/// [`subsec_nanos`]: #method.subsec_nanos
#[stable(feature = "duration", since = "1.3.0")]
#[inline]
pub fn as_secs(&self) -> u64 { self.secs }
pub const fn as_secs(&self) -> u64 { self.secs }
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add #[rustc_const_unstable="duration_getters"] to the newly const-ed functions so they aren't immediately constant on the next stable rust?

@oli-obk oli-obk self-assigned this May 9, 2018
@kennytm kennytm added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label May 9, 2018
@oli-obk
Copy link
Contributor

oli-obk commented May 10, 2018

Oh... I should have explained better. Could you add some tests that do this kind of conversion at compile-time?

So e.g. use it for computing an array length or something weird like that.

@rizakrko
Copy link
Contributor Author

That makes sense. I'l try to come up with something.Also, where should I put these tests?

@oli-obk
Copy link
Contributor

oli-obk commented May 10, 2018

That makes sense. I'l try to come up with something.Also, where should I put these tests?

I usually throw them into https://github.com/rust-lang/rust/tree/master/src/test/ui/const-eval as a // compile-pass test (https://github.com/rust-lang/rust/blob/master/src/test/ui/const-eval/const_signed_pat.rs is an example)

// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-pass
Copy link
Contributor

Choose a reason for hiding this comment

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

is this test passing without a feature attribute?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for that, it should not pass. I will update PR

@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]    Compiling env_logger v0.5.8
[00:47:25]    Compiling rustfix v0.2.0
[00:47:29]    Compiling compiletest v0.0.0 (file:///checkout/src/tools/compiletest)
[00:47:54] ..................................................................................i.................
[00:48:00] .............F...................i..................................................................
[00:48:08] ....................................................................................................
[00:48:11] ....................................................................................................
[00:48:15] ....................................................................................................
[00:48:27] ....................................................................................................
---
[00:49:04] failures:
[00:49:04] 
[00:49:04] ---- [ui] ui/const-eval/duration_conversion.rs stdout ----
[00:49:04]  
[00:49:04] error: test compilation failed although it shouldn't!
[00:49:04] status: exit code: 101
[00:49:04] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/const-eval/duration_conversion.rs" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--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/const-eval/duration_conversion.stage2-x86_64-unknown-linux-gnu" "-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/const-eval/duration_conversion.stage2-x86_64-unknown-linux-gnu.aux" "-A" "unused"
[00:49:04] ------------------------------------------
[00:49:04] 
[00:49:04] ------------------------------------------
[00:49:04] stderr:
[00:49:04] stderr:
[00:49:04] ------------------------------------------
[00:49:04] {"message":"`std::time::Duration::as_secs` is not yet stable as a const fn","code":null,"level":"error","spans":[{"file_name":"/checkout/src/test/ui/const-eval/duration_conversion.rs","byte_start":820,"byte_end":841,"line_start":20,"line_end":20,"column_start":25,"column_end":46,"is_primary":true,"text":[{"text":"    const _ONE: usize = _ONE_SECOND.as_secs() as usize;","highlight_start":25,"highlight_end":46}],"label":null,"suggested_replacement":null,"expansion":null}],"children":[{"message":"in Nightly builds, add `#![feature(duration_getters)]` to the crate attributes to enable","code":null,"level":"help","spans":[],"children":[],"rendered":null}],"rendered":"error: `std::time::Duration::as_secs` is not yet stable as a const fn\n  --> /checkout/src/test/ui/const-eval/duration_conversion.rs:20:25\n   |\nLL |     const _ONE: usize = _ONE_SECOND.as_secs() as usize;\n   |                         ^^^^^^^^^^^^^^^^^^^^^\n   |\n   = help: in Nightly builds, add `#![feature(duration_getters)]` to the crate attributes to enable\n\n"}
[00:49:04] {"message":"`std::time::Duration::subsec_millis` is not yet stable as a const fn","code":null,"level":"error","spans":[{"file_name":"/checkout/src/test/ui/const-eval/duration_conversion.rs","byte_start":876,"byte_end":908,"line_start":21,"line_end":21,"column_start":25,"column_end":57,"is_primary":true,"text":[{"text":"    const _TWO: usize = _ONE_MILLISECOND.subsec_millis() as usize;","highlight_start":25,"highlight_end":57}],"label":null,"suggested_replacement":null,"expansion":null}],"children":[{"message":"in Nightly builds, add `#![feature(duration_getters)]` to the crate attributes to enable","code":null,"level":"help","spans":[],"children":[],"rendered":null}],"rendered":"error: `std::time::Duration::subsec_millis` is not yet stable as a const fn\n  --> /checkout/src/test/ui/const-eval/duration_conversion.rs:21:25\n   |\nLL |     const _TWO: usize = _ONE_MILLISECOND.subsec_millis() as usize;\n   |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n   |\n   = help: in Nightly builds, add `#![feature(duration_getters)]` to the crate attributes to enable\n\n"}
[00:49:04] {"message":"`std::time::Duration::subsec_micros` is not yet stable as a const fn","code":null,"level":"error","spans":[{"file_name":"/checkout/src/test/ui/const-eval/duration_conversion.rs","byte_start":945,"byte_end":977,"line_start":22,"line_end":22,"column_start":27,"column_end":59,"is_primary":true,"text":[{"text":"    const _THREE: usize = _ONE_MICROSECOND.subsec_micros() as usize;","highlight_start":27,"highlight_end":59}],"label":null,"suggested_replacement":null,"expansion":null}],"children":[{"message":"in Nightly builds, add `#![feature(duration_getters)]` to the crate attributes to enable","code":null,"level":"help","spans":[],"children":[],"rendered":null}],"rendered":"error: `std::time::Duration::subsec_micros` is not yet stable as a const fn\n  --> /checkout/src/test/ui/const-eval/duration_conversion.rs:22:27\n   |\nLL |     const _THREE: usize = _ONE_MICROSECOND.subsec_micros() as usize;\n   |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n   |\n   = help: in Nightly builds, add `#![feature(duration_getters)]` to the crate attributes to enable\n\n"}
[00:49:04] {"message":"`std::time::Duration::subsec_nanos` is not yet stable as a const fn","code":null,"level":"error","spans":[{"file_name":"/checkout/src/test/ui/const-eval/duration_conversion.rs","byte_start":1013,"byte_end":1043,"line_start":23,"line_end":23,"column_start":26,"column_end":56,"is_primary":true,"text":[{"text":"    const _FOUR: usize = _ONE_NANOSECOND.subsec_nanos() as usize;","highlight_start":26,"highlight_end":56}],"label":null,"suggested_replacement":null,"expansion":null}],"children":[{"message":"in Nightly builds, add `#![feature(duration_getters)]` to the crate attributes to enable","code":null,"level":"help","spans":[],"children":[],"rendered":null}],"rendered":"error: `std::time::Duration::subsec_nanos` is not yet stable as a const fn\n  --> /checkout/src/test/ui/const-eval/duration_conversion.rs:23:26\n   |\nLL |     const _FOUR: usize = _ONE_NANOSECOND.subsec_nanos() as usize;\n   |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n   |\n   = help: in Nightly builds, add `#![feature(duration_getters)]` to the crate attributes to enable\n\n"}
[00:49:04] {"message":"aborting due to 4 previous errors","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to 4 previous errors\n\n"}
[00:49:04] ------------------------------------------
[00:49:04] 
[00:49:04] thread '[ui] ui/const-eval/duration_conversion.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:3033:9
[00:49:04] note: Run with `RUST_BACKTRACE=1` for a backtrace.
---
[00:49:04] 
[00:49:04] thread 'main' panicked at 'Some tests failed', tools/compiletest/src/main.rs:492:22
[00:49:04] 
[00:49:04] 
[00:49:04] 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-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:49:04] 
[00:49:04] 
[00:49:04] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[00:49:04] Build completed unsuccessfully in 0:02:36
[00:49:04] Build completed unsuccessfully in 0:02:36
[00:49:04] make: *** [check] Error 1
[00:49:04] Makefile:58: recipe for target 'check' failed

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:3136d883
$ 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
Copy link
Contributor

oli-obk commented May 10, 2018

OK Lgtm now, please squash the commits down to one, then we can send it off to bors

added rustc_const_unstable attribute

extended tests

added conversion test

fixed tidy test

added feature attribute
@oli-obk
Copy link
Contributor

oli-obk commented May 11, 2018

@bors r+

@bors
Copy link
Contributor

bors commented May 11, 2018

📌 Commit 4d8d0a6 has been approved by oli-obk

@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 May 11, 2018
@oli-obk
Copy link
Contributor

oli-obk commented May 11, 2018

@bors rollup

This is not gonna conflict with anything

alexcrichton added a commit to alexcrichton/rust that referenced this pull request May 11, 2018
Made some functions in time module const

They may be const, or i missed something?
kennytm added a commit to kennytm/rust that referenced this pull request May 12, 2018
Made some functions in time module const

They may be const, or i missed something?
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request May 12, 2018
Made some functions in time module const

They may be const, or i missed something?
bors added a commit that referenced this pull request May 12, 2018
Rollup of 13 pull requests

Successful merges:

 - #50544 (Cleanup some dependencies)
 - #50545 (Made some functions in time module const)
 - #50550 (use fmt::Result where applicable)
 - #50558 (Remove all reference to DepGraph::work_products)
 - #50602 (Update canonicalize docs)
 - #50607 (Allocate Symbol strings from an arena)
 - #50613 (Migrate the toolstate update bot to rust-highfive)
 - #50624 (fs::write: Add example writing a &str)
 - #50634 (Do not silently truncate offsets for `read_at`/`write_at` on emscripten)
 - #50644 (AppVeyor: Read back trace from crash dump on failure.)
 - #50661 (Ignore non .rs files for tidy libcoretest)
 - #50663 (rustc: Allow an edition's feature on that edition)
 - #50667 (rustc: Only suggest deleting `extern crate` if it works)

Failed merges:
@bors bors merged commit 4d8d0a6 into rust-lang:master May 12, 2018
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.

5 participants