Skip to content

Add lint for float in array comparison - #5345

Merged
bors merged 15 commits into
rust-lang:masterfrom
marcin-serwin:add-lint-for-float-in-array-comparison
Apr 15, 2020
Merged

Add lint for float in array comparison#5345
bors merged 15 commits into
rust-lang:masterfrom
marcin-serwin:add-lint-for-float-in-array-comparison

Conversation

@marcin-serwin

Copy link
Copy Markdown
Contributor

Fixes #4277
changelog:

  • Added new handler for expression of index kind (e.g. arr[i]). It returns a constant when both array and index are constant, or when the array is constant and all values are equal.
  • Trigger float_cmp and float_cmp_const lint when comparing arrays. Allow for comparison when one of the arrays contains only zeros or infinities.
  • Added appropriate tests for such cases.

@flip1995
flip1995 requested a review from yaahc March 30, 2020 17:39
@flip1995

Copy link
Copy Markdown
Member

@yaahc I already left a review for this in #4343, which was closed in favor of this.

@yaahc yaahc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@yaahc
yaahc requested a review from Manishearth March 30, 2020 18:48
Comment thread tests/ui/float_cmp.stderr Outdated
Comment thread tests/ui/float_cmp.stderr Outdated
@flip1995 flip1995 added the S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) label Mar 31, 2020
@marcin-serwin

marcin-serwin commented Apr 6, 2020

Copy link
Copy Markdown
Contributor Author

Hi @flip1995,
I don't know what these two new checks are and there is no info on why they fail. Could you offer some help?

@flip1995

flip1995 commented Apr 6, 2020

Copy link
Copy Markdown
Member

It's a GHA bug, that will hopefully be fixed today/soon. So don't worry about it

@marcin-serwin

Copy link
Copy Markdown
Contributor Author

I've made the changes requested in conversations, so this PR can be reviewed again.

Comment thread tests/ui/float_cmp.stderr Outdated
Comment thread clippy_lints/src/misc.rs Outdated
@flip1995 flip1995 added S-waiting-on-bors Status: The marked PR was approved and is only waiting bors and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Apr 6, 2020
@flip1995

flip1995 commented Apr 6, 2020

Copy link
Copy Markdown
Member

Thanks! Waiting for GHA to get fixed.

@flip1995

flip1995 commented Apr 6, 2020

Copy link
Copy Markdown
Member

@Toxyxer you have to run

tests/ui/update-references.sh 'target/debug/test_build_base' 'float_cmp.rs'

again

@marcin-serwin

Copy link
Copy Markdown
Contributor Author

Sorry, I forgot about the second change :>

@flip1995

flip1995 commented Apr 7, 2020

Copy link
Copy Markdown
Member

@bors r+ rollup

@bors

bors commented Apr 7, 2020

Copy link
Copy Markdown
Contributor

📌 Commit 4348af2 has been approved by flip1995

@bors

bors commented Apr 7, 2020

Copy link
Copy Markdown
Contributor

🌲 The tree is currently closed for pull requests below priority 2, this pull request will be tested once the tree is reopened

flip1995 added a commit to flip1995/rust-clippy that referenced this pull request Apr 7, 2020
…comparison, r=flip1995

Add lint for float in array comparison

Fixes rust-lang#4277
changelog:
- Added new handler for expression of index kind (e.g. `arr[i]`). It returns a constant when both array and index are constant, or when the array is constant and all values are equal.
- Trigger float_cmp and float_cmp_const lint when comparing arrays. Allow for comparison when one of the arrays contains only zeros or infinities.
- Added appropriate tests for such cases.
bors added a commit that referenced this pull request Apr 8, 2020
Rollup of 12 pull requests

Successful merges:

 - #5345 (Add lint for float in array comparison)
 - #5406 (Fix update_lints)
 - #5409 (Downgrade let_unit_value to pedantic)
 - #5410 (Downgrade trivially_copy_pass_by_ref to pedantic)
 - #5412 (Downgrade inefficient_to_string to pedantic)
 - #5415 (Add new lint for `Result<T, E>.map_or(None, Some(T))`)
 - #5417 (Update doc links and mentioned names in docs)
 - #5419 (Downgrade unreadable_literal to pedantic)
 - #5420 (Downgrade new_ret_no_self to pedantic)
 - #5422 (CONTRIBUTING.md: fix broken triage link)
 - #5424 (Incorrect suspicious_op_assign_impl)
 - #5425 (Ehance opt_as_ref_deref lint.)

Failed merges:

 - #5411 (Downgrade implicit_hasher to pedantic)
 - #5428 (Move cognitive_complexity to nursery)

r? @ghost

changelog: rollup
@bors

bors commented Apr 8, 2020

Copy link
Copy Markdown
Contributor

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

bors added a commit that referenced this pull request Apr 8, 2020
Rollup of 11 pull requests

Successful merges:

 - #5406 (Fix update_lints)
 - #5409 (Downgrade let_unit_value to pedantic)
 - #5410 (Downgrade trivially_copy_pass_by_ref to pedantic)
 - #5412 (Downgrade inefficient_to_string to pedantic)
 - #5415 (Add new lint for `Result<T, E>.map_or(None, Some(T))`)
 - #5417 (Update doc links and mentioned names in docs)
 - #5419 (Downgrade unreadable_literal to pedantic)
 - #5420 (Downgrade new_ret_no_self to pedantic)
 - #5422 (CONTRIBUTING.md: fix broken triage link)
 - #5424 (Incorrect suspicious_op_assign_impl)
 - #5425 (Ehance opt_as_ref_deref lint.)

