Skip to content

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

Merged
bors merged 2 commits into
rust-lang:masterfrom
ayazhafiz:i/73145
Jun 12, 2020
Merged

Provide suggestion to convert numeric op LHS rather than unwrapping RHS#73195
bors merged 2 commits into
rust-lang:masterfrom
ayazhafiz:i/73145

Conversation

@ayazhafiz

Copy link
Copy Markdown
Contributor

Given a code

fnfoo(x:u8,y:u32) -> bool{
x > y
}fnmain(){}

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
Copy Markdown
Contributor

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-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 10, 2020
Comment threadsrc/test/ui/numeric/numeric-cast-binop.rs Outdated
@estebank

Copy link
Copy Markdown
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-highfiverust-highfive assigned estebank and unassigned varkorJun 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.
Closesrust-lang#73145
@ayazhafiz

Copy link
Copy Markdown
ContributorAuthor

r=@estebank

@ayazhafiz
ayazhafiz requested a review from estebankJune 11, 2020 16:05
@estebank

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Jun 11, 2020

Copy link
Copy Markdown
Collaborator

📌 Commit 0c02f8a has been approved by estebank

@borsbors 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:masterJun 12, 2020
@cuvipercuviper added this to the 1.46 milestone May 2, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: 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

@ayazhafiz@rust-highfive@estebank@bors@cuviper@varkor