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

Provide suggestion to convert numeric op LHS rather than unwrapping RHS #73195

Merged
merged 2 commits into from Jun 12, 2020

Conversation

ayazhafiz
Copy link
Contributor

Given a code

fn foo(x: u8, y: u32) -> bool {
    x > y
}
fn main() {}

it could be more helpful to provide a suggestion to do "u32::from(x)"
rather than "y.try_into().unwrap()", since the latter may panic.

We do this by passing the LHS of a binary expression up the stack into
the coercion checker.

Closes #73145

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @varkor (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.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 10, 2020
@estebank
Copy link
Contributor

The code looks good, but it'll conflict with #72380. You'll have to rebase and fix the conflicts after that one lands. Once that has happened, r=me. Thanks for doing this!

r? @estebank

@rust-highfive rust-highfive assigned estebank and unassigned varkor Jun 10, 2020
@bors

This comment has been minimized.

Given a code

```rust
fn foo(x: u8, y: u32) -> bool {
    x > y
}
fn main() {}
```

it could be more helpful to provide a suggestion to do "u32::from(x)"
rather than "y.try_into().unwrap()", since the latter may panic.

We do this by passing the LHS of a binary expression up the stack into
the coercion checker.

Closes rust-lang#73145
@ayazhafiz
Copy link
Contributor Author

r=@estebank

@ayazhafiz ayazhafiz requested a review from estebank June 11, 2020 16:05
@estebank
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jun 11, 2020

📌 Commit 0c02f8a has been approved by estebank

@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-review Status: Awaiting review from the assignee but also interested parties. labels Jun 11, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 11, 2020
Rollup of 7 pull requests

Successful merges:

 - rust-lang#73033 (Fix #[thread_local] statics as asm! sym operands)
 - rust-lang#73036 (std: Enable atomic.fence emission on wasm32)
 - rust-lang#73163 (Add long error explanation for E0724)
 - rust-lang#73187 (Remove missed `cfg(bootstrap)`)
 - rust-lang#73195 (Provide suggestion to convert numeric op LHS rather than unwrapping RHS)
 - rust-lang#73247 (Add various Zulip notifications for prioritization)
 - rust-lang#73254 (Add comment about LocalDefId -> DefId)

Failed merges:

r? @ghost
@bors bors merged commit 7bdf7d0 into rust-lang:master Jun 12, 2020
@cuviper cuviper added this to the 1.46 milestone May 2, 2024
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.

Prefer T::from over .try_into().unwrap() in error messages
6 participants