-
Notifications
You must be signed in to change notification settings - Fork 13k
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 #[must_use] to all functions 'fn(float) -> float' #63871
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @joshtriplett (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
My impression (confirmed by re-reading the linked issue and others cross-referenced there) was that we don't currently have a precedent for applying |
@rkruppe I personally misused |
I don't have any opinion on whether this should land, but if it does, I'd like there to be a message that makes the error a bit more expressive (something along the lines of |
@killercup That sounds good! How about "...mutate the original value" rather than "caller"? |
I feel like this makes sense, and fits the spirit of I don't know of any general policy for whether we should add @rfcbot merge |
@joshtriplett I think it would be good to continue the discussion in the linked tracking issue and eventually determine a heuristic that Clippy can apply to treat certain types of functions as |
I've added the message discussed above. I've also added One such function, |
The job Click to expand the log.
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 |
Interesting; it looks like `clamp` is being used without using the return
value.
…On Wed, Aug 28, 2019, 11:20 AM Rust highfive robot ***@***.***> wrote:
The job x86_64-gnu-llvm-6.0 of your PR failed
<https://dev.azure.com/rust-lang/rust/_build/results?buildId=6913&view=logs&jobId=d0d954b5-f111-5dc4-4d76-03b6c9d0cf7e>
(raw log
<https://dev.azure.com/rust-lang/e71b0ddf-dd27-435a-873c-e30f86eea377/_apis/build/builds/6913/logs/49>).
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.*
2019-08-28T15:42:35.1416231Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-08-28T15:42:35.1643996Z <https://github.com/rust-lang/rust2019-08-28T15:42:35.1643996Z> ##[command]git config gc.auto 0
2019-08-28T15:42:35.1818089Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-08-28T15:42:35.1896048Z <https://github.com/rust-lang/rust.extraheader2019-08-28T15:42:35.1896048Z> ##[command]git config --get-all http.proxy
2019-08-28T15:42:35.2065713Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/63871/merge:refs/remotes/pull/63871/merge
---
2019-08-28T16:46:00.4040306Z .................................................................................................... 1500/8969
2019-08-28T16:46:06.3208847Z .................................................................................................... 1600/8969
2019-08-28T16:46:19.5727777Z .............................................i...............i...................................... 1700/8969
2019-08-28T16:46:28.1883740Z .................................................................................................... 1800/8969
2019-08-28T16:46:43.0283762Z ....................................iiiii........................................................... 1900/8969
2019-08-28T16:46:54.4033275Z .................................................................................................... 2100/8969
2019-08-28T16:46:57.0661977Z .................................................................................................... 2200/8969
2019-08-28T16:47:01.5411426Z .................................................................................................... 2300/8969
2019-08-28T16:47:09.1004222Z .................................................................................................... 2400/8969
---
2019-08-28T16:50:15.0688482Z .......................i...............i............................................................ 4700/8969
2019-08-28T16:50:27.1544472Z .................................................................................................... 4800/8969
2019-08-28T16:50:33.6882152Z .................................................................................................... 4900/8969
2019-08-28T16:50:44.9591664Z .................................................................................................... 5000/8969
2019-08-28T16:50:50.4001723Z ....ii.ii........................................................................................... 5100/8969
2019-08-28T16:51:05.0707634Z .................................................................................................... 5300/8969
2019-08-28T16:51:12.6433592Z ...................................................................i................................ 5400/8969
2019-08-28T16:51:20.3248160Z .................................................................................................... 5500/8969
2019-08-28T16:51:27.5880059Z .................................................................................................... 5600/8969
2019-08-28T16:51:27.5880059Z .................................................................................................... 5600/8969
2019-08-28T16:51:38.2835392Z .............................................................ii...i..ii...........i................. 5700/8969
2019-08-28T16:52:04.9100807Z .................................................................................................... 5900/8969
2019-08-28T16:52:14.9167931Z .................................................................................................... 6000/8969
2019-08-28T16:52:14.9167931Z .................................................................................................... 6000/8969
2019-08-28T16:52:22.0602498Z ..............................................................i..ii................................. 6100/8969
2019-08-28T16:52:50.8454658Z .................................................................................................... 6300/8969
2019-08-28T16:52:53.1025249Z .................i.................................................................................. 6400/8969
2019-08-28T16:52:55.3296970Z .........................................................................................i.......... 6500/8969
2019-08-28T16:52:58.1492226Z .................................................................................................... 6600/8969
---
2019-08-28T16:57:48.2766523Z finished in 21.888
2019-08-28T16:57:48.2977318Z Check compiletest suite=codegen mode=codegen (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-08-28T16:57:48.8260180Z
2019-08-28T16:57:48.8261035Z running 149 tests
2019-08-28T16:57:51.9096410Z i....iii......iii..iiii....i.............................i..i..................i....i.........ii.i.i 100/149
2019-08-28T16:57:53.9185632Z ..iiii..............i.........iii.i......ii......
2019-08-28T16:57:53.9186127Z
2019-08-28T16:57:53.9190093Z finished in 5.621
2019-08-28T16:57:53.9382574Z Check compiletest suite=codegen-units mode=codegen-units (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-08-28T16:57:54.1012892Z
---
2019-08-28T16:57:56.2285015Z finished in 2.290
2019-08-28T16:57:56.2476844Z Check compiletest suite=assembly mode=assembly (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-08-28T16:57:56.4090429Z
2019-08-28T16:57:56.4091164Z running 9 tests
2019-08-28T16:57:56.4092802Z iiiiiiiii
2019-08-28T16:57:56.4093573Z
2019-08-28T16:57:56.4098390Z finished in 0.162
2019-08-28T16:57:56.4289001Z Check compiletest suite=incremental mode=incremental (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-08-28T16:57:56.5917661Z
---
2019-08-28T16:58:14.8812607Z finished in 18.452
2019-08-28T16:58:14.9006080Z Check compiletest suite=debuginfo mode=debuginfo-gdb+lldb (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-08-28T16:58:15.0668052Z
2019-08-28T16:58:15.0668290Z running 122 tests
2019-08-28T16:58:40.1871805Z .iiiii...i.....i..i...i..i.i.i..i.ii..i.i.....i..i....i..........iiii..........i...ii...i.......ii.i 100/122
2019-08-28T16:58:44.9389986Z .i.i......iii.i.....ii
2019-08-28T16:58:44.9390461Z
2019-08-28T16:58:44.9395059Z finished in 30.039
2019-08-28T16:58:44.9404925Z Uplifting stage1 rustc (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-08-28T16:58:44.9407951Z Copying stage2 rustc from stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
---
2019-08-28T17:13:02.6142835Z
2019-08-28T17:13:02.6143545Z Doc-tests core
2019-08-28T17:13:07.9449659Z
2019-08-28T17:13:07.9455248Z running 2379 tests
2019-08-28T17:13:20.8317847Z ......iiiii......................................................................................... 100/2379
2019-08-28T17:13:33.6255985Z .........................................................................ii......................... 200/2379
2019-08-28T17:14:04.7392363Z .................................................................................................... 400/2379
2019-08-28T17:14:04.7392363Z .................................................................................................... 400/2379
2019-08-28T17:14:16.4858111Z ..............................i..i.................iiii............................................. 500/2379
2019-08-28T17:14:42.1247437Z .................................................................................................... 700/2379
2019-08-28T17:14:55.2519132Z .................................................................................................... 800/2379
2019-08-28T17:15:07.9026516Z .................................................................................................... 900/2379
2019-08-28T17:15:20.7127913Z .................................................................................................... 1000/2379
---
2019-08-28T17:18:40.8366711Z Compiling rand_pcg v0.1.1
2019-08-28T17:18:40.8367188Z Compiling rand_chacha v0.1.0
2019-08-28T17:18:41.2274185Z Compiling rand v0.6.1
2019-08-28T17:18:45.6157653Z Compiling std v0.0.0 (/checkout/src/libstd)
2019-08-28T17:19:11.5044247Z error: unused return value of `realstd::f32::<impl f32>::clamp` that must be used
2019-08-28T17:19:11.5045683Z --> src/libstd/f32.rs:1635:9
2019-08-28T17:19:11.5046242Z |
2019-08-28T17:19:11.5046805Z 1635 | 1.0f32.clamp(3.0, 1.0);
2019-08-28T17:19:11.5047799Z |
2019-08-28T17:19:11.5048328Z = note: `-D unused-must-use` implied by `-D warnings`
2019-08-28T17:19:11.5048328Z = note: `-D unused-must-use` implied by `-D warnings`
2019-08-28T17:19:11.5048903Z = note: method returns a new number and does not mutate the original value
2019-08-28T17:19:11.5049110Z
2019-08-28T17:19:11.5049632Z error: unused return value of `realstd::f32::<impl f32>::clamp` that must be used
2019-08-28T17:19:11.5050146Z --> src/libstd/f32.rs:1641:9
2019-08-28T17:19:11.5050610Z |
2019-08-28T17:19:11.5051127Z 1641 | 1.0f32.clamp(NAN, 1.0);
2019-08-28T17:19:11.5052618Z |
2019-08-28T17:19:11.5052618Z |
2019-08-28T17:19:11.5053162Z = note: method returns a new number and does not mutate the original value
2019-08-28T17:19:11.5053365Z
2019-08-28T17:19:11.5053852Z error: unused return value of `realstd::f32::<impl f32>::clamp` that must be used
2019-08-28T17:19:11.5054337Z --> src/libstd/f32.rs:1647:9
2019-08-28T17:19:11.5054808Z |
2019-08-28T17:19:11.5055349Z 1647 | 1.0f32.clamp(3.0, NAN);
2019-08-28T17:19:11.5056608Z |
2019-08-28T17:19:11.5056608Z |
2019-08-28T17:19:11.5057150Z = note: method returns a new number and does not mutate the original value
2019-08-28T17:19:11.8629187Z error: aborting due to 3 previous errors
2019-08-28T17:19:11.8630009Z
2019-08-28T17:19:12.1287704Z error: Could not compile `std`.
2019-08-28T17:19:12.1287885Z
2019-08-28T17:19:12.1287885Z
2019-08-28T17:19:12.1299251Z To learn more, run the command again with --verbose.
2019-08-28T17:19:12.1315777Z
2019-08-28T17:19:12.1316011Z
2019-08-28T17:19:12.1317169Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "test" "--target" "x86_64-unknown-linux-gnu" "-Zbinary-dep-depinfo" "-j" "2" "--release" "--locked" "--color" "always" "--features" "panic-unwind backtrace compiler-builtins-c" "--manifest-path" "/checkout/src/libtest/Cargo.toml" "-p" "std" "--" "--quiet"
2019-08-28T17:19:12.1317382Z
2019-08-28T17:19:12.1317418Z
2019-08-28T17:19:12.1325659Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
2019-08-28T17:19:12.1325952Z Build completed unsuccessfully in 1:29:20
2019-08-28T17:19:12.1325952Z Build completed unsuccessfully in 1:29:20
2019-08-28T17:19:12.1383692Z == clock drift check ==
2019-08-28T17:19:12.1413497Z local time: Wed Aug 28 17:19:12 UTC 2019
2019-08-28T17:19:12.2288502Z network time: Wed, 28 Aug 2019 17:19:12 GMT
2019-08-28T17:19:12.2293658Z == end clock drift check ==
2019-08-28T17:19:13.0935030Z ##[error]Bash exited with code '1'.
2019-08-28T17:19:13.0971514Z ##[section]Starting: Checkout
2019-08-28T17:19:13.0973778Z ==============================================================================
2019-08-28T17:19:13.0973835Z Task : Get sources
2019-08-28T17:19:13.0973901Z Description : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
I'm a bot <https://github.com/rust-ops/rust-log-analyzer>! 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 ***@***.****. (Feature
Requests
<https://github.com/rust-ops/rust-log-analyzer/issues?q=is%3Aopen+is%3Aissue+label%3Afeature-request>
)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#63871?email_source=notifications&email_token=AARU4T7KHZ5Z5I57OZCEE5TQG2XV7A5CNFSM4IPHK7BKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5L25BI#issuecomment-525840005>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AARU4T5AOWVM7IS4IHADNO3QG2XV7ANCNFSM4IPHK7BA>
.
|
Ah, okay, those are |
We could fix the tests ( |
src/libstd/f32.rs
Outdated
@@ -1015,7 +1015,8 @@ impl f32 { | |||
/// assert!((2.0f32).clamp(-2.0, 1.0) == 1.0); | |||
/// assert!((std::f32::NAN).clamp(-2.0, 1.0).is_nan()); | |||
/// ``` | |||
#[must_use = "method returns a new number and does not mutate the original value"] | |||
// The tests below invoke `clamp` without a return value in order to cause a `panic`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these worthy of FIXME
or some kind of (new?) issue number?
I think we should either fix the tests now or intentionally leave these
functions un-annotated (in case anyone is using `clamp` for its `panic`
behavior, which...is generally probably not a good practice).
…On Thu, Aug 29, 2019, 1:31 AM Joe ST ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/libstd/f32.rs
<#63871 (comment)>:
> @@ -1015,7 +1015,8 @@ impl f32 {
/// assert!((2.0f32).clamp(-2.0, 1.0) == 1.0);
/// assert!((std::f32::NAN).clamp(-2.0, 1.0).is_nan());
/// ```
- #[must_use = "method returns a new number and does not mutate the original value"]
+ // The tests below invoke `clamp` without a return value in order to cause a `panic`.
are these worthy of FIXME?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#63871?email_source=notifications&email_token=AARU4T4XAKOH4EZYHREFPLTQG53MHA5CNFSM4IPHK7BKYY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCDB4RZY#pullrequestreview-281266407>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AARU4T7O7CQZGWYFOLXFAULQG53MHANCNFSM4IPHK7BA>
.
|
I've gone ahead and restored the annotation for |
Ping from triage CC @BatmanAoD Thanks! |
I'm a little confused why rfcbot didn't do its thing. Let's try this instead: @rfcbot poll Merge this? |
Team member @joshtriplett has asked teams: T-libs, for consensus on:
|
The team label was T-libs and you're not on that team. :) |
Thanks @withoutboats |
⌛ Testing commit 1aa5d0c with merge 4e54f7c3b97b164eb2c6728afa0453e590016a83... |
…boats Add #[must_use] to all functions 'fn(float) -> float' These are pure functions. ```rust impl f32/f64 { fn floor(self) -> Self; fn ceil(self) -> Self; fn round(self) -> Self; fn trunc(self) -> Self; fn fract(self) -> Self; fn abs(self) -> Self; fn signum(self) -> Self; fn mul_add(self, a: Self, b: Self) -> Self; fn div_euclid(self, rhs: Self) -> Self; fn rem_euclid(self, rhs: Self) -> Self; fn powi(self, n: i32) -> Self; fn powf(self, n: Self) -> Self; fn sqrt(self) -> Self; fn exp(self) -> Self; fn exp2(self) -> Self; fn ln(self) -> Self; fn log(self, base: Self) -> Self; fn log2(self) -> Self; fn log10(self) -> Self; fn abs_sub(self, other: Self) -> Self; fn cbrt(self) -> Self; fn hypot(self, other: Self) -> Self; fn sin(self) -> Self; fn cos(self) -> Self; fn tan(self) -> Self; fn asin(self) -> Self; fn acos(self) -> Self; fn atan(self) -> Self; fn atan2(self, other: Self) -> Self; fn exp_m1(self) -> Self; fn ln_1p(self) -> Self; fn sinh(self) -> Self; fn cosh(self) -> Self; fn tanh(self) -> Self; fn asinh(self) -> Self; fn acosh(self) -> Self; fn atanh(self) -> Self; fn clamp(self, min: Self, max: Self) -> Self; } ``` Part of rust-lang#48926
@bors retry rolled up. |
⌛ Testing commit 1aa5d0c with merge dd5967887cb4a8743d649c137db63863a4e29f34... |
The job Click to expand the log.
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 |
💔 Test failed - checks-azure |
Ping from triage |
Ping again from triage |
As far as I can tell, this is a spurious failure:
How do I request a retry? |
@bors: retry |
Add #[must_use] to all functions 'fn(float) -> float' These are pure functions. ```rust impl f32/f64 { fn floor(self) -> Self; fn ceil(self) -> Self; fn round(self) -> Self; fn trunc(self) -> Self; fn fract(self) -> Self; fn abs(self) -> Self; fn signum(self) -> Self; fn mul_add(self, a: Self, b: Self) -> Self; fn div_euclid(self, rhs: Self) -> Self; fn rem_euclid(self, rhs: Self) -> Self; fn powi(self, n: i32) -> Self; fn powf(self, n: Self) -> Self; fn sqrt(self) -> Self; fn exp(self) -> Self; fn exp2(self) -> Self; fn ln(self) -> Self; fn log(self, base: Self) -> Self; fn log2(self) -> Self; fn log10(self) -> Self; fn abs_sub(self, other: Self) -> Self; fn cbrt(self) -> Self; fn hypot(self, other: Self) -> Self; fn sin(self) -> Self; fn cos(self) -> Self; fn tan(self) -> Self; fn asin(self) -> Self; fn acos(self) -> Self; fn atan(self) -> Self; fn atan2(self, other: Self) -> Self; fn exp_m1(self) -> Self; fn ln_1p(self) -> Self; fn sinh(self) -> Self; fn cosh(self) -> Self; fn tanh(self) -> Self; fn asinh(self) -> Self; fn acosh(self) -> Self; fn atanh(self) -> Self; fn clamp(self, min: Self, max: Self) -> Self; } ``` Part of #48926
☀️ Test successful - checks-azure |
These are pure functions.
Part of #48926