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

Fixes issue #4892. #5445

Merged
merged 2 commits into from Apr 17, 2020
Merged

Fixes issue #4892. #5445

merged 2 commits into from Apr 17, 2020

Conversation

ghost
Copy link

@ghost ghost commented Apr 10, 2020

First contribution here 😊 ! Do not hesitate to correct me.

This PR is related to issue #4892 .

Summary

-literal.method_call(args)

The main idea is to not trigger clippy::precedence when the method call is an odd function.

Example

// should trigger lint 
let _ = -1.0_f64.abs() //precedence of method call abs() and neg ('-') is ambiguous

// should not trigger lint
let _ = -1.0_f64.sin() // sin is an odd function => -sin(x) = sin(-x) 

Theory

Rust allows following literals:

  • char
  • string
  • integers
  • floats
  • byte
  • bool

Only integers/floats implements the relevant std::ops::Neg.
Following odd functions are implemented on i[8-128] and/or f[32-64]:

  • asin
  • asinh
  • atan
  • atanh
  • cbrt
  • fract
  • round
  • signum
  • sin
  • sinh
  • tan
  • tanh
  • to_degrees
  • to_radians

Implementation

As suggested by flip1995 in comment, this PR add a whitelist of odd functions and compare method call to the the whitelist before triggering lint.

changelog: Don't trigger [clippy::precedence] on odd functions.

@ghost ghost changed the title [WIP] Fixes issue #4892. Fixes issue #4892. Apr 11, 2020
@phansch phansch added the S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) label Apr 15, 2020
@ghost
Copy link
Author

ghost commented Apr 17, 2020

I integrated recommended changes and rebase upstream/master.

@flip1995
Copy link
Member

@bors r+

Thanks!

@bors
Copy link
Contributor

bors commented Apr 17, 2020

📌 Commit 66b855c has been approved by flip1995

@bors
Copy link
Contributor

bors commented Apr 17, 2020

⌛ Testing commit 66b855c with merge a63f812...

bors added a commit that referenced this pull request Apr 17, 2020
Fixes issue #4892.

First contribution here 😊 ! Do not hesitate to correct me.

This PR is related to issue #4892 .

# Summary

```rust
-literal.method_call(args)
```
The main idea is to not trigger `clippy:precedence` when the method call is an odd function.

# Example

```rust
// should trigger lint
let _ = -1.0_f64.abs() //precedence of method call abs() and neg ('-') is ambiguous

// should not trigger lint
let _ = -1.0_f64.sin() // sin is an odd function => -sin(x) = sin(-x)
```

# Theory

Rust allows following literals:
- char
- string
- integers
- floats
- byte
- bool

Only integers/floats implements the relevant `std::ops::Neg`.
Following odd functions are implemented on i[8-128] and/or f[32-64]:
- `asin`
- `asinh`
- `atan`
- `atanh`
- `cbrt`
- `fract`
- `round`
- `signum`
- `sin`
- `sinh`
- `tan`
- `tanh `
- `to_degrees`
- `to_radians`

# Implementation

As suggested by `flip1995` in [comment](#4892 (comment)), this PR add a whitelist of odd functions and compare method call to the the whitelist before triggering lint.
@bors
Copy link
Contributor

bors commented Apr 17, 2020

💔 Test failed - checks-action_test

@flip1995
Copy link
Member

@bors retry

@bors
Copy link
Contributor

bors commented Apr 17, 2020

⌛ Testing commit 66b855c with merge 52dacbc...

@bors
Copy link
Contributor

bors commented Apr 17, 2020

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

@bors bors merged commit 52dacbc into rust-lang:master Apr 17, 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.

4 participants