rust icon indicating copy to clipboard operation
rust copied to clipboard

Add better assert messages for f32/f64 clamps

Open Xaeroxe opened this issue 3 years ago • 3 comments

Xaeroxe avatar Sep 18 '22 00:09 Xaeroxe

r? @joshtriplett

(rust-highfive has picked a reviewer for you, use r? to override)

rust-highfive avatar Sep 18 '22 00:09 rust-highfive

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

rustbot avatar Sep 18 '22 00:09 rustbot

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
configure: rust.debug-assertions := True
configure: rust.overflow-checks := True
configure: llvm.assertions      := True
configure: dist.missing-tools   := True
configure: build.configure-args := ['--enable-sccache', '--disable-manage-submodu ...
configure: writing `config.toml` in current directory
configure: 
configure: run `python /checkout/x.py --help`
Attempting with retry: make prepare
---
skip untracked path cpu-usage.csv during rustfmt invocations
skip untracked path src/doc/book/ during rustfmt invocations
skip untracked path src/doc/rust-by-example/ during rustfmt invocations
skip untracked path src/llvm-project/ during rustfmt invocations
Diff in /checkout/library/core/src/num/f32.rs at line 1391:
     #[stable(feature = "clamp", since = "1.50.0")]
     #[inline]
     pub fn clamp(mut self, min: f32, max: f32) -> f32 {
-        assert!(min <= max, "min > max, or either was NaN. This is not allowed. min: {min:?}, max: {max:?}");
+        assert!(
+            min <= max,
+            "min > max, or either was NaN. This is not allowed. min: {min:?}, max: {max:?}"
+        );
         if self < min {
             self = min;
Diff in /checkout/library/core/src/num/f64.rs at line 1389:
Diff in /checkout/library/core/src/num/f64.rs at line 1389:
     #[stable(feature = "clamp", since = "1.50.0")]
     #[inline]
     pub fn clamp(mut self, min: f64, max: f64) -> f64 {
-        assert!(min <= max, "min > max, or either was NaN. This is not allowed. min: {min:?}, max: {max:?}");
+        assert!(
+            min <= max,
+            "min > max, or either was NaN. This is not allowed. min: {min:?}, max: {max:?}"
+        );
         if self < min {
             self = min;
         }
Running `"/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/rustfmt" "--config-path" "/checkout" "--edition" "2021" "--unstable-features" "--skip-children" "--check" "/checkout/library/core/src/hint.rs" "/checkout/library/core/tests/asserting.rs" "/checkout/library/core/src/num/f32.rs" "/checkout/library/core/src/future/into_future.rs" "/checkout/library/core/src/num/f64.rs" "/checkout/library/core/src/future/poll_fn.rs" "/checkout/library/core/src/num/error.rs" "/checkout/library/core/tests/iter/traits/accum.rs"` failed.
If you're running `tidy`, try again with `--bless`. Or, if you just want to format code, run `./x.py fmt` instead.

rust-log-analyzer avatar Sep 18 '22 00:09 rust-log-analyzer

Minor tweak to the message, but otherwise LGTM. r=me with the suggestions (or similar) applied.

joshtriplett avatar Oct 03 '22 13:10 joshtriplett

Does this work?

@bors r=@joshtriplett

Xaeroxe avatar Oct 03 '22 15:10 Xaeroxe

@Xaeroxe: :key: Insufficient privileges: Not in reviewers

bors avatar Oct 03 '22 15:10 bors

I'd like this to go into the 1.66 release. With the inclusion of the new clippy lint manual_clamp in 1.66, more people are going to trigger this panic message than they would in 1.65

Xaeroxe avatar Oct 10 '22 04:10 Xaeroxe

@joshtriplett this is ready for re-review

Xaeroxe avatar Oct 31 '22 17:10 Xaeroxe

ping from triage: @Xaeroxe

FYI: when a PR is ready for review, send a message containing @rustbot ready to switch to S-waiting-on-review so the PR is in the reviewer's backlog.

doing this for you - @rustbot ready

JohnCSimon avatar Jan 01 '23 19:01 JohnCSimon

Thank you!

Xaeroxe avatar Jan 01 '23 21:01 Xaeroxe

lgtm, thanks!

@bors r+

ChrisDenton avatar Apr 14 '23 08:04 ChrisDenton

:pushpin: Commit c7f54daaf44b16469193b03694360153c82aab08 has been approved by ChrisDenton

It is now in the queue for this repository.

bors avatar Apr 14 '23 08:04 bors

:hourglass: Testing commit c7f54daaf44b16469193b03694360153c82aab08 with merge 3e565f1a27a19f7da48c7109500b4351c0819e68...

bors avatar Apr 14 '23 10:04 bors

:sunny: Test successful - checks-actions Approved by: ChrisDenton Pushing 3e565f1a27a19f7da48c7109500b4351c0819e68 to master...

bors avatar Apr 14 '23 12:04 bors

Finished benchmarking commit (3e565f1a27a19f7da48c7109500b4351c0819e68): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.6% [1.6%, 1.6%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.1% [-2.1%, -2.1%] 1
All ❌✅ (primary) - - 0

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.3% [2.2%, 2.4%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

rust-timer avatar Apr 15 '23 02:04 rust-timer