Failed merges:

 - #5345 (Add lint for float in array comparison)
 - #5411 (Downgrade implicit_hasher to pedantic)
 - #5428 (Move cognitive_complexity to nursery)

r? @ghost

changelog: rollup
@flip1995

flip1995 commented Apr 8, 2020

Copy link
Copy Markdown
Member

@Toxyxer a rebase is required after the rollup #5438

@bors

bors commented Apr 8, 2020

Copy link
Copy Markdown
Contributor

🔒 Merge conflict

This pull request and the master branch diverged in a way that cannot be automatically merged. Please rebase on top of the latest master branch, and let the reviewer approve again.

How do I rebase?

Assuming self is your fork and upstream is this repository, you can resolve the conflict following these steps:

  1. git checkout add-lint-for-float-in-array-comparison (switch to your branch)
  2. git fetch upstream master (retrieve the latest master)
  3. git rebase upstream/master -p (rebase on top of it)
  4. Follow the on-screen instruction to resolve conflicts (check git status if you got lost).
  5. git push self add-lint-for-float-in-array-comparison --force-with-lease (update this PR)

You may also read Git Rebasing to Resolve Conflicts by Drew Blessing for a short tutorial.

Please avoid the "Resolve conflicts" button on GitHub. It uses git merge instead of git rebase which makes the PR commit history more difficult to read.

Sometimes step 4 will complete without asking for resolution. This is usually due to difference between how Cargo.lock conflict is handled during merge and rebase. This is normal, and you should still perform step 5 to update this PR.

Error message
Auto-merging tests/ui/float_cmp_const.stderr
CONFLICT (content): Merge conflict in tests/ui/float_cmp_const.stderr
Auto-merging tests/ui/float_cmp_const.rs
Auto-merging tests/ui/float_cmp.stderr
CONFLICT (content): Merge conflict in tests/ui/float_cmp.stderr
Auto-merging tests/ui/float_cmp.rs
Auto-merging clippy_lints/src/misc.rs
CONFLICT (content): Merge conflict in clippy_lints/src/misc.rs
Auto-merging clippy_lints/src/consts.rs
Automatic merge failed; fix conflicts and then commit the result.

@phansch phansch added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-bors Status: The marked PR was approved and is only waiting bors labels Apr 9, 2020
@phansch

phansch commented Apr 10, 2020

Copy link
Copy Markdown
Contributor

@bors retry

@phansch

phansch commented Apr 11, 2020

Copy link
Copy Markdown
Contributor

Ah.. that should have been
@bors r=flip1995

@bors

bors commented Apr 11, 2020

Copy link
Copy Markdown
Contributor

📌 Commit 4449cc7 has been approved by flip1995

@bors

bors commented Apr 11, 2020

Copy link
Copy Markdown
Contributor

⌛ Testing commit 4449cc7 with merge 2e6ff6e...

bors added a commit that referenced this pull request Apr 11, 2020
… r=flip1995

Add lint for float in array comparison

Fixes #4277
changelog:
- Added new handler for expression of index kind (e.g. `arr[i]`). It returns a constant when both array and index are constant, or when the array is constant and all values are equal.
- Trigger float_cmp and float_cmp_const lint when comparing arrays. Allow for comparison when one of the arrays contains only zeros or infinities.
- Added appropriate tests for such cases.
@bors

bors commented Apr 11, 2020

Copy link
Copy Markdown
Contributor

💔 Test failed - checks-action_remark_test

@marcin-serwin

Copy link
Copy Markdown
Contributor Author

Hey @flip1995,
Could you help me with the homu test fail? There is no information on why these checks failed.

@phansch

phansch commented Apr 15, 2020

Copy link
Copy Markdown
Contributor

This was probably just a random failure, let's try again

@bors retry

@bors

bors commented Apr 15, 2020

Copy link
Copy Markdown
Contributor

⌛ Testing commit 4449cc7 with merge 756bb28...

bors added a commit that referenced this pull request Apr 15, 2020
… r=flip1995

Add lint for float in array comparison

Fixes #4277
changelog:
- Added new handler for expression of index kind (e.g. `arr[i]`). It returns a constant when both array and index are constant, or when the array is constant and all values are equal.
- Trigger float_cmp and float_cmp_const lint when comparing arrays. Allow for comparison when one of the arrays contains only zeros or infinities.
- Added appropriate tests for such cases.
@phansch

phansch commented Apr 15, 2020

Copy link
Copy Markdown
Contributor

Hmm, bors should have merged this by now.. Let's give this another try 🤷

@bors retry

@bors

bors commented Apr 15, 2020

Copy link
Copy Markdown
Contributor

⌛ Testing commit 4449cc7 with merge a96f874...

@bors

bors commented Apr 15, 2020

Copy link
Copy Markdown
Contributor

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: flip1995
Pushing a96f874 to master...

@bors
bors merged commit a96f874 into rust-lang:master Apr 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Float comparison lint doesn't seem to trigger on float array comparison

6 participants